aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-01-25 16:59:51 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-01-25 16:59:51 -0500
commitb31fde6db2b76a9f7f59bf016652b46cff43f8da (patch)
tree2af4c48ae97b9800604fc0b36bc5c274d46d4aa3
parentf31c338675872875e24f124af0689131b0c72600 (diff)
parenta999337b49fcdd2c4a475e97e4b8337ebdfa4abf (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/v4l-dvb
* git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/v4l-dvb: (509 commits) V4L/DVB (7078): radio: fix sf16fmi section mismatch V4L/DVB (7077): bt878: remove handcrafted PCI subsystem ID check V4L/DVB (7075): Make a local function static V4L/DVB (7074): DiB7000P: correct tuning problem for 7MHz channel V4L/DVB (7073): DiB7070: Reception quality improved V4L/DVB (7072): sets the MT2060 IF1 frequency according to EEPROM V4L/DVB (7071): DiB0700: Start streaming the right way V4L/DVB (7070): Fix some tuning problems V4L/DVB (7069): Support for myTV.t V4L/DVB (7068): Add support for WinTV Nova-T-CE driver V4L/DVB (7067): fix autoserach in the Hauppauge NOVA-T 500 V4L/DVB (7066): ASUS My Cinema U3000 Mini DVBT Tuner V4L/DVB (7065): Artec T14BR patches V4L/DVB (7063): xc5000: Fix OOPS caused by missing firmware V4L/DVB (7062): radio-si570x: Some fixes and new USB ID addition V4L/DVB (7061): radio-si470x: Some cleanups V4L/DVB (7060): em28xx: remove has_tuner V4L/DVB (7059): cx88: Ensure the tuner is reset correctly V4L/DVB (7058): IR corrections for the Pinnacle 800i V4L/DVB (7056): tuner: suppress obsolete tuner i2c address warning for XC5000 tuners ...
-rw-r--r--Documentation/DocBook/videobook.tmpl9
-rw-r--r--Documentation/dvb/bt8xx.txt12
-rw-r--r--Documentation/video4linux/CARDLIST.cx238854
-rw-r--r--Documentation/video4linux/CARDLIST.cx881
-rw-r--r--Documentation/video4linux/CARDLIST.em28xx17
-rw-r--r--Documentation/video4linux/CARDLIST.ivtv6
-rw-r--r--Documentation/video4linux/CARDLIST.saa713417
-rw-r--r--Documentation/video4linux/CARDLIST.tuner5
-rw-r--r--Documentation/video4linux/CARDLIST.usbvision1
-rw-r--r--Documentation/video4linux/extract_xc3028.pl926
-rw-r--r--Documentation/video4linux/sn9c102.txt1
-rw-r--r--MAINTAINERS9
-rw-r--r--drivers/media/Kconfig22
-rw-r--r--drivers/media/common/Kconfig2
-rw-r--r--drivers/media/common/ir-functions.c3
-rw-r--r--drivers/media/common/ir-keymaps.c146
-rw-r--r--drivers/media/common/saa7146_fops.c9
-rw-r--r--drivers/media/common/saa7146_vbi.c10
-rw-r--r--drivers/media/common/saa7146_video.c8
-rw-r--r--drivers/media/dvb/b2c2/flexcop.c1
-rw-r--r--drivers/media/dvb/bt8xx/bt878.c76
-rw-r--r--drivers/media/dvb/bt8xx/bt878.h6
-rw-r--r--drivers/media/dvb/bt8xx/dst.c19
-rw-r--r--drivers/media/dvb/bt8xx/dst_common.h5
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c6
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.h43
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ringbuffer.c5
-rw-r--r--drivers/media/dvb/dvb-usb/af9005.c7
-rw-r--r--drivers/media/dvb/dvb-usb/au6610.c6
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c436
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.h7
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c5
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c149
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c3
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.h3
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h18
-rw-r--r--drivers/media/dvb/dvb-usb/gl861.c6
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.c16
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.h1
-rw-r--r--drivers/media/dvb/dvb-usb/opera1.c6
-rw-r--r--drivers/media/dvb/dvb-usb/opera1.h9
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.c15
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.h2
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c5
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.h5
-rw-r--r--drivers/media/dvb/frontends/Kconfig16
-rw-r--r--drivers/media/dvb/frontends/Makefile5
-rw-r--r--drivers/media/dvb/frontends/dib0070.c13
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c10
-rw-r--r--drivers/media/dvb/frontends/dib7000m.c9
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c18
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.h5
-rw-r--r--drivers/media/dvb/frontends/mt2266.c204
-rw-r--r--drivers/media/dvb/frontends/mt312.c257
-rw-r--r--drivers/media/dvb/frontends/mt312.h15
-rw-r--r--drivers/media/dvb/frontends/mt352.c8
-rw-r--r--drivers/media/dvb/frontends/or51132.c6
-rw-r--r--drivers/media/dvb/frontends/or51211.c6
-rw-r--r--drivers/media/dvb/frontends/s5h1409.c97
-rw-r--r--drivers/media/dvb/frontends/s5h1409.h11
-rw-r--r--drivers/media/dvb/frontends/tda18271-common.c653
-rw-r--r--drivers/media/dvb/frontends/tda18271-fe.c1225
-rw-r--r--drivers/media/dvb/frontends/tda18271-priv.h212
-rw-r--r--drivers/media/dvb/frontends/tda18271-tables.c1285
-rw-r--r--drivers/media/dvb/frontends/tda18271.h78
-rw-r--r--drivers/media/dvb/frontends/tda827x.c367
-rw-r--r--drivers/media/dvb/frontends/tda827x.h7
-rw-r--r--drivers/media/dvb/frontends/ves1820.c4
-rw-r--r--drivers/media/dvb/frontends/xc5000.c964
-rw-r--r--drivers/media/dvb/frontends/xc5000.h62
-rw-r--r--drivers/media/dvb/frontends/xc5000_priv.h36
-rw-r--r--drivers/media/dvb/frontends/zl10353.c327
-rw-r--r--drivers/media/dvb/frontends/zl10353.h9
-rw-r--r--drivers/media/dvb/frontends/zl10353_priv.h23
-rw-r--r--drivers/media/dvb/ttpci/Kconfig37
-rw-r--r--drivers/media/dvb/ttpci/Makefile12
-rw-r--r--drivers/media/dvb/ttpci/av7110.c3
-rw-r--r--drivers/media/dvb/ttpci/av7110.h7
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c16
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.h3
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c4
-rw-r--r--drivers/media/radio/Kconfig10
-rw-r--r--drivers/media/radio/Makefile1
-rw-r--r--drivers/media/radio/dsbr100.c18
-rw-r--r--drivers/media/radio/radio-gemtek.c6
-rw-r--r--drivers/media/radio/radio-maestro.c2
-rw-r--r--drivers/media/radio/radio-sf16fmi.c2
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c3
-rw-r--r--drivers/media/radio/radio-si470x.c1432
-rw-r--r--drivers/media/video/Kconfig52
-rw-r--r--drivers/media/video/Makefile10
-rw-r--r--drivers/media/video/bt8xx/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/Makefile2
-rw-r--r--drivers/media/video/bt8xx/bttv-audio-hook.c382
-rw-r--r--drivers/media/video/bt8xx/bttv-audio-hook.h23
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c444
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c2374
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c5
-rw-r--r--drivers/media/video/bt8xx/bttv-risc.c14
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c58
-rw-r--r--drivers/media/video/bt8xx/bttv.h5
-rw-r--r--drivers/media/video/bt8xx/bttvp.h20
-rw-r--r--drivers/media/video/bw-qcam.c10
-rw-r--r--drivers/media/video/cs5345.c168
-rw-r--r--drivers/media/video/cs53l32a.c78
-rw-r--r--drivers/media/video/cx2341x.c313
-rw-r--r--drivers/media/video/cx23885/Kconfig4
-rw-r--r--drivers/media/video/cx23885/Makefile2
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c135
-rw-r--r--drivers/media/video/cx23885/cx23885-core.c296
-rw-r--r--drivers/media/video/cx23885/cx23885-dvb.c179
-rw-r--r--drivers/media/video/cx23885/cx23885-i2c.c98
-rw-r--r--drivers/media/video/cx23885/cx23885-reg.h13
-rw-r--r--drivers/media/video/cx23885/cx23885-vbi.c258
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c1557
-rw-r--r--drivers/media/video/cx23885/cx23885.h168
-rw-r--r--drivers/media/video/cx25840/cx25840-audio.c123
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c695
-rw-r--r--drivers/media/video/cx25840/cx25840-core.h1
-rw-r--r--drivers/media/video/cx25840/cx25840-firmware.c5
-rw-r--r--drivers/media/video/cx25840/cx25840-vbi.c2
-rw-r--r--drivers/media/video/cx88/Kconfig1
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c2
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c92
-rw-r--r--drivers/media/video/cx88/cx88-cards.c120
-rw-r--r--drivers/media/video/cx88/cx88-core.c4
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c33
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c27
-rw-r--r--drivers/media/video/cx88/cx88-input.c6
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c39
-rw-r--r--drivers/media/video/cx88/cx88-vbi.c10
-rw-r--r--drivers/media/video/cx88/cx88-video.c58
-rw-r--r--drivers/media/video/cx88/cx88.h11
-rw-r--r--drivers/media/video/em28xx/Kconfig17
-rw-r--r--drivers/media/video/em28xx/Makefile6
-rw-r--r--drivers/media/video/em28xx/em28xx-audio.c489
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c688
-rw-r--r--drivers/media/video/em28xx/em28xx-core.c88
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c81
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c52
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c2622
-rw-r--r--drivers/media/video/em28xx/em28xx.h166
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c157
-rw-r--r--drivers/media/video/et61x251/et61x251_sensor.h8
-rw-r--r--drivers/media/video/ir-kbd-i2c.c3
-rw-r--r--drivers/media/video/ivtv/Kconfig2
-rw-r--r--drivers/media/video/ivtv/Makefile5
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.c173
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.h27
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c117
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h26
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c52
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.c24
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c119
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.h1
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c127
-rw-r--r--drivers/media/video/ivtv/ivtv-irq.c95
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.h2
-rw-r--r--drivers/media/video/ivtv/ivtv-routing.c25
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c25
-rw-r--r--drivers/media/video/ivtv/ivtv-version.h2
-rw-r--r--drivers/media/video/ivtv/ivtv-yuv.c1094
-rw-r--r--drivers/media/video/ivtv/ivtv-yuv.h12
-rw-r--r--drivers/media/video/ivtv/ivtvfb.c6
-rw-r--r--drivers/media/video/m52790.c168
-rw-r--r--drivers/media/video/meye.c2
-rw-r--r--drivers/media/video/msp3400-driver.c238
-rw-r--r--drivers/media/video/msp3400-kthreads.c166
-rw-r--r--drivers/media/video/mt20xx.c2
-rw-r--r--drivers/media/video/pvrusb2/Kconfig37
-rw-r--r--drivers/media/video/pvrusb2/Makefile2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-audio.c62
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-context.c55
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-context.h5
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c97
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debug.h39
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debugifc.c177
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-devattr.c217
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-devattr.h119
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-eeprom.c1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-encoder.c75
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-encoder.h1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h80
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c1301
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.h144
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c10
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-main.c6
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-std.c7
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c60
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c7
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-video-v4l.c55
-rw-r--r--drivers/media/video/saa7115.c80
-rw-r--r--drivers/media/video/saa7127.c148
-rw-r--r--drivers/media/video/saa7134/Kconfig13
-rw-r--r--drivers/media/video/saa7134/Makefile1
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c16
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c614
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c35
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c19
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c293
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c15
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c63
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c1046
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c8
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c79
-rw-r--r--drivers/media/video/saa7134/saa7134-vbi.c8
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c1536
-rw-r--r--drivers/media/video/saa7134/saa7134.h34
-rw-r--r--drivers/media/video/sn9c102/Makefile1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c4
-rw-r--r--drivers/media/video/sn9c102/sn9c102_devtable.h2
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mt9v111.c259
-rw-r--r--drivers/media/video/stk-sensor.c578
-rw-r--r--drivers/media/video/stk-webcam.c1465
-rw-r--r--drivers/media/video/stk-webcam.h138
-rw-r--r--drivers/media/video/tda7432.c232
-rw-r--r--drivers/media/video/tda8290.c901
-rw-r--r--drivers/media/video/tda8290.h31
-rw-r--r--drivers/media/video/tda9875.c167
-rw-r--r--drivers/media/video/tda9887.c305
-rw-r--r--drivers/media/video/tda9887.h38
-rw-r--r--drivers/media/video/tea5761.c2
-rw-r--r--drivers/media/video/tea5767.c92
-rw-r--r--drivers/media/video/tea5767.h19
-rw-r--r--drivers/media/video/tlv320aic23b.c134
-rw-r--r--drivers/media/video/tuner-core.c748
-rw-r--r--drivers/media/video/tuner-driver.h99
-rw-r--r--drivers/media/video/tuner-i2c.h57
-rw-r--r--drivers/media/video/tuner-simple.c17
-rw-r--r--drivers/media/video/tuner-types.c12
-rw-r--r--drivers/media/video/tuner-xc2028-types.h128
-rw-r--r--drivers/media/video/tuner-xc2028.c1213
-rw-r--r--drivers/media/video/tuner-xc2028.h63
-rw-r--r--drivers/media/video/tvaudio.c504
-rw-r--r--drivers/media/video/tveeprom.c504
-rw-r--r--drivers/media/video/upd64031a.c111
-rw-r--r--drivers/media/video/upd64083.c103
-rw-r--r--drivers/media/video/usbvision/usbvision-cards.c18
-rw-r--r--drivers/media/video/usbvision/usbvision-cards.h1
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c330
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c60
-rw-r--r--drivers/media/video/usbvision/usbvision.h8
-rw-r--r--drivers/media/video/v4l2-common.c32
-rw-r--r--drivers/media/video/v4l2-int-device.c6
-rw-r--r--drivers/media/video/videobuf-core.c357
-rw-r--r--drivers/media/video/videobuf-dma-sg.c23
-rw-r--r--drivers/media/video/videobuf-dvb.c2
-rw-r--r--drivers/media/video/videobuf-vmalloc.c2
-rw-r--r--drivers/media/video/videodev.c8
-rw-r--r--drivers/media/video/vivi.c706
-rw-r--r--drivers/media/video/vp27smpx.c113
-rw-r--r--drivers/media/video/wm8739.c137
-rw-r--r--drivers/media/video/wm8775.c140
-rw-r--r--drivers/media/video/zr364xx.c2
-rw-r--r--include/linux/i2c-id.h2
-rw-r--r--include/media/cs5345.h39
-rw-r--r--include/media/cx2341x.h2
-rw-r--r--include/media/cx25840.h19
-rw-r--r--include/media/ir-common.h3
-rw-r--r--include/media/m52790.h93
-rw-r--r--include/media/saa7146_vv.h1
-rw-r--r--include/media/tuner.h5
-rw-r--r--include/media/v4l2-chip-ident.h6
-rw-r--r--include/media/v4l2-common.h18
-rw-r--r--include/media/v4l2-i2c-drv-legacy.h140
-rw-r--r--include/media/v4l2-i2c-drv.h68
-rw-r--r--include/media/v4l2-int-device.h5
-rw-r--r--include/media/videobuf-core.h20
269 files changed, 29548 insertions, 11654 deletions
diff --git a/Documentation/DocBook/videobook.tmpl b/Documentation/DocBook/videobook.tmpl
index b629da33951d..b3d93ee27693 100644
--- a/Documentation/DocBook/videobook.tmpl
+++ b/Documentation/DocBook/videobook.tmpl
@@ -96,7 +96,6 @@ static struct video_device my_radio
96{ 96{
97 "My radio", 97 "My radio",
98 VID_TYPE_TUNER, 98 VID_TYPE_TUNER,
99 VID_HARDWARE_MYRADIO,
100 radio_open. 99 radio_open.
101 radio_close, 100 radio_close,
102 NULL, /* no read */ 101 NULL, /* no read */
@@ -119,13 +118,6 @@ static struct video_device my_radio
119 way to change channel so it is tuneable. 118 way to change channel so it is tuneable.
120 </para> 119 </para>
121 <para> 120 <para>
122 The VID_HARDWARE_ types are unique to each device. Numbers are assigned by
123 <email>alan@redhat.com</email> when device drivers are going to be released. Until then you
124 can pull a suitably large number out of your hat and use it. 10000 should be
125 safe for a very long time even allowing for the huge number of vendors
126 making new and different radio cards at the moment.
127 </para>
128 <para>
129 We declare an open and close routine, but we do not need read or write, 121 We declare an open and close routine, but we do not need read or write,
130 which are used to read and write video data to or from the card itself. As 122 which are used to read and write video data to or from the card itself. As
131 we have no read or write there is no poll function. 123 we have no read or write there is no poll function.
@@ -844,7 +836,6 @@ static struct video_device my_camera
844 "My Camera", 836 "My Camera",
845 VID_TYPE_OVERLAY|VID_TYPE_SCALES|\ 837 VID_TYPE_OVERLAY|VID_TYPE_SCALES|\
846 VID_TYPE_CAPTURE|VID_TYPE_CHROMAKEY, 838 VID_TYPE_CAPTURE|VID_TYPE_CHROMAKEY,
847 VID_HARDWARE_MYCAMERA,
848 camera_open. 839 camera_open.
849 camera_close, 840 camera_close,
850 camera_read, /* no read */ 841 camera_read, /* no read */
diff --git a/Documentation/dvb/bt8xx.txt b/Documentation/dvb/bt8xx.txt
index ecb47adda063..b7b1d1b1da46 100644
--- a/Documentation/dvb/bt8xx.txt
+++ b/Documentation/dvb/bt8xx.txt
@@ -78,6 +78,18 @@ Example:
78For a full list of card ID's please see Documentation/video4linux/CARDLIST.bttv. 78For a full list of card ID's please see Documentation/video4linux/CARDLIST.bttv.
79In case of further problems please subscribe and send questions to the mailing list: linux-dvb@linuxtv.org. 79In case of further problems please subscribe and send questions to the mailing list: linux-dvb@linuxtv.org.
80 80
812c) Probing the cards with broken PCI subsystem ID
82--------------------------------------------------
83There are some TwinHan cards that the EEPROM has become corrupted for some
84reason. The cards do not have correct PCI subsystem ID. But we can force
85probing the cards with broken PCI subsystem ID
86
87 $ echo 109e 0878 $subvendor $subdevice > \
88 /sys/bus/pci/drivers/bt878/new_id
89
90109e: PCI_VENDOR_ID_BROOKTREE
910878: PCI_DEVICE_ID_BROOKTREE_878
92
81Authors: Richard Walker, 93Authors: Richard Walker,
82 Jamie Honan, 94 Jamie Honan,
83 Michael Hunold, 95 Michael Hunold,
diff --git a/Documentation/video4linux/CARDLIST.cx23885 b/Documentation/video4linux/CARDLIST.cx23885
index 00cb646a4bde..0924e6e142c4 100644
--- a/Documentation/video4linux/CARDLIST.cx23885
+++ b/Documentation/video4linux/CARDLIST.cx23885
@@ -1,5 +1,7 @@
1 0 -> UNKNOWN/GENERIC [0070:3400] 1 0 -> UNKNOWN/GENERIC [0070:3400]
2 1 -> Hauppauge WinTV-HVR1800lp [0070:7600] 2 1 -> Hauppauge WinTV-HVR1800lp [0070:7600]
3 2 -> Hauppauge WinTV-HVR1800 [0070:7800,0070:7801] 3 2 -> Hauppauge WinTV-HVR1800 [0070:7800,0070:7801,0070:7809]
4 3 -> Hauppauge WinTV-HVR1250 [0070:7911] 4 3 -> Hauppauge WinTV-HVR1250 [0070:7911]
5 4 -> DViCO FusionHDTV5 Express [18ac:d500] 5 4 -> DViCO FusionHDTV5 Express [18ac:d500]
6 5 -> Hauppauge WinTV-HVR1500Q [0070:7790,0070:7797]
7 6 -> Hauppauge WinTV-HVR1500 [0070:7710,0070:7717]
diff --git a/Documentation/video4linux/CARDLIST.cx88 b/Documentation/video4linux/CARDLIST.cx88
index 82ac8250e978..bc5593bd9704 100644
--- a/Documentation/video4linux/CARDLIST.cx88
+++ b/Documentation/video4linux/CARDLIST.cx88
@@ -56,3 +56,4 @@
56 55 -> Shenzhen Tungsten Ages Tech TE-DTV-250 / Swann OEM [c180:c980] 56 55 -> Shenzhen Tungsten Ages Tech TE-DTV-250 / Swann OEM [c180:c980]
57 56 -> Hauppauge WinTV-HVR1300 DVB-T/Hybrid MPEG Encoder [0070:9600,0070:9601,0070:9602] 57 56 -> Hauppauge WinTV-HVR1300 DVB-T/Hybrid MPEG Encoder [0070:9600,0070:9601,0070:9602]
58 57 -> ADS Tech Instant Video PCI [1421:0390] 58 57 -> ADS Tech Instant Video PCI [1421:0390]
59 58 -> Pinnacle PCTV HD 800i [11bd:0051]
diff --git a/Documentation/video4linux/CARDLIST.em28xx b/Documentation/video4linux/CARDLIST.em28xx
index 37f0e3cedf43..6a8469f2bcae 100644
--- a/Documentation/video4linux/CARDLIST.em28xx
+++ b/Documentation/video4linux/CARDLIST.em28xx
@@ -1,14 +1,17 @@
1 0 -> Unknown EM2800 video grabber (em2800) [eb1a:2800] 1 0 -> Unknown EM2800 video grabber (em2800) [eb1a:2800]
2 1 -> Unknown EM2820/2840 video grabber (em2820/em2840) 2 1 -> Unknown EM2750/28xx video grabber (em2820/em2840) [eb1a:2750,eb1a:2820,eb1a:2821,eb1a:2860,eb1a:2861,eb1a:2870,eb1a:2881,eb1a:2883]
3 2 -> Terratec Cinergy 250 USB (em2820/em2840) [0ccd:0036] 3 2 -> Terratec Cinergy 250 USB (em2820/em2840) [0ccd:0036]
4 3 -> Pinnacle PCTV USB 2 (em2820/em2840) [2304:0208] 4 3 -> Pinnacle PCTV USB 2 (em2820/em2840) [2304:0208]
5 4 -> Hauppauge WinTV USB 2 (em2820/em2840) [2040:4200] 5 4 -> Hauppauge WinTV USB 2 (em2820/em2840) [2040:4200,2040:4201]
6 5 -> MSI VOX USB 2.0 (em2820/em2840) [eb1a:2820] 6 5 -> MSI VOX USB 2.0 (em2820/em2840)
7 6 -> Terratec Cinergy 200 USB (em2800) 7 6 -> Terratec Cinergy 200 USB (em2800)
8 7 -> Leadtek Winfast USB II (em2800) 8 7 -> Leadtek Winfast USB II (em2800)
9 8 -> Kworld USB2800 (em2800) 9 8 -> Kworld USB2800 (em2800)
10 9 -> Pinnacle Dazzle DVC 90 (em2820/em2840) [2304:0207] 10 9 -> Pinnacle Dazzle DVC 90/DVC 100 (em2820/em2840) [2304:0207,2304:021a]
11 10 -> Hauppauge WinTV HVR 900 (em2880) 11 10 -> Hauppauge WinTV HVR 900 (em2880) [2040:6500]
12 11 -> Terratec Hybrid XS (em2880) 12 11 -> Terratec Hybrid XS (em2880) [0ccd:0042]
13 12 -> Kworld PVR TV 2800 RF (em2820/em2840) 13 12 -> Kworld PVR TV 2800 RF (em2820/em2840)
14 13 -> Terratec Prodigy XS (em2880) 14 13 -> Terratec Prodigy XS (em2880) [0ccd:0047]
15 14 -> Pixelview Prolink PlayTV USB 2.0 (em2820/em2840)
16 15 -> V-Gear PocketTV (em2800)
17 16 -> Hauppauge WinTV HVR 950 (em2880) [2040:6513]
diff --git a/Documentation/video4linux/CARDLIST.ivtv b/Documentation/video4linux/CARDLIST.ivtv
index ddd76a0eb100..a019e27e42b3 100644
--- a/Documentation/video4linux/CARDLIST.ivtv
+++ b/Documentation/video4linux/CARDLIST.ivtv
@@ -16,3 +16,9 @@
1616 -> GOTVIEW PCI DVD2 Deluxe [ffac:0600] 1616 -> GOTVIEW PCI DVD2 Deluxe [ffac:0600]
1717 -> Yuan MPC622 [ff01:d998] 1717 -> Yuan MPC622 [ff01:d998]
1818 -> Digital Cowboy DCT-MTVP1 [1461:bfff] 1818 -> Digital Cowboy DCT-MTVP1 [1461:bfff]
1919 -> Yuan PG600V2/GotView PCI DVD Lite [ffab:0600,ffad:0600]
2020 -> Club3D ZAP-TV1x01 [ffab:0600]
2121 -> AverTV MCE 116 Plus [1461:c439]
2222 -> ASUS Falcon2 [1043:4b66,1043:462e,1043:4b2e]
2323 -> AverMedia PVR-150 Plus [1461:c035]
2424 -> AverMedia EZMaker PCI Deluxe [1461:c03f]
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index a14545300e4c..5d3b6b4d2515 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -80,7 +80,7 @@
80 79 -> Sedna/MuchTV PC TV Cardbus TV/Radio (ITO25 Rev:2B) 80 79 -> Sedna/MuchTV PC TV Cardbus TV/Radio (ITO25 Rev:2B)
81 80 -> ASUS Digimatrix TV [1043:0210] 81 80 -> ASUS Digimatrix TV [1043:0210]
82 81 -> Philips Tiger reference design [1131:2018] 82 81 -> Philips Tiger reference design [1131:2018]
83 82 -> MSI TV@Anywhere plus [1462:6231] 83 82 -> MSI TV@Anywhere plus [1462:6231,1462:8624]
84 83 -> Terratec Cinergy 250 PCI TV [153b:1160] 84 83 -> Terratec Cinergy 250 PCI TV [153b:1160]
85 84 -> LifeView FlyDVB Trio [5168:0319] 85 84 -> LifeView FlyDVB Trio [5168:0319]
86 85 -> AverTV DVB-T 777 [1461:2c05,1461:2c05] 86 85 -> AverTV DVB-T 777 [1461:2c05,1461:2c05]
@@ -102,7 +102,7 @@
102101 -> Pinnacle PCTV 310i [11bd:002f] 102101 -> Pinnacle PCTV 310i [11bd:002f]
103102 -> Avermedia AVerTV Studio 507 [1461:9715] 103102 -> Avermedia AVerTV Studio 507 [1461:9715]
104103 -> Compro Videomate DVB-T200A 104103 -> Compro Videomate DVB-T200A
105104 -> Hauppauge WinTV-HVR1110 DVB-T/Hybrid [0070:6701] 105104 -> Hauppauge WinTV-HVR1110 DVB-T/Hybrid [0070:6700,0070:6701,0070:6702,0070:6703,0070:6704,0070:6705]
106105 -> Terratec Cinergy HT PCMCIA [153b:1172] 106105 -> Terratec Cinergy HT PCMCIA [153b:1172]
107106 -> Encore ENLTV [1131:2342,1131:2341,3016:2344] 107106 -> Encore ENLTV [1131:2342,1131:2341,3016:2344]
108107 -> Encore ENLTV-FM [1131:230f] 108107 -> Encore ENLTV-FM [1131:230f]
@@ -116,3 +116,16 @@
116115 -> Sabrent PCMCIA TV-PCB05 [0919:2003] 116115 -> Sabrent PCMCIA TV-PCB05 [0919:2003]
117116 -> 10MOONS TM300 TV Card [1131:2304] 117116 -> 10MOONS TM300 TV Card [1131:2304]
118117 -> Avermedia Super 007 [1461:f01d] 118117 -> Avermedia Super 007 [1461:f01d]
119118 -> Beholder BeholdTV 401 [0000:4016]
120119 -> Beholder BeholdTV 403 [0000:4036]
121120 -> Beholder BeholdTV 403 FM [0000:4037]
122121 -> Beholder BeholdTV 405 [0000:4050]
123122 -> Beholder BeholdTV 405 FM [0000:4051]
124123 -> Beholder BeholdTV 407 [0000:4070]
125124 -> Beholder BeholdTV 407 FM [0000:4071]
126125 -> Beholder BeholdTV 409 [0000:4090]
127126 -> Beholder BeholdTV 505 FM/RDS [0000:5051,0000:505B,5ace:5050]
128127 -> Beholder BeholdTV 507 FM/RDS / BeholdTV 509 FM [0000:5071,0000:507B,5ace:5070,5ace:5090]
129128 -> Beholder BeholdTV Columbus TVFM [0000:5201]
130129 -> Beholder BeholdTV 607 / BeholdTV 609 [5ace:6070,5ace:6071,5ace:6072,5ace:6073,5ace:6090,5ace:6091,5ace:6092,5ace:6093]
131130 -> Beholder BeholdTV M6 / BeholdTV M6 Extra [5ace:6190,5ace:6193]
diff --git a/Documentation/video4linux/CARDLIST.tuner b/Documentation/video4linux/CARDLIST.tuner
index a88c02d23805..0e2394695bb8 100644
--- a/Documentation/video4linux/CARDLIST.tuner
+++ b/Documentation/video4linux/CARDLIST.tuner
@@ -52,7 +52,7 @@ tuner=50 - TCL 2002N
52tuner=51 - Philips PAL/SECAM_D (FM 1256 I-H3) 52tuner=51 - Philips PAL/SECAM_D (FM 1256 I-H3)
53tuner=52 - Thomson DTT 7610 (ATSC/NTSC) 53tuner=52 - Thomson DTT 7610 (ATSC/NTSC)
54tuner=53 - Philips FQ1286 54tuner=53 - Philips FQ1286
55tuner=54 - tda8290+75 55tuner=54 - Philips/NXP TDA 8290/8295 + 8275/8275A/18271
56tuner=55 - TCL 2002MB 56tuner=55 - TCL 2002MB
57tuner=56 - Philips PAL/SECAM multi (FQ1216AME MK4) 57tuner=56 - Philips PAL/SECAM multi (FQ1216AME MK4)
58tuner=57 - Philips FQ1236A MK4 58tuner=57 - Philips FQ1236A MK4
@@ -69,7 +69,8 @@ tuner=67 - Philips TD1316 Hybrid Tuner
69tuner=68 - Philips TUV1236D ATSC/NTSC dual in 69tuner=68 - Philips TUV1236D ATSC/NTSC dual in
70tuner=69 - Tena TNF 5335 and similar models 70tuner=69 - Tena TNF 5335 and similar models
71tuner=70 - Samsung TCPN 2121P30A 71tuner=70 - Samsung TCPN 2121P30A
72tuner=71 - Xceive xc3028 72tuner=71 - Xceive xc2028/xc3028 tuner
73tuner=72 - Thomson FE6600 73tuner=72 - Thomson FE6600
74tuner=73 - Samsung TCPG 6121P30A 74tuner=73 - Samsung TCPG 6121P30A
75tuner=75 - Philips TEA5761 FM Radio 75tuner=75 - Philips TEA5761 FM Radio
76tuner=76 - Xceive 5000 tuner
diff --git a/Documentation/video4linux/CARDLIST.usbvision b/Documentation/video4linux/CARDLIST.usbvision
index 3d6850ef0245..0b72d3fee17e 100644
--- a/Documentation/video4linux/CARDLIST.usbvision
+++ b/Documentation/video4linux/CARDLIST.usbvision
@@ -62,3 +62,4 @@
62 61 -> Pinnacle Studio Linx Video input cable (PAL) [2304:0301] 62 61 -> Pinnacle Studio Linx Video input cable (PAL) [2304:0301]
63 62 -> Pinnacle PCTV Bungee USB (PAL) FM [2304:0419] 63 62 -> Pinnacle PCTV Bungee USB (PAL) FM [2304:0419]
64 63 -> Hauppauge WinTv-USB [2400:4200] 64 63 -> Hauppauge WinTv-USB [2400:4200]
65 64 -> Pinnacle Studio PCTV USB (NTSC) FM V3 [2304:0113]
diff --git a/Documentation/video4linux/extract_xc3028.pl b/Documentation/video4linux/extract_xc3028.pl
new file mode 100644
index 000000000000..cced8ac5c543
--- /dev/null
+++ b/Documentation/video4linux/extract_xc3028.pl
@@ -0,0 +1,926 @@
1#!/usr/bin/perl
2
3# Copyright (c) Mauro Carvalho Chehab <mchehab@infradead.org>
4# Released under GPLv2
5#
6# In order to use, you need to:
7# 1) Download the windows driver with something like:
8# wget http://www.steventoth.net/linux/xc5000/HVR-12x0-14x0-17x0_1_25_25271_WHQL.zip
9# 2) Extract the file hcw85bda.sys from the zip into the current dir:
10# unzip -j HVR-12x0-14x0-17x0_1_25_25271_WHQL.zip Driver85/hcw85bda.sys
11# 3) run the script:
12# ./extract_xc3028.pl
13# 4) copy the generated file:
14# cp xc3028-v27.fw /lib/firmware
15
16#use strict;
17use IO::Handle;
18
19my $debug=0;
20
21sub verify ($$)
22{
23 my ($filename, $hash) = @_;
24 my ($testhash);
25
26 if (system("which md5sum > /dev/null 2>&1")) {
27 die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
28 }
29
30 open(CMD, "md5sum ".$filename."|");
31 $testhash = <CMD>;
32 $testhash =~ /([a-zA-Z0-9]*)/;
33 $testhash = $1;
34 close CMD;
35 die "Hash of extracted file does not match (found $testhash, expected $hash!\n" if ($testhash ne $hash);
36}
37
38sub get_hunk ($$)
39{
40 my ($offset, $length) = @_;
41 my ($chunklength, $buf, $rcount, $out);
42
43 sysseek(INFILE, $offset, SEEK_SET);
44 while ($length > 0) {
45 # Calc chunk size
46 $chunklength = 2048;
47 $chunklength = $length if ($chunklength > $length);
48
49 $rcount = sysread(INFILE, $buf, $chunklength);
50 die "Ran out of data\n" if ($rcount != $chunklength);
51 $out .= $buf;
52 $length -= $rcount;
53 }
54 return $out;
55}
56
57sub write_le16($)
58{
59 my $val = shift;
60 my $msb = ($val >> 8) &0xff;
61 my $lsb = $val & 0xff;
62
63 syswrite(OUTFILE, chr($lsb).chr($msb));
64}
65
66sub write_le32($)
67{
68 my $val = shift;
69 my $l3 = ($val >> 24) & 0xff;
70 my $l2 = ($val >> 16) & 0xff;
71 my $l1 = ($val >> 8) & 0xff;
72 my $l0 = $val & 0xff;
73
74 syswrite(OUTFILE, chr($l0).chr($l1).chr($l2).chr($l3));
75}
76
77sub write_le64($$)
78{
79 my $msb_val = shift;
80 my $lsb_val = shift;
81 my $l7 = ($msb_val >> 24) & 0xff;
82 my $l6 = ($msb_val >> 16) & 0xff;
83 my $l5 = ($msb_val >> 8) & 0xff;
84 my $l4 = $msb_val & 0xff;
85
86 my $l3 = ($lsb_val >> 24) & 0xff;
87 my $l2 = ($lsb_val >> 16) & 0xff;
88 my $l1 = ($lsb_val >> 8) & 0xff;
89 my $l0 = $lsb_val & 0xff;
90
91 syswrite(OUTFILE,
92 chr($l0).chr($l1).chr($l2).chr($l3).
93 chr($l4).chr($l5).chr($l6).chr($l7));
94}
95
96sub write_hunk($$)
97{
98 my ($offset, $length) = @_;
99 my $out = get_hunk($offset, $length);
100
101 printf "(len %d) ",$length if ($debug);
102
103 for (my $i=0;$i<$length;$i++) {
104 printf "%02x ",ord(substr($out,$i,1)) if ($debug);
105 }
106 printf "\n" if ($debug);
107
108 syswrite(OUTFILE, $out);
109}
110
111sub write_hunk_fix_endian($$)
112{
113 my ($offset, $length) = @_;
114 my $out = get_hunk($offset, $length);
115
116 printf "(len_fix %d) ",$length if ($debug);
117
118 for (my $i=0;$i<$length;$i++) {
119 printf "%02x ",ord(substr($out,$i,1)) if ($debug);
120 }
121 printf "\n" if ($debug);
122
123 my $i=0;
124 while ($i<$length) {
125 my $size = ord(substr($out,$i,1))*256+ord(substr($out,$i+1,1));
126 syswrite(OUTFILE, substr($out,$i+1,1));
127 syswrite(OUTFILE, substr($out,$i,1));
128 $i+=2;
129 if ($size>0 && $size <0x8000) {
130 for (my $j=0;$j<$size;$j++) {
131 syswrite(OUTFILE, substr($out,$j+$i,1));
132 }
133 $i+=$size;
134 }
135 }
136}
137
138sub main_firmware($$$$)
139{
140 my $out;
141 my $j=0;
142 my $outfile = shift;
143 my $name = shift;
144 my $version = shift;
145 my $nr_desc = shift;
146
147 for ($j = length($name); $j <32; $j++) {
148 $name = $name.chr(0);
149}
150
151 open OUTFILE, ">$outfile";
152 syswrite(OUTFILE, $name);
153 write_le16($version);
154 write_le16($nr_desc);
155
156 #
157 # Firmware 0, type: BASE FW F8MHZ (0x00000003), id: (0000000000000000), size: 8718
158 #
159
160 write_le32(0x00000003); # Type
161 write_le64(0x00000000, 0x00000000); # ID
162 write_le32(8718); # Size
163 write_hunk_fix_endian(813432, 8718);
164
165 #
166 # Firmware 1, type: BASE FW F8MHZ MTS (0x00000007), id: (0000000000000000), size: 8712
167 #
168
169 write_le32(0x00000007); # Type
170 write_le64(0x00000000, 0x00000000); # ID
171 write_le32(8712); # Size
172 write_hunk_fix_endian(822152, 8712);
173
174 #
175 # Firmware 2, type: BASE FW FM (0x00000401), id: (0000000000000000), size: 8562
176 #
177
178 write_le32(0x00000401); # Type
179 write_le64(0x00000000, 0x00000000); # ID
180 write_le32(8562); # Size
181 write_hunk_fix_endian(830872, 8562);
182
183 #
184 # Firmware 3, type: BASE FW FM INPUT1 (0x00000c01), id: (0000000000000000), size: 8576
185 #
186
187 write_le32(0x00000c01); # Type
188 write_le64(0x00000000, 0x00000000); # ID
189 write_le32(8576); # Size
190 write_hunk_fix_endian(839440, 8576);
191
192 #
193 # Firmware 4, type: BASE FW (0x00000001), id: (0000000000000000), size: 8706
194 #
195
196 write_le32(0x00000001); # Type
197 write_le64(0x00000000, 0x00000000); # ID
198 write_le32(8706); # Size
199 write_hunk_fix_endian(848024, 8706);
200
201 #
202 # Firmware 5, type: BASE FW MTS (0x00000005), id: (0000000000000000), size: 8682
203 #
204
205 write_le32(0x00000005); # Type
206 write_le64(0x00000000, 0x00000000); # ID
207 write_le32(8682); # Size
208 write_hunk_fix_endian(856736, 8682);
209
210 #
211 # Firmware 6, type: STD FW (0x00000000), id: PAL/BG A2/A (0000000100000007), size: 161
212 #
213
214 write_le32(0x00000000); # Type
215 write_le64(0x00000001, 0x00000007); # ID
216 write_le32(161); # Size
217 write_hunk_fix_endian(865424, 161);
218
219 #
220 # Firmware 7, type: STD FW MTS (0x00000004), id: PAL/BG A2/A (0000000100000007), size: 169
221 #
222
223 write_le32(0x00000004); # Type
224 write_le64(0x00000001, 0x00000007); # ID
225 write_le32(169); # Size
226 write_hunk_fix_endian(865592, 169);
227
228 #
229 # Firmware 8, type: STD FW (0x00000000), id: PAL/BG A2/B (0000000200000007), size: 161
230 #
231
232 write_le32(0x00000000); # Type
233 write_le64(0x00000002, 0x00000007); # ID
234 write_le32(161); # Size
235 write_hunk_fix_endian(865424, 161);
236
237 #
238 # Firmware 9, type: STD FW MTS (0x00000004), id: PAL/BG A2/B (0000000200000007), size: 169
239 #
240
241 write_le32(0x00000004); # Type
242 write_le64(0x00000002, 0x00000007); # ID
243 write_le32(169); # Size
244 write_hunk_fix_endian(865592, 169);
245
246 #
247 # Firmware 10, type: STD FW (0x00000000), id: PAL/BG NICAM/A (0000000400000007), size: 161
248 #
249
250 write_le32(0x00000000); # Type
251 write_le64(0x00000004, 0x00000007); # ID
252 write_le32(161); # Size
253 write_hunk_fix_endian(866112, 161);
254
255 #
256 # Firmware 11, type: STD FW MTS (0x00000004), id: PAL/BG NICAM/A (0000000400000007), size: 169
257 #
258
259 write_le32(0x00000004); # Type
260 write_le64(0x00000004, 0x00000007); # ID
261 write_le32(169); # Size
262 write_hunk_fix_endian(866280, 169);
263
264 #
265 # Firmware 12, type: STD FW (0x00000000), id: PAL/BG NICAM/B (0000000800000007), size: 161
266 #
267
268 write_le32(0x00000000); # Type
269 write_le64(0x00000008, 0x00000007); # ID
270 write_le32(161); # Size
271 write_hunk_fix_endian(866112, 161);
272
273 #
274 # Firmware 13, type: STD FW MTS (0x00000004), id: PAL/BG NICAM/B (0000000800000007), size: 169
275 #
276
277 write_le32(0x00000004); # Type
278 write_le64(0x00000008, 0x00000007); # ID
279 write_le32(169); # Size
280 write_hunk_fix_endian(866280, 169);
281
282 #
283 # Firmware 14, type: STD FW (0x00000000), id: PAL/DK A2 (00000003000000e0), size: 161
284 #
285
286 write_le32(0x00000000); # Type
287 write_le64(0x00000003, 0x000000e0); # ID
288 write_le32(161); # Size
289 write_hunk_fix_endian(866800, 161);
290
291 #
292 # Firmware 15, type: STD FW MTS (0x00000004), id: PAL/DK A2 (00000003000000e0), size: 169
293 #
294
295 write_le32(0x00000004); # Type
296 write_le64(0x00000003, 0x000000e0); # ID
297 write_le32(169); # Size
298 write_hunk_fix_endian(866968, 169);
299
300 #
301 # Firmware 16, type: STD FW (0x00000000), id: PAL/DK NICAM (0000000c000000e0), size: 161
302 #
303
304 write_le32(0x00000000); # Type
305 write_le64(0x0000000c, 0x000000e0); # ID
306 write_le32(161); # Size
307 write_hunk_fix_endian(867144, 161);
308
309 #
310 # Firmware 17, type: STD FW MTS (0x00000004), id: PAL/DK NICAM (0000000c000000e0), size: 169
311 #
312
313 write_le32(0x00000004); # Type
314 write_le64(0x0000000c, 0x000000e0); # ID
315 write_le32(169); # Size
316 write_hunk_fix_endian(867312, 169);
317
318 #
319 # Firmware 18, type: STD FW (0x00000000), id: SECAM/K1 (0000000000200000), size: 161
320 #
321
322 write_le32(0x00000000); # Type
323 write_le64(0x00000000, 0x00200000); # ID
324 write_le32(161); # Size
325 write_hunk_fix_endian(867488, 161);
326
327 #
328 # Firmware 19, type: STD FW MTS (0x00000004), id: SECAM/K1 (0000000000200000), size: 169
329 #
330
331 write_le32(0x00000004); # Type
332 write_le64(0x00000000, 0x00200000); # ID
333 write_le32(169); # Size
334 write_hunk_fix_endian(867656, 169);
335
336 #
337 # Firmware 20, type: STD FW (0x00000000), id: SECAM/K3 (0000000004000000), size: 161
338 #
339
340 write_le32(0x00000000); # Type
341 write_le64(0x00000000, 0x04000000); # ID
342 write_le32(161); # Size
343 write_hunk_fix_endian(867832, 161);
344
345 #
346 # Firmware 21, type: STD FW MTS (0x00000004), id: SECAM/K3 (0000000004000000), size: 169
347 #
348
349 write_le32(0x00000004); # Type
350 write_le64(0x00000000, 0x04000000); # ID
351 write_le32(169); # Size
352 write_hunk_fix_endian(868000, 169);
353
354 #
355 # Firmware 22, type: STD FW D2633 DTV6 ATSC (0x00010030), id: (0000000000000000), size: 149
356 #
357
358 write_le32(0x00010030); # Type
359 write_le64(0x00000000, 0x00000000); # ID
360 write_le32(149); # Size
361 write_hunk_fix_endian(868176, 149);
362
363 #
364 # Firmware 23, type: STD FW D2620 DTV6 QAM (0x00000068), id: (0000000000000000), size: 149
365 #
366
367 write_le32(0x00000068); # Type
368 write_le64(0x00000000, 0x00000000); # ID
369 write_le32(149); # Size
370 write_hunk_fix_endian(868336, 149);
371
372 #
373 # Firmware 24, type: STD FW D2633 DTV6 QAM (0x00000070), id: (0000000000000000), size: 149
374 #
375
376 write_le32(0x00000070); # Type
377 write_le64(0x00000000, 0x00000000); # ID
378 write_le32(149); # Size
379 write_hunk_fix_endian(868488, 149);
380
381 #
382 # Firmware 25, type: STD FW D2620 DTV7 (0x00000088), id: (0000000000000000), size: 149
383 #
384
385 write_le32(0x00000088); # Type
386 write_le64(0x00000000, 0x00000000); # ID
387 write_le32(149); # Size
388 write_hunk_fix_endian(868648, 149);
389
390 #
391 # Firmware 26, type: STD FW D2633 DTV7 (0x00000090), id: (0000000000000000), size: 149
392 #
393
394 write_le32(0x00000090); # Type
395 write_le64(0x00000000, 0x00000000); # ID
396 write_le32(149); # Size
397 write_hunk_fix_endian(868800, 149);
398
399 #
400 # Firmware 27, type: STD FW D2620 DTV78 (0x00000108), id: (0000000000000000), size: 149
401 #
402
403 write_le32(0x00000108); # Type
404 write_le64(0x00000000, 0x00000000); # ID
405 write_le32(149); # Size
406 write_hunk_fix_endian(868960, 149);
407
408 #
409 # Firmware 28, type: STD FW D2633 DTV78 (0x00000110), id: (0000000000000000), size: 149
410 #
411
412 write_le32(0x00000110); # Type
413 write_le64(0x00000000, 0x00000000); # ID
414 write_le32(149); # Size
415 write_hunk_fix_endian(869112, 149);
416
417 #
418 # Firmware 29, type: STD FW D2620 DTV8 (0x00000208), id: (0000000000000000), size: 149
419 #
420
421 write_le32(0x00000208); # Type
422 write_le64(0x00000000, 0x00000000); # ID
423 write_le32(149); # Size
424 write_hunk_fix_endian(868648, 149);
425
426 #
427 # Firmware 30, type: STD FW D2633 DTV8 (0x00000210), id: (0000000000000000), size: 149
428 #
429
430 write_le32(0x00000210); # Type
431 write_le64(0x00000000, 0x00000000); # ID
432 write_le32(149); # Size
433 write_hunk_fix_endian(868800, 149);
434
435 #
436 # Firmware 31, type: STD FW FM (0x00000400), id: (0000000000000000), size: 135
437 #
438
439 write_le32(0x00000400); # Type
440 write_le64(0x00000000, 0x00000000); # ID
441 write_le32(135); # Size
442 write_hunk_fix_endian(869584, 135);
443
444 #
445 # Firmware 32, type: STD FW (0x00000000), id: PAL/I (0000000000000010), size: 161
446 #
447
448 write_le32(0x00000000); # Type
449 write_le64(0x00000000, 0x00000010); # ID
450 write_le32(161); # Size
451 write_hunk_fix_endian(869728, 161);
452
453 #
454 # Firmware 33, type: STD FW MTS (0x00000004), id: PAL/I (0000000000000010), size: 169
455 #
456
457 write_le32(0x00000004); # Type
458 write_le64(0x00000000, 0x00000010); # ID
459 write_le32(169); # Size
460 write_hunk_fix_endian(869896, 169);
461
462 #
463 # Firmware 34, type: STD FW (0x00000000), id: SECAM/L AM (0000001000400000), size: 169
464 #
465
466 write_le32(0x00000000); # Type
467 write_le64(0x00000010, 0x00400000); # ID
468 write_le32(169); # Size
469 write_hunk_fix_endian(870072, 169);
470
471 #
472 # Firmware 35, type: STD FW (0x00000000), id: SECAM/L NICAM (0000000c00400000), size: 161
473 #
474
475 write_le32(0x00000000); # Type
476 write_le64(0x0000000c, 0x00400000); # ID
477 write_le32(161); # Size
478 write_hunk_fix_endian(870248, 161);
479
480 #
481 # Firmware 36, type: STD FW (0x00000000), id: SECAM/Lc (0000000000800000), size: 161
482 #
483
484 write_le32(0x00000000); # Type
485 write_le64(0x00000000, 0x00800000); # ID
486 write_le32(161); # Size
487 write_hunk_fix_endian(870416, 161);
488
489 #
490 # Firmware 37, type: STD FW (0x00000000), id: NTSC/M Kr (0000000000008000), size: 161
491 #
492
493 write_le32(0x00000000); # Type
494 write_le64(0x00000000, 0x00008000); # ID
495 write_le32(161); # Size
496 write_hunk_fix_endian(870584, 161);
497
498 #
499 # Firmware 38, type: STD FW LCD (0x00001000), id: NTSC/M Kr (0000000000008000), size: 161
500 #
501
502 write_le32(0x00001000); # Type
503 write_le64(0x00000000, 0x00008000); # ID
504 write_le32(161); # Size
505 write_hunk_fix_endian(870752, 161);
506
507 #
508 # Firmware 39, type: STD FW LCD NOGD (0x00003000), id: NTSC/M Kr (0000000000008000), size: 161
509 #
510
511 write_le32(0x00003000); # Type
512 write_le64(0x00000000, 0x00008000); # ID
513 write_le32(161); # Size
514 write_hunk_fix_endian(870920, 161);
515
516 #
517 # Firmware 40, type: STD FW MTS (0x00000004), id: NTSC/M Kr (0000000000008000), size: 169
518 #
519
520 write_le32(0x00000004); # Type
521 write_le64(0x00000000, 0x00008000); # ID
522 write_le32(169); # Size
523 write_hunk_fix_endian(871088, 169);
524
525 #
526 # Firmware 41, type: STD FW (0x00000000), id: NTSC PAL/M PAL/N (000000000000b700), size: 161
527 #
528
529 write_le32(0x00000000); # Type
530 write_le64(0x00000000, 0x0000b700); # ID
531 write_le32(161); # Size
532 write_hunk_fix_endian(871264, 161);
533
534 #
535 # Firmware 42, type: STD FW LCD (0x00001000), id: NTSC PAL/M PAL/N (000000000000b700), size: 161
536 #
537
538 write_le32(0x00001000); # Type
539 write_le64(0x00000000, 0x0000b700); # ID
540 write_le32(161); # Size
541 write_hunk_fix_endian(871432, 161);
542
543 #
544 # Firmware 43, type: STD FW LCD NOGD (0x00003000), id: NTSC PAL/M PAL/N (000000000000b700), size: 161
545 #
546
547 write_le32(0x00003000); # Type
548 write_le64(0x00000000, 0x0000b700); # ID
549 write_le32(161); # Size
550 write_hunk_fix_endian(871600, 161);
551
552 #
553 # Firmware 44, type: STD FW (0x00000000), id: NTSC/M Jp (0000000000002000), size: 161
554 #
555
556 write_le32(0x00000000); # Type
557 write_le64(0x00000000, 0x00002000); # ID
558 write_le32(161); # Size
559 write_hunk_fix_endian(871264, 161);
560
561 #
562 # Firmware 45, type: STD FW MTS (0x00000004), id: NTSC PAL/M PAL/N (000000000000b700), size: 169
563 #
564
565 write_le32(0x00000004); # Type
566 write_le64(0x00000000, 0x0000b700); # ID
567 write_le32(169); # Size
568 write_hunk_fix_endian(871936, 169);
569
570 #
571 # Firmware 46, type: STD FW MTS LCD (0x00001004), id: NTSC PAL/M PAL/N (000000000000b700), size: 169
572 #
573
574 write_le32(0x00001004); # Type
575 write_le64(0x00000000, 0x0000b700); # ID
576 write_le32(169); # Size
577 write_hunk_fix_endian(872112, 169);
578
579 #
580 # Firmware 47, type: STD FW MTS LCD NOGD (0x00003004), id: NTSC PAL/M PAL/N (000000000000b700), size: 169
581 #
582
583 write_le32(0x00003004); # Type
584 write_le64(0x00000000, 0x0000b700); # ID
585 write_le32(169); # Size
586 write_hunk_fix_endian(872288, 169);
587
588 #
589 # Firmware 48, type: SCODE FW HAS IF (0x60000000), IF = 3.28 MHz id: (0000000000000000), size: 192
590 #
591
592 write_le32(0x60000000); # Type
593 write_le64(0x00000000, 0x00000000); # ID
594 write_le16(3280); # IF
595 write_le32(192); # Size
596 write_hunk(811896, 192);
597
598 #
599 # Firmware 49, type: SCODE FW HAS IF (0x60000000), IF = 3.30 MHz id: (0000000000000000), size: 192
600 #
601
602 write_le32(0x60000000); # Type
603 write_le64(0x00000000, 0x00000000); # ID
604 write_le16(3300); # IF
605 write_le32(192); # Size
606 write_hunk(813048, 192);
607
608 #
609 # Firmware 50, type: SCODE FW HAS IF (0x60000000), IF = 3.44 MHz id: (0000000000000000), size: 192
610 #
611
612 write_le32(0x60000000); # Type
613 write_le64(0x00000000, 0x00000000); # ID
614 write_le16(3440); # IF
615 write_le32(192); # Size
616 write_hunk(812280, 192);
617
618 #
619 # Firmware 51, type: SCODE FW HAS IF (0x60000000), IF = 3.46 MHz id: (0000000000000000), size: 192
620 #
621
622 write_le32(0x60000000); # Type
623 write_le64(0x00000000, 0x00000000); # ID
624 write_le16(3460); # IF
625 write_le32(192); # Size
626 write_hunk(812472, 192);
627
628 #
629 # Firmware 52, type: SCODE FW DTV6 ATSC OREN36 HAS IF (0x60210020), IF = 3.80 MHz id: (0000000000000000), size: 192
630 #
631
632 write_le32(0x60210020); # Type
633 write_le64(0x00000000, 0x00000000); # ID
634 write_le16(3800); # IF
635 write_le32(192); # Size
636 write_hunk(809784, 192);
637
638 #
639 # Firmware 53, type: SCODE FW HAS IF (0x60000000), IF = 4.00 MHz id: (0000000000000000), size: 192
640 #
641
642 write_le32(0x60000000); # Type
643 write_le64(0x00000000, 0x00000000); # ID
644 write_le16(4000); # IF
645 write_le32(192); # Size
646 write_hunk(812088, 192);
647
648 #
649 # Firmware 54, type: SCODE FW DTV6 ATSC TOYOTA388 HAS IF (0x60410020), IF = 4.08 MHz id: (0000000000000000), size: 192
650 #
651
652 write_le32(0x60410020); # Type
653 write_le64(0x00000000, 0x00000000); # ID
654 write_le16(4080); # IF
655 write_le32(192); # Size
656 write_hunk(809976, 192);
657
658 #
659 # Firmware 55, type: SCODE FW HAS IF (0x60000000), IF = 4.20 MHz id: (0000000000000000), size: 192
660 #
661
662 write_le32(0x60000000); # Type
663 write_le64(0x00000000, 0x00000000); # ID
664 write_le16(4200); # IF
665 write_le32(192); # Size
666 write_hunk(811704, 192);
667
668 #
669 # Firmware 56, type: SCODE FW MONO HAS IF (0x60008000), IF = 4.32 MHz id: NTSC/M Kr (0000000000008000), size: 192
670 #
671
672 write_le32(0x60008000); # Type
673 write_le64(0x00000000, 0x00008000); # ID
674 write_le16(4320); # IF
675 write_le32(192); # Size
676 write_hunk(808056, 192);
677
678 #
679 # Firmware 57, type: SCODE FW HAS IF (0x60000000), IF = 4.45 MHz id: (0000000000000000), size: 192
680 #
681
682 write_le32(0x60000000); # Type
683 write_le64(0x00000000, 0x00000000); # ID
684 write_le16(4450); # IF
685 write_le32(192); # Size
686 write_hunk(812664, 192);
687
688 #
689 # Firmware 58, type: SCODE FW HAS IF (0x60000000), IF = 4.50 MHz id: NTSC/M Jp (0000000000002000), size: 192
690 #
691
692 write_le32(0x60000000); # Type
693 write_le64(0x00000000, 0x00002000); # ID
694 write_le16(4500); # IF
695 write_le32(192); # Size
696 write_hunk(807672, 192);
697
698 #
699 # Firmware 59, type: SCODE FW LCD NOGD IF HAS IF (0x60023000), IF = 4.60 MHz id: NTSC/M Kr (0000000000008000), size: 192
700 #
701
702 write_le32(0x60023000); # Type
703 write_le64(0x00000000, 0x00008000); # ID
704 write_le16(4600); # IF
705 write_le32(192); # Size
706 write_hunk(807864, 192);
707
708 #
709 # Firmware 60, type: SCODE FW DTV78 ZARLINK456 HAS IF (0x62000100), IF = 4.76 MHz id: (0000000000000000), size: 192
710 #
711
712 write_le32(0x62000100); # Type
713 write_le64(0x00000000, 0x00000000); # ID
714 write_le16(4760); # IF
715 write_le32(192); # Size
716 write_hunk(807288, 192);
717
718 #
719 # Firmware 61, type: SCODE FW HAS IF (0x60000000), IF = 4.94 MHz id: (0000000000000000), size: 192
720 #
721
722 write_le32(0x60000000); # Type
723 write_le64(0x00000000, 0x00000000); # ID
724 write_le16(4940); # IF
725 write_le32(192); # Size
726 write_hunk(811512, 192);
727
728 #
729 # Firmware 62, type: SCODE FW DTV7 ZARLINK456 HAS IF (0x62000080), IF = 5.26 MHz id: (0000000000000000), size: 192
730 #
731
732 write_le32(0x62000080); # Type
733 write_le64(0x00000000, 0x00000000); # ID
734 write_le16(5260); # IF
735 write_le32(192); # Size
736 write_hunk(810552, 192);
737
738 #
739 # Firmware 63, type: SCODE FW MONO HAS IF (0x60008000), IF = 5.32 MHz id: PAL/BG NICAM/B (0000000800000007), size: 192
740 #
741
742 write_le32(0x60008000); # Type
743 write_le64(0x00000008, 0x00000007); # ID
744 write_le16(5320); # IF
745 write_le32(192); # Size
746 write_hunk(810744, 192);
747
748 #
749 # Firmware 64, type: SCODE FW DTV8 CHINA HAS IF (0x64000200), IF = 5.40 MHz id: (0000000000000000), size: 192
750 #
751
752 write_le32(0x64000200); # Type
753 write_le64(0x00000000, 0x00000000); # ID
754 write_le16(5400); # IF
755 write_le32(192); # Size
756 write_hunk(807096, 192);
757
758 #
759 # Firmware 65, type: SCODE FW DTV6 ATSC OREN538 HAS IF (0x60110020), IF = 5.58 MHz id: (0000000000000000), size: 192
760 #
761
762 write_le32(0x60110020); # Type
763 write_le64(0x00000000, 0x00000000); # ID
764 write_le16(5580); # IF
765 write_le32(192); # Size
766 write_hunk(809592, 192);
767
768 #
769 # Firmware 66, type: SCODE FW HAS IF (0x60000000), IF = 5.64 MHz id: PAL/BG A2/B (0000000200000007), size: 192
770 #
771
772 write_le32(0x60000000); # Type
773 write_le64(0x00000002, 0x00000007); # ID
774 write_le16(5640); # IF
775 write_le32(192); # Size
776 write_hunk(808440, 192);
777
778 #
779 # Firmware 67, type: SCODE FW HAS IF (0x60000000), IF = 5.74 MHz id: PAL/BG NICAM/B (0000000800000007), size: 192
780 #
781
782 write_le32(0x60000000); # Type
783 write_le64(0x00000008, 0x00000007); # ID
784 write_le16(5740); # IF
785 write_le32(192); # Size
786 write_hunk(808632, 192);
787
788 #
789 # Firmware 68, type: SCODE FW DTV7 DIBCOM52 HAS IF (0x61000080), IF = 5.90 MHz id: (0000000000000000), size: 192
790 #
791
792 write_le32(0x61000080); # Type
793 write_le64(0x00000000, 0x00000000); # ID
794 write_le16(5900); # IF
795 write_le32(192); # Size
796 write_hunk(810360, 192);
797
798 #
799 # Firmware 69, type: SCODE FW MONO HAS IF (0x60008000), IF = 6.00 MHz id: PAL/I (0000000000000010), size: 192
800 #
801
802 write_le32(0x60008000); # Type
803 write_le64(0x00000000, 0x00000010); # ID
804 write_le16(6000); # IF
805 write_le32(192); # Size
806 write_hunk(808824, 192);
807
808 #
809 # Firmware 70, type: SCODE FW DTV6 QAM F6MHZ HAS IF (0x68000060), IF = 6.20 MHz id: (0000000000000000), size: 192
810 #
811
812 write_le32(0x68000060); # Type
813 write_le64(0x00000000, 0x00000000); # ID
814 write_le16(6200); # IF
815 write_le32(192); # Size
816 write_hunk(809400, 192);
817
818 #
819 # Firmware 71, type: SCODE FW HAS IF (0x60000000), IF = 6.24 MHz id: PAL/I (0000000000000010), size: 192
820 #
821
822 write_le32(0x60000000); # Type
823 write_le64(0x00000000, 0x00000010); # ID
824 write_le16(6240); # IF
825 write_le32(192); # Size
826 write_hunk(808248, 192);
827
828 #
829 # Firmware 72, type: SCODE FW MONO HAS IF (0x60008000), IF = 6.32 MHz id: SECAM/K1 (0000000000200000), size: 192
830 #
831
832 write_le32(0x60008000); # Type
833 write_le64(0x00000000, 0x00200000); # ID
834 write_le16(6320); # IF
835 write_le32(192); # Size
836 write_hunk(811320, 192);
837
838 #
839 # Firmware 73, type: SCODE FW HAS IF (0x60000000), IF = 6.34 MHz id: SECAM/K1 (0000000000200000), size: 192
840 #
841
842 write_le32(0x60000000); # Type
843 write_le64(0x00000000, 0x00200000); # ID
844 write_le16(6340); # IF
845 write_le32(192); # Size
846 write_hunk(809208, 192);
847
848 #
849 # Firmware 74, type: SCODE FW MONO HAS IF (0x60008000), IF = 6.50 MHz id: SECAM/K3 (0000000004000000), size: 192
850 #
851
852 write_le32(0x60008000); # Type
853 write_le64(0x00000000, 0x04000000); # ID
854 write_le16(6500); # IF
855 write_le32(192); # Size
856 write_hunk(811128, 192);
857
858 #
859 # Firmware 75, type: SCODE FW DTV6 ATSC ATI638 HAS IF (0x60090020), IF = 6.58 MHz id: (0000000000000000), size: 192
860 #
861
862 write_le32(0x60090020); # Type
863 write_le64(0x00000000, 0x00000000); # ID
864 write_le16(6580); # IF
865 write_le32(192); # Size
866 write_hunk(807480, 192);
867
868 #
869 # Firmware 76, type: SCODE FW HAS IF (0x60000000), IF = 6.60 MHz id: PAL/DK A2 (00000003000000e0), size: 192
870 #
871
872 write_le32(0x60000000); # Type
873 write_le64(0x00000003, 0x000000e0); # ID
874 write_le16(6600); # IF
875 write_le32(192); # Size
876 write_hunk(809016, 192);
877
878 #
879 # Firmware 77, type: SCODE FW MONO HAS IF (0x60008000), IF = 6.68 MHz id: PAL/DK A2 (00000003000000e0), size: 192
880 #
881
882 write_le32(0x60008000); # Type
883 write_le64(0x00000003, 0x000000e0); # ID
884 write_le16(6680); # IF
885 write_le32(192); # Size
886 write_hunk(810936, 192);
887
888 #
889 # Firmware 78, type: SCODE FW DTV6 ATSC TOYOTA794 HAS IF (0x60810020), IF = 8.14 MHz id: (0000000000000000), size: 192
890 #
891
892 write_le32(0x60810020); # Type
893 write_le64(0x00000000, 0x00000000); # ID
894 write_le16(8140); # IF
895 write_le32(192); # Size
896 write_hunk(810168, 192);
897
898 #
899 # Firmware 79, type: SCODE FW HAS IF (0x60000000), IF = 8.20 MHz id: (0000000000000000), size: 192
900 #
901
902 write_le32(0x60000000); # Type
903 write_le64(0x00000000, 0x00000000); # ID
904 write_le16(8200); # IF
905 write_le32(192); # Size
906 write_hunk(812856, 192);
907}
908
909sub extract_firmware {
910 my $sourcefile = "hcw85bda.sys";
911 my $hash = "0e44dbf63bb0169d57446aec21881ff2";
912 my $outfile = "xc3028-v27.fw";
913 my $name = "xc2028 firmware";
914 my $version = 519;
915 my $nr_desc = 80;
916 my $out;
917
918 verify($sourcefile, $hash);
919
920 open INFILE, "<$sourcefile";
921 main_firmware($outfile, $name, $version, $nr_desc);
922 close INFILE;
923}
924
925extract_firmware;
926printf "Firmwares generated.\n";
diff --git a/Documentation/video4linux/sn9c102.txt b/Documentation/video4linux/sn9c102.txt
index 1ffad19ce891..b26f5195af51 100644
--- a/Documentation/video4linux/sn9c102.txt
+++ b/Documentation/video4linux/sn9c102.txt
@@ -568,6 +568,7 @@ the fingerprint is: '88E8 F32F 7244 68BA 3958 5D40 99DA 5D2A FCE6 35A4'.
568Many thanks to following persons for their contribute (listed in alphabetical 568Many thanks to following persons for their contribute (listed in alphabetical
569order): 569order):
570 570
571- David Anderson for the donation of a webcam;
571- Luca Capello for the donation of a webcam; 572- Luca Capello for the donation of a webcam;
572- Philippe Coval for having helped testing the PAS202BCA image sensor; 573- Philippe Coval for having helped testing the PAS202BCA image sensor;
573- Joao Rodrigo Fuzaro, Joao Limirio, Claudio Filho and Caio Begotti for the 574- Joao Rodrigo Fuzaro, Joao Limirio, Claudio Filho and Caio Begotti for the
diff --git a/MAINTAINERS b/MAINTAINERS
index 2340cfb1e25d..17524afa7475 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2141,6 +2141,15 @@ L: isdn4linux@listserv.isdn4linux.de
2141W: http://www.melware.de 2141W: http://www.melware.de
2142S: Maintained 2142S: Maintained
2143 2143
2144IVTV VIDEO4LINUX DRIVER
2145P: Hans Verkuil
2146M: hverkuil@xs4all.nl
2147L: ivtv-devel@ivtvdriver.org
2148L: ivtv-users@ivtvdriver.org
2149L: video4linux-list@redhat.com
2150W: http://www.ivtvdriver.org
2151S: Maintained
2152
2144JOURNALLING FLASH FILE SYSTEM V2 (JFFS2) 2153JOURNALLING FLASH FILE SYSTEM V2 (JFFS2)
2145P: David Woodhouse 2154P: David Woodhouse
2146M: dwmw2@infradead.org 2155M: dwmw2@infradead.org
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 1604f0490404..8f4a45346de7 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -69,11 +69,13 @@ source "drivers/media/common/Kconfig"
69config VIDEO_TUNER 69config VIDEO_TUNER
70 tristate 70 tristate
71 depends on I2C 71 depends on I2C
72 select TUNER_XC2028 if !VIDEO_TUNER_CUSTOMIZE
72 select TUNER_MT20XX if !VIDEO_TUNER_CUSTOMIZE 73 select TUNER_MT20XX if !VIDEO_TUNER_CUSTOMIZE
73 select TUNER_TDA8290 if !VIDEO_TUNER_CUSTOMIZE 74 select TUNER_TDA8290 if !VIDEO_TUNER_CUSTOMIZE
74 select TUNER_TEA5761 if !VIDEO_TUNER_CUSTOMIZE 75 select TUNER_TEA5761 if !VIDEO_TUNER_CUSTOMIZE
75 select TUNER_TEA5767 if !VIDEO_TUNER_CUSTOMIZE 76 select TUNER_TEA5767 if !VIDEO_TUNER_CUSTOMIZE
76 select TUNER_SIMPLE if !VIDEO_TUNER_CUSTOMIZE 77 select TUNER_SIMPLE if !VIDEO_TUNER_CUSTOMIZE
78 select TUNER_TDA9887 if !VIDEO_TUNER_CUSTOMIZE
77 79
78menuconfig VIDEO_TUNER_CUSTOMIZE 80menuconfig VIDEO_TUNER_CUSTOMIZE
79 bool "Customize analog tuner modules to build" 81 bool "Customize analog tuner modules to build"
@@ -89,6 +91,13 @@ menuconfig VIDEO_TUNER_CUSTOMIZE
89 91
90if VIDEO_TUNER_CUSTOMIZE 92if VIDEO_TUNER_CUSTOMIZE
91 93
94config TUNER_XC2028
95 tristate "XCeive xc2028/xc3028 tuners"
96 depends on I2C
97 default m if VIDEO_TUNER_CUSTOMIZE
98 help
99 Say Y here to include support for the xc2028/xc3028 tuners.
100
92config TUNER_MT20XX 101config TUNER_MT20XX
93 tristate "Microtune 2032 / 2050 tuners" 102 tristate "Microtune 2032 / 2050 tuners"
94 depends on I2C 103 depends on I2C
@@ -97,8 +106,10 @@ config TUNER_MT20XX
97 Say Y here to include support for the MT2032 / MT2050 tuner. 106 Say Y here to include support for the MT2032 / MT2050 tuner.
98 107
99config TUNER_TDA8290 108config TUNER_TDA8290
100 tristate "TDA 8290+8275(a) tuner combo" 109 tristate "TDA 8290/8295 + 8275(a)/18271 tuner combo"
101 depends on I2C 110 depends on I2C
111 select DVB_TDA827X
112 select DVB_TDA18271
102 default m if VIDEO_TUNER_CUSTOMIZE 113 default m if VIDEO_TUNER_CUSTOMIZE
103 help 114 help
104 Say Y here to include support for Philips TDA8290+8275(a) tuner. 115 Say Y here to include support for Philips TDA8290+8275(a) tuner.
@@ -120,10 +131,19 @@ config TUNER_TEA5767
120config TUNER_SIMPLE 131config TUNER_SIMPLE
121 tristate "Simple tuner support" 132 tristate "Simple tuner support"
122 depends on I2C 133 depends on I2C
134 select TUNER_TDA9887
123 default m if VIDEO_TUNER_CUSTOMIZE 135 default m if VIDEO_TUNER_CUSTOMIZE
124 help 136 help
125 Say Y here to include support for various simple tuners. 137 Say Y here to include support for various simple tuners.
126 138
139config TUNER_TDA9887
140 tristate "TDA 9885/6/7 analog IF demodulator"
141 depends on I2C
142 default m if VIDEO_TUNER_CUSTOMIZE
143 help
144 Say Y here to include support for Philips TDA9885/6/7
145 analog IF demodulator.
146
127endif # VIDEO_TUNER_CUSTOMIZE 147endif # VIDEO_TUNER_CUSTOMIZE
128 148
129config VIDEOBUF_GEN 149config VIDEOBUF_GEN
diff --git a/drivers/media/common/Kconfig b/drivers/media/common/Kconfig
index c5092ef1082f..06ca75911b7f 100644
--- a/drivers/media/common/Kconfig
+++ b/drivers/media/common/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_SAA7146 1config VIDEO_SAA7146
2 tristate 2 tristate
3 depends on I2C 3 depends on I2C && PCI
4 4
5config VIDEO_SAA7146_VV 5config VIDEO_SAA7146_VV
6 tristate 6 tristate
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
index e7c3ab951a44..bb2a027b9483 100644
--- a/drivers/media/common/ir-functions.c
+++ b/drivers/media/common/ir-functions.c
@@ -258,7 +258,7 @@ int ir_decode_biphase(u32 *samples, int count, int low, int high)
258 * saa7134 */ 258 * saa7134 */
259 259
260/* decode raw bit pattern to RC5 code */ 260/* decode raw bit pattern to RC5 code */
261u32 ir_rc5_decode(unsigned int code) 261static u32 ir_rc5_decode(unsigned int code)
262{ 262{
263 unsigned int org_code = code; 263 unsigned int org_code = code;
264 unsigned int pair; 264 unsigned int pair;
@@ -371,7 +371,6 @@ EXPORT_SYMBOL_GPL(ir_dump_samples);
371EXPORT_SYMBOL_GPL(ir_decode_biphase); 371EXPORT_SYMBOL_GPL(ir_decode_biphase);
372EXPORT_SYMBOL_GPL(ir_decode_pulsedistance); 372EXPORT_SYMBOL_GPL(ir_decode_pulsedistance);
373 373
374EXPORT_SYMBOL_GPL(ir_rc5_decode);
375EXPORT_SYMBOL_GPL(ir_rc5_timer_end); 374EXPORT_SYMBOL_GPL(ir_rc5_timer_end);
376EXPORT_SYMBOL_GPL(ir_rc5_timer_keyup); 375EXPORT_SYMBOL_GPL(ir_rc5_timer_keyup);
377 376
diff --git a/drivers/media/common/ir-keymaps.c b/drivers/media/common/ir-keymaps.c
index 185e8a860c1a..a4a937c90534 100644
--- a/drivers/media/common/ir-keymaps.c
+++ b/drivers/media/common/ir-keymaps.c
@@ -1331,7 +1331,12 @@ IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
1331 [ 0x35 ] = KEY_FASTFORWARD, 1331 [ 0x35 ] = KEY_FASTFORWARD,
1332 [ 0x36 ] = KEY_TV, 1332 [ 0x36 ] = KEY_TV,
1333 [ 0x37 ] = KEY_RADIO, /* FM */ 1333 [ 0x37 ] = KEY_RADIO, /* FM */
1334 [ 0x38 ] = KEY_DVD 1334 [ 0x38 ] = KEY_DVD,
1335
1336 [ 0x3e ] = KEY_F21, /* MCE +VOL, on Y04G0033 */
1337 [ 0x3a ] = KEY_F22, /* MCE -VOL, on Y04G0033 */
1338 [ 0x3b ] = KEY_F23, /* MCE +CH, on Y04G0033 */
1339 [ 0x3f ] = KEY_F24 /* MCE -CH, on Y04G0033 */
1335}; 1340};
1336 1341
1337EXPORT_SYMBOL_GPL(ir_codes_winfast); 1342EXPORT_SYMBOL_GPL(ir_codes_winfast);
@@ -1843,3 +1848,142 @@ IR_KEYTAB_TYPE ir_codes_fusionhdtv_mce[IR_KEYTAB_SIZE] = {
1843}; 1848};
1844 1849
1845EXPORT_SYMBOL_GPL(ir_codes_fusionhdtv_mce); 1850EXPORT_SYMBOL_GPL(ir_codes_fusionhdtv_mce);
1851
1852/* Pinnacle PCTV HD 800i mini remote */
1853IR_KEYTAB_TYPE ir_codes_pinnacle_pctv_hd[IR_KEYTAB_SIZE] = {
1854
1855 [0x0f] = KEY_1,
1856 [0x15] = KEY_2,
1857 [0x10] = KEY_3,
1858 [0x18] = KEY_4,
1859 [0x1b] = KEY_5,
1860 [0x1e] = KEY_6,
1861 [0x11] = KEY_7,
1862 [0x21] = KEY_8,
1863 [0x12] = KEY_9,
1864 [0x27] = KEY_0,
1865
1866 [0x24] = KEY_ZOOM,
1867 [0x2a] = KEY_SUBTITLE,
1868
1869 [0x00] = KEY_MUTE,
1870 [0x01] = KEY_ENTER, /* Pinnacle Logo */
1871 [0x39] = KEY_POWER,
1872
1873 [0x03] = KEY_VOLUMEUP,
1874 [0x09] = KEY_VOLUMEDOWN,
1875 [0x06] = KEY_CHANNELUP,
1876 [0x0c] = KEY_CHANNELDOWN,
1877
1878 [0x2d] = KEY_REWIND,
1879 [0x30] = KEY_PLAYPAUSE,
1880 [0x33] = KEY_FASTFORWARD,
1881 [0x3c] = KEY_STOP,
1882 [0x36] = KEY_RECORD,
1883 [0x3f] = KEY_EPG, /* Labeled "?" */
1884};
1885EXPORT_SYMBOL_GPL(ir_codes_pinnacle_pctv_hd);
1886
1887/*
1888 * Igor Kuznetsov <igk72@ya.ru>
1889 * Andrey J. Melnikov <temnota@kmv.ru>
1890 *
1891 * Keytable is used by BeholdTV 60x series, M6 series at
1892 * least, and probably other cards too.
1893 * The "ascii-art picture" below (in comments, first row
1894 * is the keycode in hex, and subsequent row(s) shows
1895 * the button labels (several variants when appropriate)
1896 * helps to descide which keycodes to assign to the buttons.
1897 */
1898IR_KEYTAB_TYPE ir_codes_behold[IR_KEYTAB_SIZE] = {
1899
1900 /* 0x1c 0x12 *
1901 * TV/FM POWER *
1902 * */
1903 [ 0x1c ] = KEY_TUNER, /*XXX KEY_TV KEY_RADIO */
1904 [ 0x12 ] = KEY_POWER,
1905
1906 /* 0x01 0x02 0x03 *
1907 * 1 2 3 *
1908 * *
1909 * 0x04 0x05 0x06 *
1910 * 4 5 6 *
1911 * *
1912 * 0x07 0x08 0x09 *
1913 * 7 8 9 *
1914 * */
1915 [ 0x01 ] = KEY_1,
1916 [ 0x02 ] = KEY_2,
1917 [ 0x03 ] = KEY_3,
1918 [ 0x04 ] = KEY_4,
1919 [ 0x05 ] = KEY_5,
1920 [ 0x06 ] = KEY_6,
1921 [ 0x07 ] = KEY_7,
1922 [ 0x08 ] = KEY_8,
1923 [ 0x09 ] = KEY_9,
1924
1925 /* 0x0a 0x00 0x17 *
1926 * RECALL 0 MODE *
1927 * */
1928 [ 0x0a ] = KEY_AGAIN,
1929 [ 0x00 ] = KEY_0,
1930 [ 0x17 ] = KEY_MODE,
1931
1932 /* 0x14 0x10 *
1933 * ASPECT FULLSCREEN *
1934 * */
1935 [ 0x14 ] = KEY_SCREEN,
1936 [ 0x10 ] = KEY_ZOOM,
1937
1938 /* 0x0b *
1939 * Up *
1940 * *
1941 * 0x18 0x16 0x0c *
1942 * Left Ok Right *
1943 * *
1944 * 0x015 *
1945 * Down *
1946 * */
1947 [ 0x0b ] = KEY_CHANNELUP, /*XXX KEY_UP */
1948 [ 0x18 ] = KEY_VOLUMEDOWN, /*XXX KEY_LEFT */
1949 [ 0x16 ] = KEY_OK, /*XXX KEY_ENTER */
1950 [ 0x0c ] = KEY_VOLUMEUP, /*XXX KEY_RIGHT */
1951 [ 0x15 ] = KEY_CHANNELDOWN, /*XXX KEY_DOWN */
1952
1953 /* 0x11 0x0d *
1954 * MUTE INFO *
1955 * */
1956 [ 0x11 ] = KEY_MUTE,
1957 [ 0x0d ] = KEY_INFO,
1958
1959 /* 0x0f 0x1b 0x1a *
1960 * RECORD PLAY/PAUSE STOP *
1961 * *
1962 * 0x0e 0x1f 0x1e *
1963 *TELETEXT AUDIO SOURCE *
1964 * RED YELLOW *
1965 * */
1966 [ 0x0f ] = KEY_RECORD,
1967 [ 0x1b ] = KEY_PLAYPAUSE,
1968 [ 0x1a ] = KEY_STOP,
1969 [ 0x0e ] = KEY_TEXT,
1970 [ 0x1f ] = KEY_RED, /*XXX KEY_AUDIO */
1971 [ 0x1e ] = KEY_YELLOW, /*XXX KEY_SOURCE */
1972
1973 /* 0x1d 0x13 0x19 *
1974 * SLEEP PREVIEW DVB *
1975 * GREEN BLUE *
1976 * */
1977 [ 0x1d ] = KEY_SLEEP,
1978 [ 0x13 ] = KEY_GREEN,
1979 [ 0x19 ] = KEY_BLUE, /*XXX KEY_SAT */
1980
1981 /* 0x58 0x5c *
1982 * FREEZE SNAPSHOT *
1983 * */
1984 [ 0x58 ] = KEY_SLOW,
1985 [ 0x5c ] = KEY_SAVE,
1986
1987};
1988
1989EXPORT_SYMBOL_GPL(ir_codes_behold);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index 67d1b1b1b254..f0703d8bc3e8 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -61,7 +61,7 @@ void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q,
61 videobuf_waiton(&buf->vb,0,0); 61 videobuf_waiton(&buf->vb,0,0);
62 videobuf_dma_unmap(q, dma); 62 videobuf_dma_unmap(q, dma);
63 videobuf_dma_free(dma); 63 videobuf_dma_free(dma);
64 buf->vb.state = STATE_NEEDS_INIT; 64 buf->vb.state = VIDEOBUF_NEEDS_INIT;
65} 65}
66 66
67 67
@@ -83,7 +83,7 @@ int saa7146_buffer_queue(struct saa7146_dev *dev,
83 buf->activate(dev,buf,NULL); 83 buf->activate(dev,buf,NULL);
84 } else { 84 } else {
85 list_add_tail(&buf->vb.queue,&q->queue); 85 list_add_tail(&buf->vb.queue,&q->queue);
86 buf->vb.state = STATE_QUEUED; 86 buf->vb.state = VIDEOBUF_QUEUED;
87 DEB_D(("adding buffer %p to queue. (active buffer present)\n", buf)); 87 DEB_D(("adding buffer %p to queue. (active buffer present)\n", buf));
88 } 88 }
89 return 0; 89 return 0;
@@ -174,7 +174,7 @@ void saa7146_buffer_timeout(unsigned long data)
174 spin_lock_irqsave(&dev->slock,flags); 174 spin_lock_irqsave(&dev->slock,flags);
175 if (q->curr) { 175 if (q->curr) {
176 DEB_D(("timeout on %p\n", q->curr)); 176 DEB_D(("timeout on %p\n", q->curr));
177 saa7146_buffer_finish(dev,q,STATE_ERROR); 177 saa7146_buffer_finish(dev,q,VIDEOBUF_ERROR);
178 } 178 }
179 179
180 /* we don't restart the transfer here like other drivers do. when 180 /* we don't restart the transfer here like other drivers do. when
@@ -366,7 +366,7 @@ static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait)
366 } 366 }
367 367
368 poll_wait(file, &buf->done, wait); 368 poll_wait(file, &buf->done, wait);
369 if (buf->state == STATE_DONE || buf->state == STATE_ERROR) { 369 if (buf->state == VIDEOBUF_DONE || buf->state == VIDEOBUF_ERROR) {
370 DEB_D(("poll succeeded!\n")); 370 DEB_D(("poll succeeded!\n"));
371 return POLLIN|POLLRDNORM; 371 return POLLIN|POLLRDNORM;
372 } 372 }
@@ -538,6 +538,7 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
538 // fixme: -1 should be an insmod parameter *for the extension* (like "video_nr"); 538 // fixme: -1 should be an insmod parameter *for the extension* (like "video_nr");
539 if (video_register_device(vfd, type, -1) < 0) { 539 if (video_register_device(vfd, type, -1) < 0) {
540 ERR(("cannot register v4l2 device. skipping.\n")); 540 ERR(("cannot register v4l2 device. skipping.\n"));
541 video_device_release(vfd);
541 return -1; 542 return -1;
542 } 543 }
543 544
diff --git a/drivers/media/common/saa7146_vbi.c b/drivers/media/common/saa7146_vbi.c
index 6103484e4442..c32dda973e92 100644
--- a/drivers/media/common/saa7146_vbi.c
+++ b/drivers/media/common/saa7146_vbi.c
@@ -205,7 +205,7 @@ static int buffer_activate(struct saa7146_dev *dev,
205 struct saa7146_buf *next) 205 struct saa7146_buf *next)
206{ 206{
207 struct saa7146_vv *vv = dev->vv_data; 207 struct saa7146_vv *vv = dev->vv_data;
208 buf->vb.state = STATE_ACTIVE; 208 buf->vb.state = VIDEOBUF_ACTIVE;
209 209
210 DEB_VBI(("dev:%p, buf:%p, next:%p\n",dev,buf,next)); 210 DEB_VBI(("dev:%p, buf:%p, next:%p\n",dev,buf,next));
211 saa7146_set_vbi_capture(dev,buf,next); 211 saa7146_set_vbi_capture(dev,buf,next);
@@ -238,7 +238,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,e
238 if (buf->vb.size != size) 238 if (buf->vb.size != size)
239 saa7146_dma_free(dev,q,buf); 239 saa7146_dma_free(dev,q,buf);
240 240
241 if (STATE_NEEDS_INIT == buf->vb.state) { 241 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
242 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); 242 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
243 243
244 buf->vb.width = llength; 244 buf->vb.width = llength;
@@ -257,7 +257,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,e
257 if (0 != err) 257 if (0 != err)
258 return err; 258 return err;
259 } 259 }
260 buf->vb.state = STATE_PREPARED; 260 buf->vb.state = VIDEOBUF_PREPARED;
261 buf->activate = buffer_activate; 261 buf->activate = buffer_activate;
262 262
263 return 0; 263 return 0;
@@ -335,7 +335,7 @@ static void vbi_stop(struct saa7146_fh *fh, struct file *file)
335 saa7146_write(dev, MC1, MASK_20); 335 saa7146_write(dev, MC1, MASK_20);
336 336
337 if (vv->vbi_q.curr) { 337 if (vv->vbi_q.curr) {
338 saa7146_buffer_finish(dev,&vv->vbi_q,STATE_DONE); 338 saa7146_buffer_finish(dev,&vv->vbi_q,VIDEOBUF_DONE);
339 } 339 }
340 340
341 videobuf_queue_cancel(&fh->vbi_q); 341 videobuf_queue_cancel(&fh->vbi_q);
@@ -458,7 +458,7 @@ static void vbi_irq_done(struct saa7146_dev *dev, unsigned long status)
458 /* this must be += 2, one count for each field */ 458 /* this must be += 2, one count for each field */
459 vv->vbi_fieldcount+=2; 459 vv->vbi_fieldcount+=2;
460 vv->vbi_q.curr->vb.field_count = vv->vbi_fieldcount; 460 vv->vbi_q.curr->vb.field_count = vv->vbi_fieldcount;
461 saa7146_buffer_finish(dev,&vv->vbi_q,STATE_DONE); 461 saa7146_buffer_finish(dev,&vv->vbi_q,VIDEOBUF_DONE);
462 } else { 462 } else {
463 DEB_VBI(("dev:%p\n",dev)); 463 DEB_VBI(("dev:%p\n",dev));
464 } 464 }
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index ae36d101006b..c31ab480d8e1 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -1235,7 +1235,7 @@ static int buffer_activate (struct saa7146_dev *dev,
1235{ 1235{
1236 struct saa7146_vv *vv = dev->vv_data; 1236 struct saa7146_vv *vv = dev->vv_data;
1237 1237
1238 buf->vb.state = STATE_ACTIVE; 1238 buf->vb.state = VIDEOBUF_ACTIVE;
1239 saa7146_set_capture(dev,buf,next); 1239 saa7146_set_capture(dev,buf,next);
1240 1240
1241 mod_timer(&vv->video_q.timeout, jiffies+BUFFER_TIMEOUT); 1241 mod_timer(&vv->video_q.timeout, jiffies+BUFFER_TIMEOUT);
@@ -1281,7 +1281,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1281 saa7146_dma_free(dev,q,buf); 1281 saa7146_dma_free(dev,q,buf);
1282 } 1282 }
1283 1283
1284 if (STATE_NEEDS_INIT == buf->vb.state) { 1284 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
1285 struct saa7146_format *sfmt; 1285 struct saa7146_format *sfmt;
1286 1286
1287 buf->vb.bytesperline = fh->video_fmt.bytesperline; 1287 buf->vb.bytesperline = fh->video_fmt.bytesperline;
@@ -1314,7 +1314,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1314 if (err) 1314 if (err)
1315 goto oops; 1315 goto oops;
1316 } 1316 }
1317 buf->vb.state = STATE_PREPARED; 1317 buf->vb.state = VIDEOBUF_PREPARED;
1318 buf->activate = buffer_activate; 1318 buf->activate = buffer_activate;
1319 1319
1320 return 0; 1320 return 0;
@@ -1453,7 +1453,7 @@ static void video_irq_done(struct saa7146_dev *dev, unsigned long st)
1453 1453
1454 /* only finish the buffer if we have one... */ 1454 /* only finish the buffer if we have one... */
1455 if( NULL != q->curr ) { 1455 if( NULL != q->curr ) {
1456 saa7146_buffer_finish(dev,q,STATE_DONE); 1456 saa7146_buffer_finish(dev,q,VIDEOBUF_DONE);
1457 } 1457 }
1458 saa7146_buffer_next(dev,q,0); 1458 saa7146_buffer_next(dev,q,0);
1459 1459
diff --git a/drivers/media/dvb/b2c2/flexcop.c b/drivers/media/dvb/b2c2/flexcop.c
index 29ec4183118e..2ddafd071c97 100644
--- a/drivers/media/dvb/b2c2/flexcop.c
+++ b/drivers/media/dvb/b2c2/flexcop.c
@@ -212,7 +212,6 @@ void flexcop_reset_block_300(struct flexcop_device *fc)
212 212
213 fc->write_ibi_reg(fc,ctrl_208,v208_save); 213 fc->write_ibi_reg(fc,ctrl_208,v208_save);
214} 214}
215EXPORT_SYMBOL(flexcop_reset_block_300);
216 215
217struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len) 216struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len)
218{ 217{
diff --git a/drivers/media/dvb/bt8xx/bt878.c b/drivers/media/dvb/bt8xx/bt878.c
index 85e36a1d6d78..c7bbb40223f5 100644
--- a/drivers/media/dvb/bt8xx/bt878.c
+++ b/drivers/media/dvb/bt8xx/bt878.c
@@ -378,23 +378,37 @@ bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *
378 378
379EXPORT_SYMBOL(bt878_device_control); 379EXPORT_SYMBOL(bt878_device_control);
380 380
381#define BROOKTREE_878_DEVICE(vend, dev, name) \
382 { \
383 .vendor = PCI_VENDOR_ID_BROOKTREE, \
384 .device = PCI_DEVICE_ID_BROOKTREE_878, \
385 .subvendor = (vend), .subdevice = (dev), \
386 .driver_data = (unsigned long) name \
387 }
381 388
382static struct cards card_list[] __devinitdata = { 389static struct pci_device_id bt878_pci_tbl[] __devinitdata = {
383 390 BROOKTREE_878_DEVICE(0x0071, 0x0101, "Nebula Electronics DigiTV"),
384 { 0x01010071, BTTV_BOARD_NEBULA_DIGITV, "Nebula Electronics DigiTV" }, 391 BROOKTREE_878_DEVICE(0x1461, 0x0761, "AverMedia AverTV DVB-T 761"),
385 { 0x07611461, BTTV_BOARD_AVDVBT_761, "AverMedia AverTV DVB-T 761" }, 392 BROOKTREE_878_DEVICE(0x11bd, 0x001c, "Pinnacle PCTV Sat"),
386 { 0x001c11bd, BTTV_BOARD_PINNACLESAT, "Pinnacle PCTV Sat" }, 393 BROOKTREE_878_DEVICE(0x11bd, 0x0026, "Pinnacle PCTV SAT CI"),
387 { 0x002611bd, BTTV_BOARD_TWINHAN_DST, "Pinnacle PCTV SAT CI" }, 394 BROOKTREE_878_DEVICE(0x1822, 0x0001, "Twinhan VisionPlus DVB"),
388 { 0x00011822, BTTV_BOARD_TWINHAN_DST, "Twinhan VisionPlus DVB" }, 395 BROOKTREE_878_DEVICE(0x270f, 0xfc00,
389 { 0xfc00270f, BTTV_BOARD_TWINHAN_DST, "ChainTech digitop DST-1000 DVB-S" }, 396 "ChainTech digitop DST-1000 DVB-S"),
390 { 0x07711461, BTTV_BOARD_AVDVBT_771, "AVermedia AverTV DVB-T 771" }, 397 BROOKTREE_878_DEVICE(0x1461, 0x0771, "AVermedia AverTV DVB-T 771"),
391 { 0xdb1018ac, BTTV_BOARD_DVICO_DVBT_LITE, "DViCO FusionHDTV DVB-T Lite" }, 398 BROOKTREE_878_DEVICE(0x18ac, 0xdb10, "DViCO FusionHDTV DVB-T Lite"),
392 { 0xdb1118ac, BTTV_BOARD_DVICO_DVBT_LITE, "Ultraview DVB-T Lite" }, 399 BROOKTREE_878_DEVICE(0x18ac, 0xdb11, "Ultraview DVB-T Lite"),
393 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" }, 400 BROOKTREE_878_DEVICE(0x18ac, 0xd500, "DViCO FusionHDTV 5 Lite"),
394 { 0x20007063, BTTV_BOARD_PC_HDTV, "pcHDTV HD-2000 TV" }, 401 BROOKTREE_878_DEVICE(0x7063, 0x2000, "pcHDTV HD-2000 TV"),
395 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini" } 402 BROOKTREE_878_DEVICE(0x1822, 0x0026, "DNTV Live! Mini"),
403 { }
396}; 404};
397 405
406MODULE_DEVICE_TABLE(pci, bt878_pci_tbl);
407
408static const char * __devinit card_name(const struct pci_device_id *id)
409{
410 return id->driver_data ? (const char *)id->driver_data : "Unknown";
411}
398 412
399/***********************/ 413/***********************/
400/* PCI device handling */ 414/* PCI device handling */
@@ -403,15 +417,13 @@ static struct cards card_list[] __devinitdata = {
403static int __devinit bt878_probe(struct pci_dev *dev, 417static int __devinit bt878_probe(struct pci_dev *dev,
404 const struct pci_device_id *pci_id) 418 const struct pci_device_id *pci_id)
405{ 419{
406 int result = 0, has_dvb = 0, i; 420 int result = 0;
407 unsigned char lat; 421 unsigned char lat;
408 struct bt878 *bt; 422 struct bt878 *bt;
409#if defined(__powerpc__) 423#if defined(__powerpc__)
410 unsigned int cmd; 424 unsigned int cmd;
411#endif 425#endif
412 unsigned int cardid; 426 unsigned int cardid;
413 unsigned short id;
414 struct cards *dvb_cards;
415 427
416 printk(KERN_INFO "bt878: Bt878 AUDIO function found (%d).\n", 428 printk(KERN_INFO "bt878: Bt878 AUDIO function found (%d).\n",
417 bt878_num); 429 bt878_num);
@@ -423,25 +435,11 @@ static int __devinit bt878_probe(struct pci_dev *dev,
423 if (pci_enable_device(dev)) 435 if (pci_enable_device(dev))
424 return -EIO; 436 return -EIO;
425 437
426 pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &id); 438 cardid = dev->subsystem_device << 16;
427 cardid = id << 16; 439 cardid |= dev->subsystem_vendor;
428 pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &id);
429 cardid |= id;
430
431 for (i = 0, dvb_cards = card_list; i < ARRAY_SIZE(card_list); i++, dvb_cards++) {
432 if (cardid == dvb_cards->pci_id) {
433 printk("%s: card id=[0x%x],[ %s ] has DVB functions.\n",
434 __func__, cardid, dvb_cards->name);
435 has_dvb = 1;
436 }
437 }
438 440
439 if (!has_dvb) { 441 printk(KERN_INFO "%s: card id=[0x%x],[ %s ] has DVB functions.\n",
440 printk("%s: card id=[0x%x], Unknown card.\nExiting..\n", __func__, cardid); 442 __func__, cardid, card_name(pci_id));
441 result = -EINVAL;
442
443 goto fail0;
444 }
445 443
446 bt = &bt878[bt878_num]; 444 bt = &bt878[bt878_num];
447 bt->dev = dev; 445 bt->dev = dev;
@@ -572,14 +570,6 @@ static void __devexit bt878_remove(struct pci_dev *pci_dev)
572 return; 570 return;
573} 571}
574 572
575static struct pci_device_id bt878_pci_tbl[] __devinitdata = {
576 {PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BROOKTREE_878,
577 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
578 {0,}
579};
580
581MODULE_DEVICE_TABLE(pci, bt878_pci_tbl);
582
583static struct pci_driver bt878_pci_driver = { 573static struct pci_driver bt878_pci_driver = {
584 .name = "bt878", 574 .name = "bt878",
585 .id_table = bt878_pci_tbl, 575 .id_table = bt878_pci_tbl,
diff --git a/drivers/media/dvb/bt8xx/bt878.h b/drivers/media/dvb/bt8xx/bt878.h
index d593bc145628..375fd2892a11 100644
--- a/drivers/media/dvb/bt8xx/bt878.h
+++ b/drivers/media/dvb/bt8xx/bt878.h
@@ -101,12 +101,6 @@
101#define BTTV_BOARD_DVICO_DVBT_LITE 0x80 101#define BTTV_BOARD_DVICO_DVBT_LITE 0x80
102#define BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE 0x87 102#define BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE 0x87
103 103
104struct cards {
105 __u32 pci_id;
106 __u16 card_id;
107 char *name;
108};
109
110extern int bt878_num; 104extern int bt878_num;
111 105
112struct bt878 { 106struct bt878 {
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index b7a17e69ca4d..307ff35bdf13 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -71,6 +71,7 @@ MODULE_PARM_DESC(dst_algo, "tuning algo: default is 0=(SW), 1=(HW)");
71 } \ 71 } \
72} while(0) 72} while(0)
73 73
74static int dst_command(struct dst_state *state, u8 *data, u8 len);
74 75
75static void dst_packsize(struct dst_state *state, int psize) 76static void dst_packsize(struct dst_state *state, int psize)
76{ 77{
@@ -80,7 +81,8 @@ static void dst_packsize(struct dst_state *state, int psize)
80 bt878_device_control(state->bt, DST_IG_TS, &bits); 81 bt878_device_control(state->bt, DST_IG_TS, &bits);
81} 82}
82 83
83int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb, u32 outhigh, int delay) 84static int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb,
85 u32 outhigh, int delay)
84{ 86{
85 union dst_gpio_packet enb; 87 union dst_gpio_packet enb;
86 union dst_gpio_packet bits; 88 union dst_gpio_packet bits;
@@ -109,9 +111,8 @@ int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb, u32 outhigh, int
109 111
110 return 0; 112 return 0;
111} 113}
112EXPORT_SYMBOL(dst_gpio_outb);
113 114
114int dst_gpio_inb(struct dst_state *state, u8 *result) 115static int dst_gpio_inb(struct dst_state *state, u8 *result)
115{ 116{
116 union dst_gpio_packet rd_packet; 117 union dst_gpio_packet rd_packet;
117 int err; 118 int err;
@@ -125,7 +126,6 @@ int dst_gpio_inb(struct dst_state *state, u8 *result)
125 126
126 return 0; 127 return 0;
127} 128}
128EXPORT_SYMBOL(dst_gpio_inb);
129 129
130int rdc_reset_state(struct dst_state *state) 130int rdc_reset_state(struct dst_state *state)
131{ 131{
@@ -145,7 +145,7 @@ int rdc_reset_state(struct dst_state *state)
145} 145}
146EXPORT_SYMBOL(rdc_reset_state); 146EXPORT_SYMBOL(rdc_reset_state);
147 147
148int rdc_8820_reset(struct dst_state *state) 148static int rdc_8820_reset(struct dst_state *state)
149{ 149{
150 dprintk(verbose, DST_DEBUG, 1, "Resetting DST"); 150 dprintk(verbose, DST_DEBUG, 1, "Resetting DST");
151 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) { 151 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
@@ -160,9 +160,8 @@ int rdc_8820_reset(struct dst_state *state)
160 160
161 return 0; 161 return 0;
162} 162}
163EXPORT_SYMBOL(rdc_8820_reset);
164 163
165int dst_pio_enable(struct dst_state *state) 164static int dst_pio_enable(struct dst_state *state)
166{ 165{
167 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) { 166 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
168 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !"); 167 dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
@@ -172,7 +171,6 @@ int dst_pio_enable(struct dst_state *state)
172 171
173 return 0; 172 return 0;
174} 173}
175EXPORT_SYMBOL(dst_pio_enable);
176 174
177int dst_pio_disable(struct dst_state *state) 175int dst_pio_disable(struct dst_state *state)
178{ 176{
@@ -611,7 +609,7 @@ static int dst_type_print(struct dst_state *state, u8 type)
611 return 0; 609 return 0;
612} 610}
613 611
614struct tuner_types tuner_list[] = { 612static struct tuner_types tuner_list[] = {
615 { 613 {
616 .tuner_type = TUNER_TYPE_L64724, 614 .tuner_type = TUNER_TYPE_L64724,
617 .tuner_name = "L 64724", 615 .tuner_name = "L 64724",
@@ -1224,7 +1222,7 @@ static int dst_probe(struct dst_state *state)
1224 return 0; 1222 return 0;
1225} 1223}
1226 1224
1227int dst_command(struct dst_state *state, u8 *data, u8 len) 1225static int dst_command(struct dst_state *state, u8 *data, u8 len)
1228{ 1226{
1229 u8 reply; 1227 u8 reply;
1230 1228
@@ -1287,7 +1285,6 @@ error:
1287 return -EIO; 1285 return -EIO;
1288 1286
1289} 1287}
1290EXPORT_SYMBOL(dst_command);
1291 1288
1292static int dst_get_signal(struct dst_state *state) 1289static int dst_get_signal(struct dst_state *state)
1293{ 1290{
diff --git a/drivers/media/dvb/bt8xx/dst_common.h b/drivers/media/dvb/bt8xx/dst_common.h
index 87623d203a89..d88cf2add82b 100644
--- a/drivers/media/dvb/bt8xx/dst_common.h
+++ b/drivers/media/dvb/bt8xx/dst_common.h
@@ -165,10 +165,8 @@ struct dst_config
165}; 165};
166 166
167int rdc_reset_state(struct dst_state *state); 167int rdc_reset_state(struct dst_state *state);
168int rdc_8820_reset(struct dst_state *state);
169 168
170int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode); 169int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode);
171int dst_pio_enable(struct dst_state *state);
172int dst_pio_disable(struct dst_state *state); 170int dst_pio_disable(struct dst_state *state);
173int dst_error_recovery(struct dst_state* state); 171int dst_error_recovery(struct dst_state* state);
174int dst_error_bailout(struct dst_state *state); 172int dst_error_bailout(struct dst_state *state);
@@ -179,9 +177,6 @@ int read_dst(struct dst_state *state, u8 * ret, u8 len);
179u8 dst_check_sum(u8 * buf, u32 len); 177u8 dst_check_sum(u8 * buf, u32 len);
180struct dst_state* dst_attach(struct dst_state* state, struct dvb_adapter *dvb_adapter); 178struct dst_state* dst_attach(struct dst_state* state, struct dvb_adapter *dvb_adapter);
181struct dvb_device *dst_ca_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter); 179struct dvb_device *dst_ca_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter);
182int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay);
183
184int dst_command(struct dst_state* state, u8 * data, u8 len);
185 180
186 181
187#endif // DST_COMMON_H 182#endif // DST_COMMON_H
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 445f02665577..925cfa6221ad 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -1202,6 +1202,10 @@ void dvb_frontend_detach(struct dvb_frontend* fe)
1202 fe->ops.tuner_ops.release(fe); 1202 fe->ops.tuner_ops.release(fe);
1203 symbol_put_addr(fe->ops.tuner_ops.release); 1203 symbol_put_addr(fe->ops.tuner_ops.release);
1204 } 1204 }
1205 if (fe->ops.analog_ops.release) {
1206 fe->ops.analog_ops.release(fe);
1207 symbol_put_addr(fe->ops.analog_ops.release);
1208 }
1205 ptr = (void*)fe->ops.release; 1209 ptr = (void*)fe->ops.release;
1206 if (ptr) { 1210 if (ptr) {
1207 fe->ops.release(fe); 1211 fe->ops.release(fe);
@@ -1215,6 +1219,8 @@ void dvb_frontend_detach(struct dvb_frontend* fe)
1215 fe->ops.release_sec(fe); 1219 fe->ops.release_sec(fe);
1216 if (fe->ops.tuner_ops.release) 1220 if (fe->ops.tuner_ops.release)
1217 fe->ops.tuner_ops.release(fe); 1221 fe->ops.tuner_ops.release(fe);
1222 if (fe->ops.analog_ops.release)
1223 fe->ops.analog_ops.release(fe);
1218 if (fe->ops.release) 1224 if (fe->ops.release)
1219 fe->ops.release(fe); 1225 fe->ops.release(fe);
1220} 1226}
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.h b/drivers/media/dvb/dvb-core/dvb_frontend.h
index a5262e852c82..aa4133f0bd19 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.h
@@ -84,6 +84,9 @@ struct dvb_tuner_ops {
84 /** This is support for demods like the mt352 - fills out the supplied buffer with what to write. */ 84 /** This is support for demods like the mt352 - fills out the supplied buffer with what to write. */
85 int (*calc_regs)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p, u8 *buf, int buf_len); 85 int (*calc_regs)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p, u8 *buf, int buf_len);
86 86
87 /** This is to allow setting tuner-specific configs */
88 int (*set_config)(struct dvb_frontend *fe, void *priv_cfg);
89
87 int (*get_frequency)(struct dvb_frontend *fe, u32 *frequency); 90 int (*get_frequency)(struct dvb_frontend *fe, u32 *frequency);
88 int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth); 91 int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth);
89 92
@@ -98,6 +101,28 @@ struct dvb_tuner_ops {
98 int (*set_bandwidth)(struct dvb_frontend *fe, u32 bandwidth); 101 int (*set_bandwidth)(struct dvb_frontend *fe, u32 bandwidth);
99}; 102};
100 103
104struct analog_demod_info {
105 char *name;
106};
107
108struct analog_demod_ops {
109
110 struct analog_demod_info info;
111
112 void (*set_params)(struct dvb_frontend *fe,
113 struct analog_parameters *params);
114 int (*has_signal)(struct dvb_frontend *fe);
115 int (*is_stereo)(struct dvb_frontend *fe);
116 int (*get_afc)(struct dvb_frontend *fe);
117 void (*tuner_status)(struct dvb_frontend *fe);
118 void (*standby)(struct dvb_frontend *fe);
119 void (*release)(struct dvb_frontend *fe);
120 int (*i2c_gate_ctrl)(struct dvb_frontend *fe, int enable);
121
122 /** This is to allow setting tuner-specific configuration */
123 int (*set_config)(struct dvb_frontend *fe, void *priv_cfg);
124};
125
101struct dvb_frontend_ops { 126struct dvb_frontend_ops {
102 127
103 struct dvb_frontend_info info; 128 struct dvb_frontend_info info;
@@ -143,6 +168,7 @@ struct dvb_frontend_ops {
143 int (*ts_bus_ctrl)(struct dvb_frontend* fe, int acquire); 168 int (*ts_bus_ctrl)(struct dvb_frontend* fe, int acquire);
144 169
145 struct dvb_tuner_ops tuner_ops; 170 struct dvb_tuner_ops tuner_ops;
171 struct analog_demod_ops analog_ops;
146}; 172};
147 173
148#define MAX_EVENT 8 174#define MAX_EVENT 8
@@ -159,18 +185,19 @@ struct dvb_fe_events {
159struct dvb_frontend { 185struct dvb_frontend {
160 struct dvb_frontend_ops ops; 186 struct dvb_frontend_ops ops;
161 struct dvb_adapter *dvb; 187 struct dvb_adapter *dvb;
162 void* demodulator_priv; 188 void *demodulator_priv;
163 void* tuner_priv; 189 void *tuner_priv;
164 void* frontend_priv; 190 void *frontend_priv;
165 void* sec_priv; 191 void *sec_priv;
192 void *analog_demod_priv;
166}; 193};
167 194
168extern int dvb_register_frontend(struct dvb_adapter* dvb, 195extern int dvb_register_frontend(struct dvb_adapter *dvb,
169 struct dvb_frontend* fe); 196 struct dvb_frontend *fe);
170 197
171extern int dvb_unregister_frontend(struct dvb_frontend* fe); 198extern int dvb_unregister_frontend(struct dvb_frontend *fe);
172 199
173extern void dvb_frontend_detach(struct dvb_frontend* fe); 200extern void dvb_frontend_detach(struct dvb_frontend *fe);
174 201
175extern void dvb_frontend_reinitialise(struct dvb_frontend *fe); 202extern void dvb_frontend_reinitialise(struct dvb_frontend *fe);
176 203
diff --git a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
index 9878183ba3f0..ac9d93cf83c6 100644
--- a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
+++ b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
@@ -261,11 +261,6 @@ EXPORT_SYMBOL(dvb_ringbuffer_init);
261EXPORT_SYMBOL(dvb_ringbuffer_empty); 261EXPORT_SYMBOL(dvb_ringbuffer_empty);
262EXPORT_SYMBOL(dvb_ringbuffer_free); 262EXPORT_SYMBOL(dvb_ringbuffer_free);
263EXPORT_SYMBOL(dvb_ringbuffer_avail); 263EXPORT_SYMBOL(dvb_ringbuffer_avail);
264EXPORT_SYMBOL(dvb_ringbuffer_flush);
265EXPORT_SYMBOL(dvb_ringbuffer_flush_spinlock_wakeup); 264EXPORT_SYMBOL(dvb_ringbuffer_flush_spinlock_wakeup);
266EXPORT_SYMBOL(dvb_ringbuffer_read); 265EXPORT_SYMBOL(dvb_ringbuffer_read);
267EXPORT_SYMBOL(dvb_ringbuffer_write); 266EXPORT_SYMBOL(dvb_ringbuffer_write);
268EXPORT_SYMBOL(dvb_ringbuffer_pkt_write);
269EXPORT_SYMBOL(dvb_ringbuffer_pkt_read);
270EXPORT_SYMBOL(dvb_ringbuffer_pkt_dispose);
271EXPORT_SYMBOL(dvb_ringbuffer_pkt_next);
diff --git a/drivers/media/dvb/dvb-usb/af9005.c b/drivers/media/dvb/dvb-usb/af9005.c
index 7db6eee50e39..e7f76f515b4f 100644
--- a/drivers/media/dvb/dvb-usb/af9005.c
+++ b/drivers/media/dvb/dvb-usb/af9005.c
@@ -1026,6 +1026,7 @@ static int af9005_usb_probe(struct usb_interface *intf,
1026static struct usb_device_id af9005_usb_table[] = { 1026static struct usb_device_id af9005_usb_table[] = {
1027 {USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9005)}, 1027 {USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9005)},
1028 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE)}, 1028 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE)},
1029 {USB_DEVICE(USB_VID_ANSONIC, USB_PID_ANSONIC_DVBT_USB)},
1029 {0}, 1030 {0},
1030}; 1031};
1031 1032
@@ -1075,7 +1076,7 @@ static struct dvb_usb_device_properties af9005_properties = {
1075 .rc_key_map_size = 0, 1076 .rc_key_map_size = 0,
1076 .rc_query = af9005_rc_query, 1077 .rc_query = af9005_rc_query,
1077 1078
1078 .num_device_descs = 2, 1079 .num_device_descs = 3,
1079 .devices = { 1080 .devices = {
1080 {.name = "Afatech DVB-T USB1.1 stick", 1081 {.name = "Afatech DVB-T USB1.1 stick",
1081 .cold_ids = {&af9005_usb_table[0], NULL}, 1082 .cold_ids = {&af9005_usb_table[0], NULL},
@@ -1085,6 +1086,10 @@ static struct dvb_usb_device_properties af9005_properties = {
1085 .cold_ids = {&af9005_usb_table[1], NULL}, 1086 .cold_ids = {&af9005_usb_table[1], NULL},
1086 .warm_ids = {NULL}, 1087 .warm_ids = {NULL},
1087 }, 1088 },
1089 {.name = "Ansonic DVB-T USB1.1 stick",
1090 .cold_ids = {&af9005_usb_table[2], NULL},
1091 .warm_ids = {NULL},
1092 },
1088 {NULL}, 1093 {NULL},
1089 } 1094 }
1090}; 1095};
diff --git a/drivers/media/dvb/dvb-usb/au6610.c b/drivers/media/dvb/dvb-usb/au6610.c
index 18e0b16fb2a9..f3ff81314696 100644
--- a/drivers/media/dvb/dvb-usb/au6610.c
+++ b/drivers/media/dvb/dvb-usb/au6610.c
@@ -79,12 +79,12 @@ static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
79 struct dvb_usb_device *d = i2c_get_adapdata(adap); 79 struct dvb_usb_device *d = i2c_get_adapdata(adap);
80 int i; 80 int i;
81 81
82 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
83 return -EAGAIN;
84
85 if (num > 2) 82 if (num > 2)
86 return -EINVAL; 83 return -EINVAL;
87 84
85 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
86 return -EAGAIN;
87
88 for (i = 0; i < num; i++) { 88 for (i = 0; i < num; i++) {
89 /* write/read request */ 89 /* write/read request */
90 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { 90 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 04e31cf7d530..c58365005ac1 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -15,7 +15,7 @@
15 * 15 *
16 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de) 16 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
17 * Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org) 17 * Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org)
18 * Copyright (C) 2006 Chris Pascoe (c.pascoe@itee.uq.edu.au) 18 * Copyright (C) 2006, 2007 Chris Pascoe (c.pascoe@itee.uq.edu.au)
19 * 19 *
20 * This program is free software; you can redistribute it and/or modify it 20 * This program is free software; you can redistribute it and/or modify it
21 * under the terms of the GNU General Public License as published by the Free 21 * under the terms of the GNU General Public License as published by the Free
@@ -30,11 +30,16 @@
30#include "mt352.h" 30#include "mt352.h"
31#include "mt352_priv.h" 31#include "mt352_priv.h"
32#include "zl10353.h" 32#include "zl10353.h"
33#include "tuner-xc2028.h"
34#include "tuner-xc2028-types.h"
33 35
34/* debug */ 36/* debug */
35int dvb_usb_cxusb_debug; 37static int dvb_usb_cxusb_debug;
36module_param_named(debug, dvb_usb_cxusb_debug, int, 0644); 38module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
37MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 39MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
40#define deb_info(args...) dprintk(dvb_usb_cxusb_debug,0x01,args)
41#define deb_i2c(args...) if (d->udev->descriptor.idVendor == USB_VID_MEDION) \
42 dprintk(dvb_usb_cxusb_debug,0x01,args)
38 43
39static int cxusb_ctrl_msg(struct dvb_usb_device *d, 44static int cxusb_ctrl_msg(struct dvb_usb_device *d,
40 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen) 45 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
@@ -46,11 +51,9 @@ static int cxusb_ctrl_msg(struct dvb_usb_device *d,
46 sndbuf[0] = cmd; 51 sndbuf[0] = cmd;
47 memcpy(&sndbuf[1], wbuf, wlen); 52 memcpy(&sndbuf[1], wbuf, wlen);
48 if (wo) 53 if (wo)
49 dvb_usb_generic_write(d, sndbuf, 1+wlen); 54 return dvb_usb_generic_write(d, sndbuf, 1+wlen);
50 else 55 else
51 dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0); 56 return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
52
53 return 0;
54} 57}
55 58
56/* GPIO */ 59/* GPIO */
@@ -72,6 +75,34 @@ static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
72 st->gpio_write_state[GPIO_TUNER] = onoff; 75 st->gpio_write_state[GPIO_TUNER] = onoff;
73} 76}
74 77
78static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,
79 u8 newval)
80{
81 u8 o[2], gpio_state;
82 int rc;
83
84 o[0] = 0xff & ~changemask; /* mask of bits to keep */
85 o[1] = newval & changemask; /* new values for bits */
86
87 rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);
88 if (rc < 0 || (gpio_state & changemask) != (newval & changemask))
89 deb_info("bluebird_gpio_write failed.\n");
90
91 return rc < 0 ? rc : gpio_state;
92}
93
94static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low)
95{
96 cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);
97 msleep(5);
98 cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);
99}
100
101static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
102{
103 cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
104}
105
75/* I2C */ 106/* I2C */
76static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], 107static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
77 int num) 108 int num)
@@ -82,9 +113,6 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
82 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 113 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
83 return -EAGAIN; 114 return -EAGAIN;
84 115
85 if (num > 2)
86 warn("more than two i2c messages at a time is not handled yet. TODO.");
87
88 for (i = 0; i < num; i++) { 116 for (i = 0; i < num; i++) {
89 117
90 if (d->udev->descriptor.idVendor == USB_VID_MEDION) 118 if (d->udev->descriptor.idVendor == USB_VID_MEDION)
@@ -97,8 +125,22 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
97 break; 125 break;
98 } 126 }
99 127
100 /* read request */ 128 if (msg[i].flags & I2C_M_RD) {
101 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { 129 /* read only */
130 u8 obuf[3], ibuf[1+msg[i].len];
131 obuf[0] = 0;
132 obuf[1] = msg[i].len;
133 obuf[2] = msg[i].addr;
134 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
135 obuf, 3,
136 ibuf, 1+msg[i].len) < 0) {
137 warn("i2c read failed");
138 break;
139 }
140 memcpy(msg[i].buf, &ibuf[1], msg[i].len);
141 } else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&
142 msg[i].addr == msg[i+1].addr) {
143 /* write to then read from same address */
102 u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len]; 144 u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len];
103 obuf[0] = msg[i].len; 145 obuf[0] = msg[i].len;
104 obuf[1] = msg[i+1].len; 146 obuf[1] = msg[i+1].len;
@@ -116,7 +158,8 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
116 memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len); 158 memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
117 159
118 i++; 160 i++;
119 } else { /* write */ 161 } else {
162 /* write only */
120 u8 obuf[2+msg[i].len], ibuf; 163 u8 obuf[2+msg[i].len], ibuf;
121 obuf[0] = msg[i].addr; 164 obuf[0] = msg[i].addr;
122 obuf[1] = msg[i].len; 165 obuf[1] = msg[i].len;
@@ -131,7 +174,7 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
131 } 174 }
132 175
133 mutex_unlock(&d->i2c_mutex); 176 mutex_unlock(&d->i2c_mutex);
134 return i; 177 return i == num ? num : -EREMOTEIO;
135} 178}
136 179
137static u32 cxusb_i2c_func(struct i2c_adapter *adapter) 180static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
@@ -162,6 +205,17 @@ static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
162 return 0; 205 return 0;
163} 206}
164 207
208static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
209{
210 int rc = 0;
211
212 rc = cxusb_power_ctrl(d, onoff);
213 if (!onoff)
214 cxusb_nano2_led(d, 0);
215
216 return rc;
217}
218
165static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 219static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
166{ 220{
167 u8 buf[2] = { 0x03, 0x00 }; 221 u8 buf[2] = { 0x03, 0x00 };
@@ -197,6 +251,34 @@ static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
197 return 0; 251 return 0;
198} 252}
199 253
254static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
255 int *state)
256{
257 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
258 u8 ircode[4];
259 int i;
260 struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
261 .buf = ircode, .len = 4 };
262
263 *event = 0;
264 *state = REMOTE_NO_KEY_PRESSED;
265
266 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
267 return 0;
268
269 for (i = 0; i < d->props.rc_key_map_size; i++) {
270 if (keymap[i].custom == ircode[1] &&
271 keymap[i].data == ircode[2]) {
272 *event = keymap[i].event;
273 *state = REMOTE_KEY_PRESSED;
274
275 return 0;
276 }
277 }
278
279 return 0;
280}
281
200static struct dvb_usb_rc_key dvico_mce_rc_keys[] = { 282static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
201 { 0xfe, 0x02, KEY_TV }, 283 { 0xfe, 0x02, KEY_TV },
202 { 0xfe, 0x0e, KEY_MP3 }, 284 { 0xfe, 0x0e, KEY_MP3 },
@@ -351,6 +433,20 @@ static struct mt352_config cxusb_mt352_config = {
351 .demod_init = cxusb_mt352_demod_init, 433 .demod_init = cxusb_mt352_demod_init,
352}; 434};
353 435
436static struct zl10353_config cxusb_zl10353_xc3028_config = {
437 .demod_address = 0x0f,
438 .if2 = 45600,
439 .no_tuner = 1,
440 .parallel_ts = 1,
441};
442
443static struct mt352_config cxusb_mt352_xc3028_config = {
444 .demod_address = 0x0f,
445 .if2 = 4560,
446 .no_tuner = 1,
447 .demod_init = cxusb_mt352_demod_init,
448};
449
354/* Callbacks for DVB USB */ 450/* Callbacks for DVB USB */
355static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap) 451static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
356{ 452{
@@ -386,6 +482,51 @@ static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
386 return 0; 482 return 0;
387} 483}
388 484
485static int dvico_bluebird_xc2028_callback(void *ptr, int command, int arg)
486{
487 struct dvb_usb_device *d = ptr;
488
489 switch (command) {
490 case XC2028_TUNER_RESET:
491 deb_info("%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg);
492 cxusb_bluebird_gpio_pulse(d, 0x01, 1);
493 break;
494 case XC2028_RESET_CLK:
495 deb_info("%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg);
496 break;
497 default:
498 deb_info("%s: unknown command %d, arg %d\n", __FUNCTION__,
499 command, arg);
500 return -EINVAL;
501 }
502
503 return 0;
504}
505
506static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
507{
508 struct dvb_frontend *fe;
509 struct xc2028_config cfg = {
510 .i2c_adap = &adap->dev->i2c_adap,
511 .i2c_addr = 0x61,
512 .video_dev = adap->dev,
513 .callback = dvico_bluebird_xc2028_callback,
514 };
515 static struct xc2028_ctrl ctl = {
516 .fname = "xc3028-dvico-au-01.fw",
517 .max_len = 64,
518 .scode_table = ZARLINK456,
519 };
520
521 fe = dvb_attach(xc2028_attach, adap->fe, &cfg);
522 if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)
523 return -EIO;
524
525 fe->ops.tuner_ops.set_config(fe, &ctl);
526
527 return 0;
528}
529
389static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap) 530static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
390{ 531{
391 u8 b; 532 u8 b;
@@ -447,27 +588,120 @@ static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
447 return -EIO; 588 return -EIO;
448} 589}
449 590
591static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
592{
593 u8 ircode[4];
594 int i;
595 struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
596 .buf = ircode, .len = 4 };
597
598 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
599 err("set interface failed");
600
601 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
602
603 /* reset the tuner and demodulator */
604 cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
605 cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
606 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
607
608 if ((adap->fe = dvb_attach(zl10353_attach,
609 &cxusb_zl10353_xc3028_config,
610 &adap->dev->i2c_adap)) == NULL)
611 return -EIO;
612
613 /* try to determine if there is no IR decoder on the I2C bus */
614 for (i = 0; adap->dev->props.rc_key_map != NULL && i < 5; i++) {
615 msleep(20);
616 if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
617 goto no_IR;
618 if (ircode[0] == 0 && ircode[1] == 0)
619 continue;
620 if (ircode[2] + ircode[3] != 0xff) {
621no_IR:
622 adap->dev->props.rc_key_map = NULL;
623 info("No IR receiver detected on this device.");
624 break;
625 }
626 }
627
628 return 0;
629}
630
631static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
632{
633 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
634 err("set interface failed");
635
636 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
637
638 /* reset the tuner and demodulator */
639 cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
640 cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
641 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
642
643 if ((adap->fe = dvb_attach(zl10353_attach,
644 &cxusb_zl10353_xc3028_config,
645 &adap->dev->i2c_adap)) != NULL)
646 return 0;
647
648 if ((adap->fe = dvb_attach(mt352_attach,
649 &cxusb_mt352_xc3028_config,
650 &adap->dev->i2c_adap)) != NULL)
651 return 0;
652
653 return -EIO;
654}
655
656/*
657 * DViCO has shipped two devices with the same USB ID, but only one of them
658 * needs a firmware download. Check the device class details to see if they
659 * have non-default values to decide whether the device is actually cold or
660 * not, and forget a match if it turns out we selected the wrong device.
661 */
662static int bluebird_fx2_identify_state(struct usb_device *udev,
663 struct dvb_usb_device_properties *props,
664 struct dvb_usb_device_description **desc,
665 int *cold)
666{
667 int wascold = *cold;
668
669 *cold = udev->descriptor.bDeviceClass == 0xff &&
670 udev->descriptor.bDeviceSubClass == 0xff &&
671 udev->descriptor.bDeviceProtocol == 0xff;
672
673 if (*cold && !wascold)
674 *desc = NULL;
675
676 return 0;
677}
678
450/* 679/*
451 * DViCO bluebird firmware needs the "warm" product ID to be patched into the 680 * DViCO bluebird firmware needs the "warm" product ID to be patched into the
452 * firmware file before download. 681 * firmware file before download.
453 */ 682 */
454 683
455#define BLUEBIRD_01_ID_OFFSET 6638 684static const int dvico_firmware_id_offsets[] = { 6638, 3204 };
456static int bluebird_patch_dvico_firmware_download(struct usb_device *udev, 685static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
457 const struct firmware *fw) 686 const struct firmware *fw)
458{ 687{
459 if (fw->size < BLUEBIRD_01_ID_OFFSET + 4) 688 int pos;
460 return -EINVAL; 689
690 for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {
691 int idoff = dvico_firmware_id_offsets[pos];
461 692
462 if (fw->data[BLUEBIRD_01_ID_OFFSET] == (USB_VID_DVICO & 0xff) && 693 if (fw->size < idoff + 4)
463 fw->data[BLUEBIRD_01_ID_OFFSET + 1] == USB_VID_DVICO >> 8) { 694 continue;
464 695
465 fw->data[BLUEBIRD_01_ID_OFFSET + 2] = 696 if (fw->data[idoff] == (USB_VID_DVICO & 0xff) &&
466 le16_to_cpu(udev->descriptor.idProduct) + 1; 697 fw->data[idoff + 1] == USB_VID_DVICO >> 8) {
467 fw->data[BLUEBIRD_01_ID_OFFSET + 3] = 698 fw->data[idoff + 2] =
468 le16_to_cpu(udev->descriptor.idProduct) >> 8; 699 le16_to_cpu(udev->descriptor.idProduct) + 1;
700 fw->data[idoff + 3] =
701 le16_to_cpu(udev->descriptor.idProduct) >> 8;
469 702
470 return usb_cypress_load_firmware(udev, fw, CYPRESS_FX2); 703 return usb_cypress_load_firmware(udev, fw, CYPRESS_FX2);
704 }
471 } 705 }
472 706
473 return -EINVAL; 707 return -EINVAL;
@@ -479,6 +713,9 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
479static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties; 713static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
480static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties; 714static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
481static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties; 715static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
716static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
717static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
718static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
482 719
483static int cxusb_probe(struct usb_interface *intf, 720static int cxusb_probe(struct usb_interface *intf,
484 const struct usb_device_id *id) 721 const struct usb_device_id *id)
@@ -487,7 +724,10 @@ static int cxusb_probe(struct usb_interface *intf,
487 dvb_usb_device_init(intf,&cxusb_bluebird_lgh064f_properties,THIS_MODULE,NULL) == 0 || 724 dvb_usb_device_init(intf,&cxusb_bluebird_lgh064f_properties,THIS_MODULE,NULL) == 0 ||
488 dvb_usb_device_init(intf,&cxusb_bluebird_dee1601_properties,THIS_MODULE,NULL) == 0 || 725 dvb_usb_device_init(intf,&cxusb_bluebird_dee1601_properties,THIS_MODULE,NULL) == 0 ||
489 dvb_usb_device_init(intf,&cxusb_bluebird_lgz201_properties,THIS_MODULE,NULL) == 0 || 726 dvb_usb_device_init(intf,&cxusb_bluebird_lgz201_properties,THIS_MODULE,NULL) == 0 ||
490 dvb_usb_device_init(intf,&cxusb_bluebird_dtt7579_properties,THIS_MODULE,NULL) == 0) { 727 dvb_usb_device_init(intf,&cxusb_bluebird_dtt7579_properties,THIS_MODULE,NULL) == 0 ||
728 dvb_usb_device_init(intf,&cxusb_bluebird_dualdig4_properties,THIS_MODULE,NULL) == 0 ||
729 dvb_usb_device_init(intf,&cxusb_bluebird_nano2_properties,THIS_MODULE,NULL) == 0 ||
730 dvb_usb_device_init(intf,&cxusb_bluebird_nano2_needsfirmware_properties,THIS_MODULE,NULL) == 0) {
491 return 0; 731 return 0;
492 } 732 }
493 733
@@ -508,6 +748,9 @@ static struct usb_device_id cxusb_table [] = {
508 { USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM) }, 748 { USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM) },
509 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD) }, 749 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD) },
510 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM) }, 750 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM) },
751 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4) },
752 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2) },
753 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) },
511 {} /* Terminating entry */ 754 {} /* Terminating entry */
512}; 755};
513MODULE_DEVICE_TABLE (usb, cxusb_table); 756MODULE_DEVICE_TABLE (usb, cxusb_table);
@@ -766,6 +1009,151 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
766 } 1009 }
767}; 1010};
768 1011
1012static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
1013 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1014
1015 .usb_ctrl = CYPRESS_FX2,
1016
1017 .size_of_priv = sizeof(struct cxusb_state),
1018
1019 .num_adapters = 1,
1020 .adapter = {
1021 {
1022 .streaming_ctrl = cxusb_streaming_ctrl,
1023 .frontend_attach = cxusb_dualdig4_frontend_attach,
1024 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
1025 /* parameter for the MPEG2-data transfer */
1026 .stream = {
1027 .type = USB_BULK,
1028 .count = 5,
1029 .endpoint = 0x02,
1030 .u = {
1031 .bulk = {
1032 .buffersize = 8192,
1033 }
1034 }
1035 },
1036 },
1037 },
1038
1039 .power_ctrl = cxusb_power_ctrl,
1040
1041 .i2c_algo = &cxusb_i2c_algo,
1042
1043 .generic_bulk_ctrl_endpoint = 0x01,
1044
1045 .rc_interval = 100,
1046 .rc_key_map = dvico_mce_rc_keys,
1047 .rc_key_map_size = ARRAY_SIZE(dvico_mce_rc_keys),
1048 .rc_query = cxusb_bluebird2_rc_query,
1049
1050 .num_device_descs = 1,
1051 .devices = {
1052 { "DViCO FusionHDTV DVB-T Dual Digital 4",
1053 { NULL },
1054 { &cxusb_table[13], NULL },
1055 },
1056 }
1057};
1058
1059static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
1060 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1061
1062 .usb_ctrl = CYPRESS_FX2,
1063 .identify_state = bluebird_fx2_identify_state,
1064
1065 .size_of_priv = sizeof(struct cxusb_state),
1066
1067 .num_adapters = 1,
1068 .adapter = {
1069 {
1070 .streaming_ctrl = cxusb_streaming_ctrl,
1071 .frontend_attach = cxusb_nano2_frontend_attach,
1072 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
1073 /* parameter for the MPEG2-data transfer */
1074 .stream = {
1075 .type = USB_BULK,
1076 .count = 5,
1077 .endpoint = 0x02,
1078 .u = {
1079 .bulk = {
1080 .buffersize = 8192,
1081 }
1082 }
1083 },
1084 },
1085 },
1086
1087 .power_ctrl = cxusb_nano2_power_ctrl,
1088
1089 .i2c_algo = &cxusb_i2c_algo,
1090
1091 .generic_bulk_ctrl_endpoint = 0x01,
1092
1093 .rc_interval = 100,
1094 .rc_key_map = dvico_portable_rc_keys,
1095 .rc_key_map_size = ARRAY_SIZE(dvico_portable_rc_keys),
1096 .rc_query = cxusb_bluebird2_rc_query,
1097
1098 .num_device_descs = 1,
1099 .devices = {
1100 { "DViCO FusionHDTV DVB-T NANO2",
1101 { NULL },
1102 { &cxusb_table[14], NULL },
1103 },
1104 }
1105};
1106
1107static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties = {
1108 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1109
1110 .usb_ctrl = DEVICE_SPECIFIC,
1111 .firmware = "dvb-usb-bluebird-02.fw",
1112 .download_firmware = bluebird_patch_dvico_firmware_download,
1113 .identify_state = bluebird_fx2_identify_state,
1114
1115 .size_of_priv = sizeof(struct cxusb_state),
1116
1117 .num_adapters = 1,
1118 .adapter = {
1119 {
1120 .streaming_ctrl = cxusb_streaming_ctrl,
1121 .frontend_attach = cxusb_nano2_frontend_attach,
1122 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
1123 /* parameter for the MPEG2-data transfer */
1124 .stream = {
1125 .type = USB_BULK,
1126 .count = 5,
1127 .endpoint = 0x02,
1128 .u = {
1129 .bulk = {
1130 .buffersize = 8192,
1131 }
1132 }
1133 },
1134 },
1135 },
1136
1137 .power_ctrl = cxusb_nano2_power_ctrl,
1138
1139 .i2c_algo = &cxusb_i2c_algo,
1140
1141 .generic_bulk_ctrl_endpoint = 0x01,
1142
1143 .rc_interval = 100,
1144 .rc_key_map = dvico_portable_rc_keys,
1145 .rc_key_map_size = ARRAY_SIZE(dvico_portable_rc_keys),
1146 .rc_query = cxusb_rc_query,
1147
1148 .num_device_descs = 1,
1149 .devices = {
1150 { "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
1151 { &cxusb_table[14], NULL },
1152 { &cxusb_table[15], NULL },
1153 },
1154 }
1155};
1156
769static struct usb_driver cxusb_driver = { 1157static struct usb_driver cxusb_driver = {
770 .name = "dvb_usb_cxusb", 1158 .name = "dvb_usb_cxusb",
771 .probe = cxusb_probe, 1159 .probe = cxusb_probe,
diff --git a/drivers/media/dvb/dvb-usb/cxusb.h b/drivers/media/dvb/dvb-usb/cxusb.h
index c8ef77554b00..4768a2c35517 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.h
+++ b/drivers/media/dvb/dvb-usb/cxusb.h
@@ -4,12 +4,9 @@
4#define DVB_USB_LOG_PREFIX "cxusb" 4#define DVB_USB_LOG_PREFIX "cxusb"
5#include "dvb-usb.h" 5#include "dvb-usb.h"
6 6
7extern int dvb_usb_cxusb_debug;
8#define deb_info(args...) dprintk(dvb_usb_cxusb_debug,0x01,args)
9#define deb_i2c(args...) if (d->udev->descriptor.idVendor == USB_VID_MEDION) \
10 dprintk(dvb_usb_cxusb_debug,0x01,args)
11
12/* usb commands - some of it are guesses, don't have a reference yet */ 7/* usb commands - some of it are guesses, don't have a reference yet */
8#define CMD_BLUEBIRD_GPIO_RW 0x05
9
13#define CMD_I2C_WRITE 0x08 10#define CMD_I2C_WRITE 0x08
14#define CMD_I2C_READ 0x09 11#define CMD_I2C_READ 0x09
15 12
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index 3ea294eb96bd..c9857d5c6982 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -243,7 +243,7 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
243 u8 b[4]; 243 u8 b[4];
244 244
245 b[0] = REQUEST_ENABLE_VIDEO; 245 b[0] = REQUEST_ENABLE_VIDEO;
246 b[1] = 0x00; 246 b[1] = (onoff << 4) | 0x00; /* this bit gives a kind of command, rather than enabling something or not */
247 b[2] = (0x01 << 4); /* Master mode */ 247 b[2] = (0x01 << 4); /* Master mode */
248 b[3] = 0x00; 248 b[3] = 0x00;
249 249
@@ -256,9 +256,6 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
256 256
257 b[2] |= st->channel_state; 257 b[2] |= st->channel_state;
258 258
259 if (st->channel_state) /* if at least one channel is active */
260 b[1] = (0x01 << 4) | 0x00;
261
262 deb_info("data for streaming: %x %x\n",b[1],b[2]); 259 deb_info("data for streaming: %x %x\n",b[1],b[2]);
263 260
264 return dib0700_ctrl_wr(adap->dev, b, 4); 261 return dib0700_ctrl_wr(adap->dev, b, 4);
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index 58452b52002c..e7093826e975 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -94,12 +94,28 @@ static int bristol_frontend_attach(struct dvb_usb_adapter *adap)
94 (10 + adap->id) << 1, &bristol_dib3000mc_config[adap->id])) == NULL ? -ENODEV : 0; 94 (10 + adap->id) << 1, &bristol_dib3000mc_config[adap->id])) == NULL ? -ENODEV : 0;
95} 95}
96 96
97static int eeprom_read(struct i2c_adapter *adap,u8 adrs,u8 *pval)
98{
99 struct i2c_msg msg[2] = {
100 { .addr = 0x50, .flags = 0, .buf = &adrs, .len = 1 },
101 { .addr = 0x50, .flags = I2C_M_RD, .buf = pval, .len = 1 },
102 };
103 if (i2c_transfer(adap, msg, 2) != 2) return -EREMOTEIO;
104 return 0;
105}
106
97static int bristol_tuner_attach(struct dvb_usb_adapter *adap) 107static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
98{ 108{
99 struct dib0700_state *st = adap->dev->priv; 109 struct i2c_adapter *prim_i2c = &adap->dev->i2c_adap;
100 struct i2c_adapter *tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe, 1); 110 struct i2c_adapter *tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe, 1);
101 return dvb_attach(mt2060_attach,adap->fe, tun_i2c, &bristol_mt2060_config[adap->id], 111 s8 a;
102 st->mt2060_if1[adap->id]) == NULL ? -ENODEV : 0; 112 int if1=1220;
113 if (adap->dev->udev->descriptor.idVendor == USB_VID_HAUPPAUGE &&
114 adap->dev->udev->descriptor.idProduct == USB_PID_HAUPPAUGE_NOVA_T_500_2) {
115 if (!eeprom_read(prim_i2c,0x59 + adap->id,&a)) if1=1220+a;
116 }
117 return dvb_attach(mt2060_attach,adap->fe, tun_i2c,&bristol_mt2060_config[adap->id],
118 if1) == NULL ? -ENODEV : 0;
103} 119}
104 120
105/* STK7700D: Pinnacle/Terratec/Hauppauge Dual DVB-T Diversity */ 121/* STK7700D: Pinnacle/Terratec/Hauppauge Dual DVB-T Diversity */
@@ -230,6 +246,27 @@ static struct mt2266_config stk7700d_mt2266_config[2] = {
230 } 246 }
231}; 247};
232 248
249static int stk7700P2_frontend_attach(struct dvb_usb_adapter *adap)
250{
251 if (adap->id == 0) {
252 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
253 msleep(10);
254 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
255 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
256 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
257 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
258 msleep(10);
259 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
260 msleep(10);
261 dib7000p_i2c_enumeration(&adap->dev->i2c_adap,1,18,stk7700d_dib7000p_mt2266_config);
262 }
263
264 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1),
265 &stk7700d_dib7000p_mt2266_config[adap->id]);
266
267 return adap->fe == NULL ? -ENODEV : 0;
268}
269
233static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap) 270static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
234{ 271{
235 if (adap->id == 0) { 272 if (adap->id == 0) {
@@ -415,6 +452,35 @@ static struct dvb_usb_rc_key dib0700_rc_keys[] = {
415 { 0x1e, 0x38, KEY_YELLOW }, 452 { 0x1e, 0x38, KEY_YELLOW },
416 { 0x1e, 0x3b, KEY_GOTO }, 453 { 0x1e, 0x3b, KEY_GOTO },
417 { 0x1e, 0x3d, KEY_POWER }, 454 { 0x1e, 0x3d, KEY_POWER },
455
456 /* Key codes for the Leadtek Winfast DTV Dongle */
457 { 0x00, 0x42, KEY_POWER },
458 { 0x07, 0x7c, KEY_TUNER },
459 { 0x0f, 0x4e, KEY_PRINT }, /* PREVIEW */
460 { 0x08, 0x40, KEY_SCREEN }, /* full screen toggle*/
461 { 0x0f, 0x71, KEY_DOT }, /* frequency */
462 { 0x07, 0x43, KEY_0 },
463 { 0x0c, 0x41, KEY_1 },
464 { 0x04, 0x43, KEY_2 },
465 { 0x0b, 0x7f, KEY_3 },
466 { 0x0e, 0x41, KEY_4 },
467 { 0x06, 0x43, KEY_5 },
468 { 0x09, 0x7f, KEY_6 },
469 { 0x0d, 0x7e, KEY_7 },
470 { 0x05, 0x7c, KEY_8 },
471 { 0x0a, 0x40, KEY_9 },
472 { 0x0e, 0x4e, KEY_CLEAR },
473 { 0x04, 0x7c, KEY_CHANNEL }, /* show channel number */
474 { 0x0f, 0x41, KEY_LAST }, /* recall */
475 { 0x03, 0x42, KEY_MUTE },
476 { 0x06, 0x4c, KEY_RESERVED }, /* PIP button*/
477 { 0x01, 0x72, KEY_SHUFFLE }, /* SNAPSHOT */
478 { 0x0c, 0x4e, KEY_PLAYPAUSE }, /* TIMESHIFT */
479 { 0x0b, 0x70, KEY_RECORD },
480 { 0x03, 0x7d, KEY_VOLUMEUP },
481 { 0x01, 0x7d, KEY_VOLUMEDOWN },
482 { 0x02, 0x42, KEY_CHANNELUP },
483 { 0x00, 0x7d, KEY_CHANNELDOWN },
418}; 484};
419 485
420/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */ 486/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
@@ -578,16 +644,22 @@ static struct mt2060_config stk7700p_mt2060_config = {
578 644
579static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap) 645static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
580{ 646{
647 struct i2c_adapter *prim_i2c = &adap->dev->i2c_adap;
581 struct dib0700_state *st = adap->dev->priv; 648 struct dib0700_state *st = adap->dev->priv;
582 struct i2c_adapter *tun_i2c; 649 struct i2c_adapter *tun_i2c;
583 650 s8 a;
651 int if1=1220;
652 if (adap->dev->udev->descriptor.idVendor == USB_VID_HAUPPAUGE &&
653 adap->dev->udev->descriptor.idProduct == USB_PID_HAUPPAUGE_NOVA_T_STICK) {
654 if (!eeprom_read(prim_i2c,0x58,&a)) if1=1220+a;
655 }
584 if (st->is_dib7000pc) 656 if (st->is_dib7000pc)
585 tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1); 657 tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
586 else 658 else
587 tun_i2c = dib7000m_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1); 659 tun_i2c = dib7000m_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
588 660
589 return dvb_attach(mt2060_attach, adap->fe, tun_i2c, &stk7700p_mt2060_config, 661 return dvb_attach(mt2060_attach, adap->fe, tun_i2c, &stk7700p_mt2060_config,
590 st->mt2060_if1[0]) == NULL ? -ENODEV : 0; 662 if1) == NULL ? -ENODEV : 0;
591} 663}
592 664
593/* DIB7070 generic */ 665/* DIB7070 generic */
@@ -709,6 +781,8 @@ static struct dib7000p_config dib7070p_dib7000p_config = {
709 .agc_config_count = 1, 781 .agc_config_count = 1,
710 .agc = &dib7070_agc_config, 782 .agc = &dib7070_agc_config,
711 .bw = &dib7070_bw_config_12_mhz, 783 .bw = &dib7070_bw_config_12_mhz,
784 .tuner_is_baseband = 1,
785 .spur_protect = 1,
712 786
713 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS, 787 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
714 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES, 788 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
@@ -748,6 +822,8 @@ static struct dib7000p_config stk7070pd_dib7000p_config[2] = {
748 .agc_config_count = 1, 822 .agc_config_count = 1,
749 .agc = &dib7070_agc_config, 823 .agc = &dib7070_agc_config,
750 .bw = &dib7070_bw_config_12_mhz, 824 .bw = &dib7070_bw_config_12_mhz,
825 .tuner_is_baseband = 1,
826 .spur_protect = 1,
751 827
752 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS, 828 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
753 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES, 829 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
@@ -760,6 +836,8 @@ static struct dib7000p_config stk7070pd_dib7000p_config[2] = {
760 .agc_config_count = 1, 836 .agc_config_count = 1,
761 .agc = &dib7070_agc_config, 837 .agc = &dib7070_agc_config,
762 .bw = &dib7070_bw_config_12_mhz, 838 .bw = &dib7070_bw_config_12_mhz,
839 .tuner_is_baseband = 1,
840 .spur_protect = 1,
763 841
764 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS, 842 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
765 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES, 843 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
@@ -821,6 +899,12 @@ struct usb_device_id dib0700_usb_id_table[] = {
821 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T) }, 899 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T) },
822 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500_PC) }, 900 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500_PC) },
823/* 20 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_EXPRESS) }, 901/* 20 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_EXPRESS) },
902 { USB_DEVICE(USB_VID_GIGABYTE, USB_PID_GIGABYTE_U7000) },
903 { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ARTEC_T14BR) },
904 { USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3000) },
905 { USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100) },
906/* 25 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_3) },
907 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_MYTV_T) },
824 { 0 } /* Terminating entry */ 908 { 0 } /* Terminating entry */
825}; 909};
826MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table); 910MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
@@ -862,7 +946,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
862 }, 946 },
863 }, 947 },
864 948
865 .num_device_descs = 7, 949 .num_device_descs = 8,
866 .devices = { 950 .devices = {
867 { "DiBcom STK7700P reference design", 951 { "DiBcom STK7700P reference design",
868 { &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] }, 952 { &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] },
@@ -891,6 +975,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
891 { "AVerMedia AVerTV DVB-T Express", 975 { "AVerMedia AVerTV DVB-T Express",
892 { &dib0700_usb_id_table[20] }, 976 { &dib0700_usb_id_table[20] },
893 { NULL }, 977 { NULL },
978 },
979 { "Gigabyte U7000",
980 { &dib0700_usb_id_table[21], NULL },
981 { NULL },
894 } 982 }
895 }, 983 },
896 984
@@ -961,7 +1049,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
961 { "DiBcom STK7700D reference design", 1049 { "DiBcom STK7700D reference design",
962 { &dib0700_usb_id_table[14], NULL }, 1050 { &dib0700_usb_id_table[14], NULL },
963 { NULL }, 1051 { NULL },
964 }, 1052 }
965 }, 1053 },
966 1054
967 .rc_interval = DEFAULT_RC_INTERVAL, 1055 .rc_interval = DEFAULT_RC_INTERVAL,
@@ -974,6 +1062,25 @@ struct dvb_usb_device_properties dib0700_devices[] = {
974 .num_adapters = 1, 1062 .num_adapters = 1,
975 .adapter = { 1063 .adapter = {
976 { 1064 {
1065 .frontend_attach = stk7700P2_frontend_attach,
1066 .tuner_attach = stk7700d_tuner_attach,
1067
1068 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
1069 },
1070 },
1071
1072 .num_device_descs = 1,
1073 .devices = {
1074 { "ASUS My Cinema U3000 Mini DVBT Tuner",
1075 { &dib0700_usb_id_table[23], NULL },
1076 { NULL },
1077 },
1078 }
1079 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1080
1081 .num_adapters = 1,
1082 .adapter = {
1083 {
977 .frontend_attach = stk7070p_frontend_attach, 1084 .frontend_attach = stk7070p_frontend_attach,
978 .tuner_attach = dib7070p_tuner_attach, 1085 .tuner_attach = dib7070p_tuner_attach,
979 1086
@@ -983,7 +1090,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
983 }, 1090 },
984 }, 1091 },
985 1092
986 .num_device_descs = 2, 1093 .num_device_descs = 6,
987 .devices = { 1094 .devices = {
988 { "DiBcom STK7070P reference design", 1095 { "DiBcom STK7070P reference design",
989 { &dib0700_usb_id_table[15], NULL }, 1096 { &dib0700_usb_id_table[15], NULL },
@@ -993,7 +1100,29 @@ struct dvb_usb_device_properties dib0700_devices[] = {
993 { &dib0700_usb_id_table[16], NULL }, 1100 { &dib0700_usb_id_table[16], NULL },
994 { NULL }, 1101 { NULL },
995 }, 1102 },
996 } 1103 { "Artec T14BR DVB-T",
1104 { &dib0700_usb_id_table[22], NULL },
1105 { NULL },
1106 },
1107 { "ASUS My Cinema U3100 Mini DVBT Tuner",
1108 { &dib0700_usb_id_table[24], NULL },
1109 { NULL },
1110 },
1111 { "Hauppauge Nova-T Stick",
1112 { &dib0700_usb_id_table[25], NULL },
1113 { NULL },
1114 },
1115 { "Hauppauge Nova-T MyTV.t",
1116 { &dib0700_usb_id_table[26], NULL },
1117 { NULL },
1118 },
1119 },
1120
1121 .rc_interval = DEFAULT_RC_INTERVAL,
1122 .rc_key_map = dib0700_rc_keys,
1123 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys),
1124 .rc_query = dib0700_rc_query
1125
997 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 1126 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
998 1127
999 .num_adapters = 2, 1128 .num_adapters = 2,
@@ -1024,7 +1153,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1024 { "Pinnacle PCTV Dual DVB-T Diversity Stick", 1153 { "Pinnacle PCTV Dual DVB-T Diversity Stick",
1025 { &dib0700_usb_id_table[18], NULL }, 1154 { &dib0700_usb_id_table[18], NULL },
1026 { NULL }, 1155 { NULL },
1027 }, 1156 }
1028 } 1157 }
1029 }, 1158 },
1030}; 1159};
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index bca1e0905739..3acbda4aa27e 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -17,9 +17,10 @@
17#include "nxt6000.h" 17#include "nxt6000.h"
18 18
19/* debug */ 19/* debug */
20int dvb_usb_digitv_debug; 20static int dvb_usb_digitv_debug;
21module_param_named(debug,dvb_usb_digitv_debug, int, 0644); 21module_param_named(debug,dvb_usb_digitv_debug, int, 0644);
22MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 22MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
23#define deb_rc(args...) dprintk(dvb_usb_digitv_debug,0x01,args)
23 24
24static int digitv_ctrl_msg(struct dvb_usb_device *d, 25static int digitv_ctrl_msg(struct dvb_usb_device *d,
25 u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen) 26 u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
diff --git a/drivers/media/dvb/dvb-usb/digitv.h b/drivers/media/dvb/dvb-usb/digitv.h
index 8b43e3db8691..908c09f4966b 100644
--- a/drivers/media/dvb/dvb-usb/digitv.h
+++ b/drivers/media/dvb/dvb-usb/digitv.h
@@ -8,9 +8,6 @@ struct digitv_state {
8 int is_nxt6000; 8 int is_nxt6000;
9}; 9};
10 10
11extern int dvb_usb_digitv_debug;
12#define deb_rc(args...) dprintk(dvb_usb_digitv_debug,0x01,args)
13
14/* protocol (from usblogging and the SDK: 11/* protocol (from usblogging and the SDK:
15 * 12 *
16 * Always 7 bytes bulk message(s) for controlling 13 * Always 7 bytes bulk message(s) for controlling
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 4fa3e895028a..aa4844ef875e 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -15,7 +15,9 @@
15#define USB_VID_ALCOR_MICRO 0x058f 15#define USB_VID_ALCOR_MICRO 0x058f
16#define USB_VID_ALINK 0x05e3 16#define USB_VID_ALINK 0x05e3
17#define USB_VID_ANCHOR 0x0547 17#define USB_VID_ANCHOR 0x0547
18#define USB_VID_ANSONIC 0x10b9
18#define USB_VID_ANUBIS_ELECTRONIC 0x10fd 19#define USB_VID_ANUBIS_ELECTRONIC 0x10fd
20#define USB_VID_ASUS 0x0b05
19#define USB_VID_AVERMEDIA 0x07ca 21#define USB_VID_AVERMEDIA 0x07ca
20#define USB_VID_COMPRO 0x185b 22#define USB_VID_COMPRO 0x185b
21#define USB_VID_COMPRO_UNK 0x145f 23#define USB_VID_COMPRO_UNK 0x145f
@@ -44,12 +46,16 @@
44#define USB_VID_ULTIMA_ELECTRONIC 0x05d8 46#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
45#define USB_VID_UNIWILL 0x1584 47#define USB_VID_UNIWILL 0x1584
46#define USB_VID_WIDEVIEW 0x14aa 48#define USB_VID_WIDEVIEW 0x14aa
49/* dom : pour gigabyte u7000 */
50#define USB_VID_GIGABYTE 0x1044
51
47 52
48/* Product IDs */ 53/* Product IDs */
49#define USB_PID_ADSTECH_USB2_COLD 0xa333 54#define USB_PID_ADSTECH_USB2_COLD 0xa333
50#define USB_PID_ADSTECH_USB2_WARM 0xa334 55#define USB_PID_ADSTECH_USB2_WARM 0xa334
51#define USB_PID_AFATECH_AF9005 0x9020 56#define USB_PID_AFATECH_AF9005 0x9020
52#define USB_VID_ALINK_DTU 0xf170 57#define USB_VID_ALINK_DTU 0xf170
58#define USB_PID_ANSONIC_DVBT_USB 0x6000
53#define USB_PID_AVERMEDIA_DVBT_USB_COLD 0x0001 59#define USB_PID_AVERMEDIA_DVBT_USB_COLD 0x0001
54#define USB_PID_AVERMEDIA_DVBT_USB_WARM 0x0002 60#define USB_PID_AVERMEDIA_DVBT_USB_WARM 0x0002
55#define USB_PID_AVERMEDIA_DVBT_USB2_COLD 0xa800 61#define USB_PID_AVERMEDIA_DVBT_USB2_COLD 0xa800
@@ -69,6 +75,7 @@
69#define USB_PID_DIBCOM_STK7700P 0x1e14 75#define USB_PID_DIBCOM_STK7700P 0x1e14
70#define USB_PID_DIBCOM_STK7700P_PC 0x1e78 76#define USB_PID_DIBCOM_STK7700P_PC 0x1e78
71#define USB_PID_DIBCOM_STK7700D 0x1ef0 77#define USB_PID_DIBCOM_STK7700D 0x1ef0
78#define USB_PID_DIBCOM_STK7700_U7000 0x7001
72#define USB_PID_DIBCOM_STK7070P 0x1ebc 79#define USB_PID_DIBCOM_STK7070P 0x1ebc
73#define USB_PID_DIBCOM_STK7070PD 0x1ebe 80#define USB_PID_DIBCOM_STK7070PD 0x1ebe
74#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131 81#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131
@@ -99,6 +106,7 @@
99#define USB_PID_ULTIMA_TVBOX_USB2_WARM 0x810a 106#define USB_PID_ULTIMA_TVBOX_USB2_WARM 0x810a
100#define USB_PID_ARTEC_T14_COLD 0x810b 107#define USB_PID_ARTEC_T14_COLD 0x810b
101#define USB_PID_ARTEC_T14_WARM 0x810c 108#define USB_PID_ARTEC_T14_WARM 0x810c
109#define USB_PID_ARTEC_T14BR 0x810f
102#define USB_PID_ULTIMA_TVBOX_USB2_FX_COLD 0x8613 110#define USB_PID_ULTIMA_TVBOX_USB2_FX_COLD 0x8613
103#define USB_PID_ULTIMA_TVBOX_USB2_FX_WARM 0x1002 111#define USB_PID_ULTIMA_TVBOX_USB2_FX_WARM 0x1002
104#define USB_PID_UNK_HYPER_PALTEK_COLD 0x005e 112#define USB_PID_UNK_HYPER_PALTEK_COLD 0x005e
@@ -120,6 +128,8 @@
120#define USB_PID_HAUPPAUGE_NOVA_T_500_2 0x9950 128#define USB_PID_HAUPPAUGE_NOVA_T_500_2 0x9950
121#define USB_PID_HAUPPAUGE_NOVA_T_STICK 0x7050 129#define USB_PID_HAUPPAUGE_NOVA_T_STICK 0x7050
122#define USB_PID_HAUPPAUGE_NOVA_T_STICK_2 0x7060 130#define USB_PID_HAUPPAUGE_NOVA_T_STICK_2 0x7060
131#define USB_PID_HAUPPAUGE_NOVA_T_STICK_3 0x7070
132#define USB_PID_HAUPPAUGE_MYTV_T 0x7080
123#define USB_PID_HAUPPAUGE_NOVA_TD_STICK 0x9580 133#define USB_PID_HAUPPAUGE_NOVA_TD_STICK 0x9580
124#define USB_PID_AVERMEDIA_EXPRESS 0xb568 134#define USB_PID_AVERMEDIA_EXPRESS 0xb568
125#define USB_PID_AVERMEDIA_VOLAR 0xa807 135#define USB_PID_AVERMEDIA_VOLAR 0xa807
@@ -143,6 +153,9 @@
143#define USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM 0xdb51 153#define USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM 0xdb51
144#define USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD 0xdb58 154#define USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD 0xdb58
145#define USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM 0xdb59 155#define USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM 0xdb59
156#define USB_PID_DVICO_BLUEBIRD_DUAL_4 0xdb78
157#define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2 0xdb70
158#define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM 0xdb71
146#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD 0xdb54 159#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD 0xdb54
147#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM 0xdb55 160#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM 0xdb55
148#define USB_PID_MEDION_MD95700 0x0932 161#define USB_PID_MEDION_MD95700 0x0932
@@ -170,6 +183,9 @@
170#define USB_PID_OPERA1_WARM 0x3829 183#define USB_PID_OPERA1_WARM 0x3829
171#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD 0x0514 184#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD 0x0514
172#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM 0x0513 185#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM 0x0513
173 186/* dom pour gigabyte u7000 */
187#define USB_PID_GIGABYTE_U7000 0x7001
188#define USB_PID_ASUS_U3000 0x171f
189#define USB_PID_ASUS_U3100 0x173f
174 190
175#endif 191#endif
diff --git a/drivers/media/dvb/dvb-usb/gl861.c b/drivers/media/dvb/dvb-usb/gl861.c
index f01d99c1c43c..6b99d9f4d5b3 100644
--- a/drivers/media/dvb/dvb-usb/gl861.c
+++ b/drivers/media/dvb/dvb-usb/gl861.c
@@ -56,12 +56,12 @@ static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
56 struct dvb_usb_device *d = i2c_get_adapdata(adap); 56 struct dvb_usb_device *d = i2c_get_adapdata(adap);
57 int i; 57 int i;
58 58
59 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
60 return -EAGAIN;
61
62 if (num > 2) 59 if (num > 2)
63 return -EINVAL; 60 return -EINVAL;
64 61
62 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
63 return -EAGAIN;
64
65 for (i = 0; i < num; i++) { 65 for (i = 0; i < num; i++) {
66 /* write/read request */ 66 /* write/read request */
67 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { 67 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.c b/drivers/media/dvb/dvb-usb/gp8psk.c
index 92147ee3e14f..83e8535014c6 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk.c
@@ -171,22 +171,6 @@ static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
171 return 0; 171 return 0;
172} 172}
173 173
174int gp8psk_bcm4500_reload(struct dvb_usb_device *d)
175{
176 u8 buf;
177 int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
178 /* Turn off 8psk power */
179 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
180 return -EINVAL;
181 /* Turn On 8psk power */
182 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
183 return -EINVAL;
184 /* load BCM4500 firmware */
185 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
186 if (gp8psk_load_bcm4500fw(d))
187 return EINVAL;
188 return 0;
189}
190 174
191static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 175static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
192{ 176{
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.h b/drivers/media/dvb/dvb-usb/gp8psk.h
index e83a57506cfa..e5cd8149c23d 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.h
+++ b/drivers/media/dvb/dvb-usb/gp8psk.h
@@ -92,6 +92,5 @@ extern struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d);
92extern int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen); 92extern int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
93extern int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, 93extern int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
94 u16 index, u8 *b, int blen); 94 u16 index, u8 *b, int blen);
95extern int gp8psk_bcm4500_reload(struct dvb_usb_device *d);
96 95
97#endif 96#endif
diff --git a/drivers/media/dvb/dvb-usb/opera1.c b/drivers/media/dvb/dvb-usb/opera1.c
index d7c04951ceab..21935bf7059e 100644
--- a/drivers/media/dvb/dvb-usb/opera1.c
+++ b/drivers/media/dvb/dvb-usb/opera1.c
@@ -10,7 +10,9 @@
10* see Documentation/dvb/README.dvb-usb for more information 10* see Documentation/dvb/README.dvb-usb for more information
11*/ 11*/
12 12
13#include "opera1.h" 13#define DVB_USB_LOG_PREFIX "opera"
14
15#include "dvb-usb.h"
14#include "stv0299.h" 16#include "stv0299.h"
15 17
16#define OPERA_READ_MSG 0 18#define OPERA_READ_MSG 0
@@ -38,7 +40,7 @@ struct opera_rc_keys {
38 u32 event; 40 u32 event;
39}; 41};
40 42
41int dvb_usb_opera1_debug; 43static int dvb_usb_opera1_debug;
42module_param_named(debug, dvb_usb_opera1_debug, int, 0644); 44module_param_named(debug, dvb_usb_opera1_debug, int, 0644);
43MODULE_PARM_DESC(debug, 45MODULE_PARM_DESC(debug,
44 "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64 (or-able))." 46 "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64 (or-able))."
diff --git a/drivers/media/dvb/dvb-usb/opera1.h b/drivers/media/dvb/dvb-usb/opera1.h
deleted file mode 100644
index 53174427902d..000000000000
--- a/drivers/media/dvb/dvb-usb/opera1.h
+++ /dev/null
@@ -1,9 +0,0 @@
1#ifndef _OPERA1_H_
2#define _OPERA1_H_
3
4#define DVB_USB_LOG_PREFIX "opera"
5#include "dvb-usb.h"
6
7extern int dvb_usb_opera1_debug;
8#define deb_xfer(args...) dprintk(dvb_usb_opera1_debug,0x02,args)
9#endif
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c
index 16533b31a82d..e553c139ac44 100644
--- a/drivers/media/dvb/dvb-usb/vp702x.c
+++ b/drivers/media/dvb/dvb-usb/vp702x.c
@@ -56,7 +56,7 @@ int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8
56 return ret; 56 return ret;
57} 57}
58 58
59int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, 59static int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
60 u16 index, u8 *b, int blen) 60 u16 index, u8 *b, int blen)
61{ 61{
62 int ret; 62 int ret;
@@ -204,19 +204,6 @@ static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
204 return 0; 204 return 0;
205} 205}
206 206
207int vp702x_power_ctrl(struct dvb_usb_device *d, int onoff)
208{
209 struct vp702x_device_state *st = d->priv;
210
211 if (st->power_state == 0 && onoff)
212 vp702x_usb_out_op(d, SET_TUNER_POWER_REQ, 1, 7, NULL, 0);
213 else if (st->power_state == 1 && onoff == 0)
214 vp702x_usb_out_op(d, SET_TUNER_POWER_REQ, 0, 7, NULL, 0);
215
216 st->power_state = onoff;
217
218 return 0;
219}
220 207
221static int vp702x_read_mac_addr(struct dvb_usb_device *d,u8 mac[6]) 208static int vp702x_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
222{ 209{
diff --git a/drivers/media/dvb/dvb-usb/vp702x.h b/drivers/media/dvb/dvb-usb/vp702x.h
index 25a9dee4c824..c2f97f96c21f 100644
--- a/drivers/media/dvb/dvb-usb/vp702x.h
+++ b/drivers/media/dvb/dvb-usb/vp702x.h
@@ -102,7 +102,5 @@ extern struct dvb_frontend * vp702x_fe_attach(struct dvb_usb_device *d);
102 102
103extern int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec); 103extern int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec);
104extern int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen); 104extern int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
105extern int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
106extern int vp702x_power_ctrl(struct dvb_usb_device *d, int onoff);
107 105
108#endif 106#endif
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index 5bbd2d5192f0..c172babf59bb 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -15,9 +15,12 @@
15#include "vp7045.h" 15#include "vp7045.h"
16 16
17/* debug */ 17/* debug */
18int dvb_usb_vp7045_debug; 18static int dvb_usb_vp7045_debug;
19module_param_named(debug,dvb_usb_vp7045_debug, int, 0644); 19module_param_named(debug,dvb_usb_vp7045_debug, int, 0644);
20MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS); 20MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
21#define deb_info(args...) dprintk(dvb_usb_vp7045_debug,0x01,args)
22#define deb_xfer(args...) dprintk(dvb_usb_vp7045_debug,0x02,args)
23#define deb_rc(args...) dprintk(dvb_usb_vp7045_debug,0x04,args)
21 24
22int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen, int msec) 25int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen, int msec)
23{ 26{
diff --git a/drivers/media/dvb/dvb-usb/vp7045.h b/drivers/media/dvb/dvb-usb/vp7045.h
index 9ce21a20fa86..969688f85267 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.h
+++ b/drivers/media/dvb/dvb-usb/vp7045.h
@@ -17,11 +17,6 @@
17#define DVB_USB_LOG_PREFIX "vp7045" 17#define DVB_USB_LOG_PREFIX "vp7045"
18#include "dvb-usb.h" 18#include "dvb-usb.h"
19 19
20extern int dvb_usb_vp7045_debug;
21#define deb_info(args...) dprintk(dvb_usb_vp7045_debug,0x01,args)
22#define deb_xfer(args...) dprintk(dvb_usb_vp7045_debug,0x02,args)
23#define deb_rc(args...) dprintk(dvb_usb_vp7045_debug,0x04,args)
24
25/* vp7045 commands */ 20/* vp7045 commands */
26 21
27/* Twinhan Vendor requests */ 22/* Twinhan Vendor requests */
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 59b9ed1f1aec..9ad86ce4a4e5 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -316,6 +316,13 @@ config DVB_TDA827X
316 help 316 help
317 A DVB-T silicon tuner module. Say Y when you want to support this tuner. 317 A DVB-T silicon tuner module. Say Y when you want to support this tuner.
318 318
319config DVB_TDA18271
320 tristate "NXP TDA18271 silicon tuner"
321 depends on I2C
322 default m if DVB_FE_CUSTOMISE
323 help
324 A silicon tuner module. Say Y when you want to support this tuner.
325
319config DVB_TUNER_QT1010 326config DVB_TUNER_QT1010
320 tristate "Quantek QT1010 silicon tuner" 327 tristate "Quantek QT1010 silicon tuner"
321 depends on DVB_CORE && I2C 328 depends on DVB_CORE && I2C
@@ -353,6 +360,15 @@ config DVB_TUNER_DIB0070
353 This device is only used inside a SiP called togther with a 360 This device is only used inside a SiP called togther with a
354 demodulator for now. 361 demodulator for now.
355 362
363config DVB_TUNER_XC5000
364 tristate "Xceive XC5000 silicon tuner"
365 depends on I2C
366 default m if DVB_FE_CUSTOMISE
367 help
368 A driver for the silicon tuner XC5000 from Xceive.
369 This device is only used inside a SiP called togther with a
370 demodulator for now.
371
356comment "Miscellaneous devices" 372comment "Miscellaneous devices"
357 depends on DVB_CORE 373 depends on DVB_CORE
358 374
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 4b8ad1f132aa..16bd107ebd32 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -3,6 +3,9 @@
3# 3#
4 4
5EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ 5EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
6EXTRA_CFLAGS += -Idrivers/media/video/
7
8tda18271-objs := tda18271-tables.o tda18271-common.o tda18271-fe.o
6 9
7obj-$(CONFIG_DVB_PLL) += dvb-pll.o 10obj-$(CONFIG_DVB_PLL) += dvb-pll.o
8obj-$(CONFIG_DVB_STV0299) += stv0299.o 11obj-$(CONFIG_DVB_STV0299) += stv0299.o
@@ -39,6 +42,7 @@ obj-$(CONFIG_DVB_ISL6421) += isl6421.o
39obj-$(CONFIG_DVB_TDA10086) += tda10086.o 42obj-$(CONFIG_DVB_TDA10086) += tda10086.o
40obj-$(CONFIG_DVB_TDA826X) += tda826x.o 43obj-$(CONFIG_DVB_TDA826X) += tda826x.o
41obj-$(CONFIG_DVB_TDA827X) += tda827x.o 44obj-$(CONFIG_DVB_TDA827X) += tda827x.o
45obj-$(CONFIG_DVB_TDA18271) += tda18271.o
42obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o 46obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o
43obj-$(CONFIG_DVB_TUNER_MT2266) += mt2266.o 47obj-$(CONFIG_DVB_TUNER_MT2266) += mt2266.o
44obj-$(CONFIG_DVB_TUNER_DIB0070) += dib0070.o 48obj-$(CONFIG_DVB_TUNER_DIB0070) += dib0070.o
@@ -46,3 +50,4 @@ obj-$(CONFIG_DVB_TUNER_QT1010) += qt1010.o
46obj-$(CONFIG_DVB_TUA6100) += tua6100.o 50obj-$(CONFIG_DVB_TUA6100) += tua6100.o
47obj-$(CONFIG_DVB_TUNER_MT2131) += mt2131.o 51obj-$(CONFIG_DVB_TUNER_MT2131) += mt2131.o
48obj-$(CONFIG_DVB_S5H1409) += s5h1409.o 52obj-$(CONFIG_DVB_S5H1409) += s5h1409.o
53obj-$(CONFIG_DVB_TUNER_XC5000) += xc5000.o
diff --git a/drivers/media/dvb/frontends/dib0070.c b/drivers/media/dvb/frontends/dib0070.c
index 481eaa684157..fe895bf7b18f 100644
--- a/drivers/media/dvb/frontends/dib0070.c
+++ b/drivers/media/dvb/frontends/dib0070.c
@@ -434,9 +434,14 @@ static u16 dib0070_p1f_defaults[] =
434 0, 434 0,
435}; 435};
436 436
437static void dib0070_wbd_calibration(struct dib0070_state *state) 437static void dib0070_wbd_calibration(struct dvb_frontend *fe)
438{ 438{
439 u16 wbd_offs; 439 u16 wbd_offs;
440 struct dib0070_state *state = fe->tuner_priv;
441
442 if (state->cfg->sleep)
443 state->cfg->sleep(fe, 0);
444
440 dib0070_write_reg(state, 0x0f, 0x6d81); 445 dib0070_write_reg(state, 0x0f, 0x6d81);
441 dib0070_write_reg(state, 0x20, 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001); 446 dib0070_write_reg(state, 0x20, 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001);
442 msleep(9); 447 msleep(9);
@@ -444,6 +449,10 @@ static void dib0070_wbd_calibration(struct dib0070_state *state)
444 dib0070_write_reg(state, 0x20, 0); 449 dib0070_write_reg(state, 0x20, 0);
445 state->wbd_ff_offset = ((wbd_offs * 8 * 18 / 33 + 1) / 2); 450 state->wbd_ff_offset = ((wbd_offs * 8 * 18 / 33 + 1) / 2);
446 dprintk( "WBDStart = %d (Vargen) - FF = %hd", (u32) wbd_offs * 1800/1024, state->wbd_ff_offset); 451 dprintk( "WBDStart = %d (Vargen) - FF = %hd", (u32) wbd_offs * 1800/1024, state->wbd_ff_offset);
452
453 if (state->cfg->sleep)
454 state->cfg->sleep(fe, 1);
455
447} 456}
448 457
449u16 dib0070_wbd_offset(struct dvb_frontend *fe) 458u16 dib0070_wbd_offset(struct dvb_frontend *fe)
@@ -560,7 +569,7 @@ struct dvb_frontend * dib0070_attach(struct dvb_frontend *fe, struct i2c_adapter
560 if (dib0070_reset(state) != 0) 569 if (dib0070_reset(state) != 0)
561 goto free_mem; 570 goto free_mem;
562 571
563 dib0070_wbd_calibration(state); 572 dib0070_wbd_calibration(fe);
564 573
565 printk(KERN_INFO "DiB0070: successfully identified\n"); 574 printk(KERN_INFO "DiB0070: successfully identified\n");
566 memcpy(&fe->ops.tuner_ops, &dib0070_ops, sizeof(struct dvb_tuner_ops)); 575 memcpy(&fe->ops.tuner_ops, &dib0070_ops, sizeof(struct dvb_tuner_ops));
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index edae0be063f5..fa851601e7d4 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -684,6 +684,9 @@ static int dib3000mc_set_frontend(struct dvb_frontend* fe,
684 struct dvb_frontend_parameters *fep) 684 struct dvb_frontend_parameters *fep)
685{ 685{
686 struct dib3000mc_state *state = fe->demodulator_priv; 686 struct dib3000mc_state *state = fe->demodulator_priv;
687 int ret;
688
689 dib3000mc_set_output_mode(state, OUTMODE_HIGH_Z);
687 690
688 state->current_bandwidth = fep->u.ofdm.bandwidth; 691 state->current_bandwidth = fep->u.ofdm.bandwidth;
689 dib3000mc_set_bandwidth(state, BANDWIDTH_TO_KHZ(fep->u.ofdm.bandwidth)); 692 dib3000mc_set_bandwidth(state, BANDWIDTH_TO_KHZ(fep->u.ofdm.bandwidth));
@@ -700,7 +703,7 @@ static int dib3000mc_set_frontend(struct dvb_frontend* fe,
700 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO || 703 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ||
701 fep->u.ofdm.constellation == QAM_AUTO || 704 fep->u.ofdm.constellation == QAM_AUTO ||
702 fep->u.ofdm.code_rate_HP == FEC_AUTO) { 705 fep->u.ofdm.code_rate_HP == FEC_AUTO) {
703 int i = 100, found; 706 int i = 1000, found;
704 707
705 dib3000mc_autosearch_start(fe, fep); 708 dib3000mc_autosearch_start(fe, fep);
706 do { 709 do {
@@ -715,10 +718,11 @@ static int dib3000mc_set_frontend(struct dvb_frontend* fe,
715 dib3000mc_get_frontend(fe, fep); 718 dib3000mc_get_frontend(fe, fep);
716 } 719 }
717 720
721 ret = dib3000mc_tune(fe, fep);
722
718 /* make this a config parameter */ 723 /* make this a config parameter */
719 dib3000mc_set_output_mode(state, OUTMODE_MPEG2_FIFO); 724 dib3000mc_set_output_mode(state, OUTMODE_MPEG2_FIFO);
720 725 return ret;
721 return dib3000mc_tune(fe, fep);
722} 726}
723 727
724static int dib3000mc_read_status(struct dvb_frontend *fe, fe_status_t *stat) 728static int dib3000mc_read_status(struct dvb_frontend *fe, fe_status_t *stat)
diff --git a/drivers/media/dvb/frontends/dib7000m.c b/drivers/media/dvb/frontends/dib7000m.c
index fb18441a8c57..5f1375e30dfc 100644
--- a/drivers/media/dvb/frontends/dib7000m.c
+++ b/drivers/media/dvb/frontends/dib7000m.c
@@ -1171,7 +1171,9 @@ static int dib7000m_set_frontend(struct dvb_frontend* fe,
1171 struct dvb_frontend_parameters *fep) 1171 struct dvb_frontend_parameters *fep)
1172{ 1172{
1173 struct dib7000m_state *state = fe->demodulator_priv; 1173 struct dib7000m_state *state = fe->demodulator_priv;
1174 int time; 1174 int time, ret;
1175
1176 dib7000m_set_output_mode(state, OUTMODE_HIGH_Z);
1175 1177
1176 state->current_bandwidth = fep->u.ofdm.bandwidth; 1178 state->current_bandwidth = fep->u.ofdm.bandwidth;
1177 dib7000m_set_bandwidth(state, BANDWIDTH_TO_KHZ(fep->u.ofdm.bandwidth)); 1179 dib7000m_set_bandwidth(state, BANDWIDTH_TO_KHZ(fep->u.ofdm.bandwidth));
@@ -1206,10 +1208,11 @@ static int dib7000m_set_frontend(struct dvb_frontend* fe,
1206 dib7000m_get_frontend(fe, fep); 1208 dib7000m_get_frontend(fe, fep);
1207 } 1209 }
1208 1210
1211 ret = dib7000m_tune(fe, fep);
1212
1209 /* make this a config parameter */ 1213 /* make this a config parameter */
1210 dib7000m_set_output_mode(state, OUTMODE_MPEG2_FIFO); 1214 dib7000m_set_output_mode(state, OUTMODE_MPEG2_FIFO);
1211 1215 return ret;
1212 return dib7000m_tune(fe, fep);
1213} 1216}
1214 1217
1215static int dib7000m_read_status(struct dvb_frontend *fe, fe_status_t *stat) 1218static int dib7000m_read_status(struct dvb_frontend *fe, fe_status_t *stat)
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index f45bcfc51cf8..47c23e29753e 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -35,8 +35,8 @@ struct dib7000p_state {
35 35
36 u16 wbd_ref; 36 u16 wbd_ref;
37 37
38 u8 current_band; 38 u8 current_band;
39 fe_bandwidth_t current_bandwidth; 39 u32 current_bandwidth;
40 struct dibx000_agc_config *current_agc; 40 struct dibx000_agc_config *current_agc;
41 u32 timf; 41 u32 timf;
42 42
@@ -1074,7 +1074,7 @@ static int dib7000p_get_frontend(struct dvb_frontend* fe,
1074 1074
1075 fep->inversion = INVERSION_AUTO; 1075 fep->inversion = INVERSION_AUTO;
1076 1076
1077 fep->u.ofdm.bandwidth = state->current_bandwidth; 1077 fep->u.ofdm.bandwidth = BANDWIDTH_TO_INDEX(state->current_bandwidth);
1078 1078
1079 switch ((tps >> 8) & 0x3) { 1079 switch ((tps >> 8) & 0x3) {
1080 case 0: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; break; 1080 case 0: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; break;
@@ -1128,12 +1128,11 @@ static int dib7000p_set_frontend(struct dvb_frontend* fe,
1128 struct dvb_frontend_parameters *fep) 1128 struct dvb_frontend_parameters *fep)
1129{ 1129{
1130 struct dib7000p_state *state = fe->demodulator_priv; 1130 struct dib7000p_state *state = fe->demodulator_priv;
1131 int time; 1131 int time, ret;
1132 1132
1133 state->current_bandwidth = fep->u.ofdm.bandwidth; 1133 dib7000p_set_output_mode(state, OUTMODE_HIGH_Z);
1134 dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(fep->u.ofdm.bandwidth));
1135 1134
1136 /* maybe the parameter has been changed */ 1135 /* maybe the parameter has been changed */
1137 state->sfn_workaround_active = buggy_sfn_workaround; 1136 state->sfn_workaround_active = buggy_sfn_workaround;
1138 1137
1139 if (fe->ops.tuner_ops.set_params) 1138 if (fe->ops.tuner_ops.set_params)
@@ -1166,10 +1165,11 @@ static int dib7000p_set_frontend(struct dvb_frontend* fe,
1166 dib7000p_get_frontend(fe, fep); 1165 dib7000p_get_frontend(fe, fep);
1167 } 1166 }
1168 1167
1168 ret = dib7000p_tune(fe, fep);
1169
1169 /* make this a config parameter */ 1170 /* make this a config parameter */
1170 dib7000p_set_output_mode(state, OUTMODE_MPEG2_FIFO); 1171 dib7000p_set_output_mode(state, OUTMODE_MPEG2_FIFO);
1171 1172 return ret;
1172 return dib7000p_tune(fe, fep);
1173} 1173}
1174 1174
1175static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t *stat) 1175static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t *stat)
diff --git a/drivers/media/dvb/frontends/dibx000_common.h b/drivers/media/dvb/frontends/dibx000_common.h
index 5e17275afd25..84e4d5362922 100644
--- a/drivers/media/dvb/frontends/dibx000_common.h
+++ b/drivers/media/dvb/frontends/dibx000_common.h
@@ -128,6 +128,11 @@ enum dibx000_adc_states {
128 (v) == BANDWIDTH_7_MHZ ? 7000 : \ 128 (v) == BANDWIDTH_7_MHZ ? 7000 : \
129 (v) == BANDWIDTH_6_MHZ ? 6000 : 8000 ) 129 (v) == BANDWIDTH_6_MHZ ? 6000 : 8000 )
130 130
131#define BANDWIDTH_TO_INDEX(v) ( \
132 (v) == 8000 ? BANDWIDTH_8_MHZ : \
133 (v) == 7000 ? BANDWIDTH_7_MHZ : \
134 (v) == 6000 ? BANDWIDTH_6_MHZ : BANDWIDTH_8_MHZ )
135
131/* Chip output mode. */ 136/* Chip output mode. */
132#define OUTMODE_HIGH_Z 0 137#define OUTMODE_HIGH_Z 0
133#define OUTMODE_MPEG2_PAR_GATED_CLK 1 138#define OUTMODE_MPEG2_PAR_GATED_CLK 1
diff --git a/drivers/media/dvb/frontends/mt2266.c b/drivers/media/dvb/frontends/mt2266.c
index 03fe8265745f..54b18f94b14b 100644
--- a/drivers/media/dvb/frontends/mt2266.c
+++ b/drivers/media/dvb/frontends/mt2266.c
@@ -38,8 +38,12 @@ struct mt2266_priv {
38 38
39 u32 frequency; 39 u32 frequency;
40 u32 bandwidth; 40 u32 bandwidth;
41 u8 band;
41}; 42};
42 43
44#define MT2266_VHF 1
45#define MT2266_UHF 0
46
43/* Here, frequencies are expressed in kiloHertz to avoid 32 bits overflows */ 47/* Here, frequencies are expressed in kiloHertz to avoid 32 bits overflows */
44 48
45static int debug; 49static int debug;
@@ -90,26 +94,30 @@ static int mt2266_writeregs(struct mt2266_priv *priv,u8 *buf, u8 len)
90} 94}
91 95
92// Initialisation sequences 96// Initialisation sequences
93static u8 mt2266_init1[] = { 97static u8 mt2266_init1[] = { REG_TUNE, 0x00, 0x00, 0x28,
94 REG_TUNE, 98 0x00, 0x52, 0x99, 0x3f };
95 0x00, 0x00, 0x28, 0x00, 0x52, 0x99, 0x3f };
96 99
97static u8 mt2266_init2[] = { 100static u8 mt2266_init2[] = {
98 0x17, 0x6d, 0x71, 0x61, 0xc0, 0xbf, 0xff, 0xdc, 0x00, 0x0a, 101 0x17, 0x6d, 0x71, 0x61, 0xc0, 0xbf, 0xff, 0xdc, 0x00, 0x0a, 0xd4,
99 0xd4, 0x03, 0x64, 0x64, 0x64, 0x64, 0x22, 0xaa, 0xf2, 0x1e, 0x80, 0x14, 0x01, 0x01, 0x01, 0x01, 102 0x03, 0x64, 0x64, 0x64, 0x64, 0x22, 0xaa, 0xf2, 0x1e, 0x80, 0x14,
100 0x01, 0x01, 0x7f, 0x5e, 0x3f, 0xff, 0xff, 0xff, 0x00, 0x77, 0x0f, 0x2d }; 103 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x7f, 0x5e, 0x3f, 0xff, 0xff,
104 0xff, 0x00, 0x77, 0x0f, 0x2d
105};
106
107static u8 mt2266_init_8mhz[] = { REG_BANDWIDTH, 0x22, 0x22, 0x22, 0x22,
108 0x22, 0x22, 0x22, 0x22 };
101 109
102static u8 mt2266_init_8mhz[] = { 110static u8 mt2266_init_7mhz[] = { REG_BANDWIDTH, 0x32, 0x32, 0x32, 0x32,
103 REG_BANDWIDTH, 111 0x32, 0x32, 0x32, 0x32 };
104 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 };
105 112
106static u8 mt2266_init_7mhz[] = { 113static u8 mt2266_init_6mhz[] = { REG_BANDWIDTH, 0xa7, 0xa7, 0xa7, 0xa7,
107 REG_BANDWIDTH, 114 0xa7, 0xa7, 0xa7, 0xa7 };
108 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32 };
109 115
110static u8 mt2266_init_6mhz[] = { 116static u8 mt2266_uhf[] = { 0x1d, 0xdc, 0x00, 0x0a, 0xd4, 0x03, 0x64, 0x64,
111 REG_BANDWIDTH, 117 0x64, 0x64, 0x22, 0xaa, 0xf2, 0x1e, 0x80, 0x14 };
112 0xa7, 0xa7, 0xa7, 0xa7, 0xa7, 0xa7, 0xa7, 0xa7 }; 118
119static u8 mt2266_vhf[] = { 0x1d, 0xfe, 0x00, 0x00, 0xb4, 0x03, 0xa5, 0xa5,
120 0xa5, 0xa5, 0x82, 0xaa, 0xf1, 0x17, 0x80, 0x1f };
113 121
114#define FREF 30000 // Quartz oscillator 30 MHz 122#define FREF 30000 // Quartz oscillator 30 MHz
115 123
@@ -122,35 +130,78 @@ static int mt2266_set_params(struct dvb_frontend *fe, struct dvb_frontend_parame
122 u8 lnaband; 130 u8 lnaband;
123 u8 b[10]; 131 u8 b[10];
124 int i; 132 int i;
133 u8 band;
125 134
126 priv = fe->tuner_priv; 135 priv = fe->tuner_priv;
127 136
128 mt2266_writereg(priv,0x17,0x6d);
129 mt2266_writereg(priv,0x1c,0xff);
130
131 freq = params->frequency / 1000; // Hz -> kHz 137 freq = params->frequency / 1000; // Hz -> kHz
138 if (freq < 470000 && freq > 230000)
139 return -EINVAL; /* Gap between VHF and UHF bands */
132 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0; 140 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
133 priv->frequency = freq * 1000; 141 priv->frequency = freq * 1000;
134 tune=2 * freq * (8192/16) / (FREF/16); 142
135 143 tune = 2 * freq * (8192/16) / (FREF/16);
136 if (freq <= 495000) lnaband = 0xEE; else 144 band = (freq < 300000) ? MT2266_VHF : MT2266_UHF;
137 if (freq <= 525000) lnaband = 0xDD; else 145 if (band == MT2266_VHF)
138 if (freq <= 550000) lnaband = 0xCC; else 146 tune *= 2;
139 if (freq <= 580000) lnaband = 0xBB; else 147
140 if (freq <= 605000) lnaband = 0xAA; else 148 switch (params->u.ofdm.bandwidth) {
141 if (freq <= 630000) lnaband = 0x99; else 149 case BANDWIDTH_6_MHZ:
142 if (freq <= 655000) lnaband = 0x88; else 150 mt2266_writeregs(priv, mt2266_init_6mhz,
143 if (freq <= 685000) lnaband = 0x77; else 151 sizeof(mt2266_init_6mhz));
144 if (freq <= 710000) lnaband = 0x66; else 152 break;
145 if (freq <= 735000) lnaband = 0x55; else 153 case BANDWIDTH_7_MHZ:
146 if (freq <= 765000) lnaband = 0x44; else 154 mt2266_writeregs(priv, mt2266_init_7mhz,
147 if (freq <= 802000) lnaband = 0x33; else 155 sizeof(mt2266_init_7mhz));
148 if (freq <= 840000) lnaband = 0x22; else lnaband = 0x11; 156 break;
149 157 case BANDWIDTH_8_MHZ:
150 msleep(100); 158 default:
151 mt2266_writeregs(priv,(params->u.ofdm.bandwidth==BANDWIDTH_6_MHZ)?mt2266_init_6mhz: 159 mt2266_writeregs(priv, mt2266_init_8mhz,
152 (params->u.ofdm.bandwidth==BANDWIDTH_7_MHZ)?mt2266_init_7mhz: 160 sizeof(mt2266_init_8mhz));
153 mt2266_init_8mhz,sizeof(mt2266_init_8mhz)); 161 break;
162 }
163
164 if (band == MT2266_VHF && priv->band == MT2266_UHF) {
165 dprintk("Switch from UHF to VHF");
166 mt2266_writereg(priv, 0x05, 0x04);
167 mt2266_writereg(priv, 0x19, 0x61);
168 mt2266_writeregs(priv, mt2266_vhf, sizeof(mt2266_vhf));
169 } else if (band == MT2266_UHF && priv->band == MT2266_VHF) {
170 dprintk("Switch from VHF to UHF");
171 mt2266_writereg(priv, 0x05, 0x52);
172 mt2266_writereg(priv, 0x19, 0x61);
173 mt2266_writeregs(priv, mt2266_uhf, sizeof(mt2266_uhf));
174 }
175 msleep(10);
176
177 if (freq <= 495000)
178 lnaband = 0xEE;
179 else if (freq <= 525000)
180 lnaband = 0xDD;
181 else if (freq <= 550000)
182 lnaband = 0xCC;
183 else if (freq <= 580000)
184 lnaband = 0xBB;
185 else if (freq <= 605000)
186 lnaband = 0xAA;
187 else if (freq <= 630000)
188 lnaband = 0x99;
189 else if (freq <= 655000)
190 lnaband = 0x88;
191 else if (freq <= 685000)
192 lnaband = 0x77;
193 else if (freq <= 710000)
194 lnaband = 0x66;
195 else if (freq <= 735000)
196 lnaband = 0x55;
197 else if (freq <= 765000)
198 lnaband = 0x44;
199 else if (freq <= 802000)
200 lnaband = 0x33;
201 else if (freq <= 840000)
202 lnaband = 0x22;
203 else
204 lnaband = 0x11;
154 205
155 b[0] = REG_TUNE; 206 b[0] = REG_TUNE;
156 b[1] = (tune >> 8) & 0x1F; 207 b[1] = (tune >> 8) & 0x1F;
@@ -158,47 +209,54 @@ static int mt2266_set_params(struct dvb_frontend *fe, struct dvb_frontend_parame
158 b[3] = tune >> 13; 209 b[3] = tune >> 13;
159 mt2266_writeregs(priv,b,4); 210 mt2266_writeregs(priv,b,4);
160 211
161 dprintk("set_parms: tune=%d band=%d",(int)tune,(int)lnaband); 212 dprintk("set_parms: tune=%d band=%d %s",
162 dprintk("set_parms: [1..3]: %2x %2x %2x",(int)b[1],(int)b[2],(int)b[3]); 213 (int) tune, (int) lnaband,
163 214 (band == MT2266_UHF) ? "UHF" : "VHF");
164 b[0] = 0x05; 215 dprintk("set_parms: [1..3]: %2x %2x %2x",
165 b[1] = 0x62; 216 (int) b[1], (int) b[2], (int)b[3]);
166 b[2] = lnaband; 217
167 mt2266_writeregs(priv,b,3); 218 if (band == MT2266_UHF) {
219 b[0] = 0x05;
220 b[1] = (priv->band == MT2266_VHF) ? 0x52 : 0x62;
221 b[2] = lnaband;
222 mt2266_writeregs(priv, b, 3);
223 }
168 224
169 //Waits for pll lock or timeout 225 /* Wait for pll lock or timeout */
170 i = 0; 226 i = 0;
171 do { 227 do {
172 mt2266_readreg(priv,REG_LOCK,b); 228 mt2266_readreg(priv,REG_LOCK,b);
173 if ((b[0] & 0x40)==0x40) 229 if (b[0] & 0x40)
174 break; 230 break;
175 msleep(10); 231 msleep(10);
176 i++; 232 i++;
177 } while (i<10); 233 } while (i<10);
178 dprintk("Lock when i=%i",(int)i); 234 dprintk("Lock when i=%i",(int)i);
235
236 if (band == MT2266_UHF && priv->band == MT2266_VHF)
237 mt2266_writereg(priv, 0x05, 0x62);
238
239 priv->band = band;
240
179 return ret; 241 return ret;
180} 242}
181 243
182static void mt2266_calibrate(struct mt2266_priv *priv) 244static void mt2266_calibrate(struct mt2266_priv *priv)
183{ 245{
184 mt2266_writereg(priv,0x11,0x03); 246 mt2266_writereg(priv, 0x11, 0x03);
185 mt2266_writereg(priv,0x11,0x01); 247 mt2266_writereg(priv, 0x11, 0x01);
186 248 mt2266_writeregs(priv, mt2266_init1, sizeof(mt2266_init1));
187 mt2266_writeregs(priv,mt2266_init1,sizeof(mt2266_init1)); 249 mt2266_writeregs(priv, mt2266_init2, sizeof(mt2266_init2));
188 mt2266_writeregs(priv,mt2266_init2,sizeof(mt2266_init2)); 250 mt2266_writereg(priv, 0x33, 0x5e);
189 251 mt2266_writereg(priv, 0x10, 0x10);
190 mt2266_writereg(priv,0x33,0x5e); 252 mt2266_writereg(priv, 0x10, 0x00);
191 mt2266_writereg(priv,0x10,0x10); 253 mt2266_writeregs(priv, mt2266_init_8mhz, sizeof(mt2266_init_8mhz));
192 mt2266_writereg(priv,0x10,0x00);
193
194 mt2266_writeregs(priv,mt2266_init_8mhz,sizeof(mt2266_init_8mhz));
195
196 msleep(25); 254 msleep(25);
197 mt2266_writereg(priv,0x17,0x6d); 255 mt2266_writereg(priv, 0x17, 0x6d);
198 mt2266_writereg(priv,0x1c,0x00); 256 mt2266_writereg(priv, 0x1c, 0x00);
199 msleep(75); 257 msleep(75);
200 mt2266_writereg(priv,0x17,0x6d); 258 mt2266_writereg(priv, 0x17, 0x6d);
201 mt2266_writereg(priv,0x1c,0xff); 259 mt2266_writereg(priv, 0x1c, 0xff);
202} 260}
203 261
204static int mt2266_get_frequency(struct dvb_frontend *fe, u32 *frequency) 262static int mt2266_get_frequency(struct dvb_frontend *fe, u32 *frequency)
@@ -217,17 +275,22 @@ static int mt2266_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
217 275
218static int mt2266_init(struct dvb_frontend *fe) 276static int mt2266_init(struct dvb_frontend *fe)
219{ 277{
278 int ret;
220 struct mt2266_priv *priv = fe->tuner_priv; 279 struct mt2266_priv *priv = fe->tuner_priv;
221 mt2266_writereg(priv,0x17,0x6d); 280 ret = mt2266_writereg(priv, 0x17, 0x6d);
222 mt2266_writereg(priv,0x1c,0xff); 281 if (ret < 0)
282 return ret;
283 ret = mt2266_writereg(priv, 0x1c, 0xff);
284 if (ret < 0)
285 return ret;
223 return 0; 286 return 0;
224} 287}
225 288
226static int mt2266_sleep(struct dvb_frontend *fe) 289static int mt2266_sleep(struct dvb_frontend *fe)
227{ 290{
228 struct mt2266_priv *priv = fe->tuner_priv; 291 struct mt2266_priv *priv = fe->tuner_priv;
229 mt2266_writereg(priv,0x17,0x6d); 292 mt2266_writereg(priv, 0x17, 0x6d);
230 mt2266_writereg(priv,0x1c,0x00); 293 mt2266_writereg(priv, 0x1c, 0x00);
231 return 0; 294 return 0;
232} 295}
233 296
@@ -241,8 +304,8 @@ static int mt2266_release(struct dvb_frontend *fe)
241static const struct dvb_tuner_ops mt2266_tuner_ops = { 304static const struct dvb_tuner_ops mt2266_tuner_ops = {
242 .info = { 305 .info = {
243 .name = "Microtune MT2266", 306 .name = "Microtune MT2266",
244 .frequency_min = 470000000, 307 .frequency_min = 174000000,
245 .frequency_max = 860000000, 308 .frequency_max = 862000000,
246 .frequency_step = 50000, 309 .frequency_step = 50000,
247 }, 310 },
248 .release = mt2266_release, 311 .release = mt2266_release,
@@ -264,8 +327,9 @@ struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter
264 327
265 priv->cfg = cfg; 328 priv->cfg = cfg;
266 priv->i2c = i2c; 329 priv->i2c = i2c;
330 priv->band = MT2266_UHF;
267 331
268 if (mt2266_readreg(priv,0,&id) != 0) { 332 if (mt2266_readreg(priv, 0, &id)) {
269 kfree(priv); 333 kfree(priv);
270 return NULL; 334 return NULL;
271 } 335 }
diff --git a/drivers/media/dvb/frontends/mt312.c b/drivers/media/dvb/frontends/mt312.c
index 0606b9a5b616..1638301fbd6e 100644
--- a/drivers/media/dvb/frontends/mt312.c
+++ b/drivers/media/dvb/frontends/mt312.c
@@ -37,9 +37,9 @@
37 37
38 38
39struct mt312_state { 39struct mt312_state {
40 struct i2c_adapter* i2c; 40 struct i2c_adapter *i2c;
41 /* configuration settings */ 41 /* configuration settings */
42 const struct mt312_config* config; 42 const struct mt312_config *config;
43 struct dvb_frontend frontend; 43 struct dvb_frontend frontend;
44 44
45 u8 id; 45 u8 id;
@@ -49,14 +49,15 @@ struct mt312_state {
49static int debug; 49static int debug;
50#define dprintk(args...) \ 50#define dprintk(args...) \
51 do { \ 51 do { \
52 if (debug) printk(KERN_DEBUG "mt312: " args); \ 52 if (debug) \
53 printk(KERN_DEBUG "mt312: " args); \
53 } while (0) 54 } while (0)
54 55
55#define MT312_SYS_CLK 90000000UL /* 90 MHz */ 56#define MT312_SYS_CLK 90000000UL /* 90 MHz */
56#define MT312_LPOWER_SYS_CLK 60000000UL /* 60 MHz */ 57#define MT312_LPOWER_SYS_CLK 60000000UL /* 60 MHz */
57#define MT312_PLL_CLK 10000000UL /* 10 MHz */ 58#define MT312_PLL_CLK 10000000UL /* 10 MHz */
58 59
59static int mt312_read(struct mt312_state* state, const enum mt312_reg_addr reg, 60static int mt312_read(struct mt312_state *state, const enum mt312_reg_addr reg,
60 void *buf, const size_t count) 61 void *buf, const size_t count)
61{ 62{
62 int ret; 63 int ret;
@@ -79,7 +80,7 @@ static int mt312_read(struct mt312_state* state, const enum mt312_reg_addr reg,
79 return -EREMOTEIO; 80 return -EREMOTEIO;
80 } 81 }
81 82
82 if(debug) { 83 if (debug) {
83 int i; 84 int i;
84 dprintk("R(%d):", reg & 0x7f); 85 dprintk("R(%d):", reg & 0x7f);
85 for (i = 0; i < count; i++) 86 for (i = 0; i < count; i++)
@@ -90,14 +91,14 @@ static int mt312_read(struct mt312_state* state, const enum mt312_reg_addr reg,
90 return 0; 91 return 0;
91} 92}
92 93
93static int mt312_write(struct mt312_state* state, const enum mt312_reg_addr reg, 94static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg,
94 const void *src, const size_t count) 95 const void *src, const size_t count)
95{ 96{
96 int ret; 97 int ret;
97 u8 buf[count + 1]; 98 u8 buf[count + 1];
98 struct i2c_msg msg; 99 struct i2c_msg msg;
99 100
100 if(debug) { 101 if (debug) {
101 int i; 102 int i;
102 dprintk("W(%d):", reg & 0x7f); 103 dprintk("W(%d):", reg & 0x7f);
103 for (i = 0; i < count; i++) 104 for (i = 0; i < count; i++)
@@ -123,13 +124,13 @@ static int mt312_write(struct mt312_state* state, const enum mt312_reg_addr reg,
123 return 0; 124 return 0;
124} 125}
125 126
126static inline int mt312_readreg(struct mt312_state* state, 127static inline int mt312_readreg(struct mt312_state *state,
127 const enum mt312_reg_addr reg, u8 *val) 128 const enum mt312_reg_addr reg, u8 *val)
128{ 129{
129 return mt312_read(state, reg, val, 1); 130 return mt312_read(state, reg, val, 1);
130} 131}
131 132
132static inline int mt312_writereg(struct mt312_state* state, 133static inline int mt312_writereg(struct mt312_state *state,
133 const enum mt312_reg_addr reg, const u8 val) 134 const enum mt312_reg_addr reg, const u8 val)
134{ 135{
135 return mt312_write(state, reg, &val, 1); 136 return mt312_write(state, reg, &val, 1);
@@ -140,18 +141,19 @@ static inline u32 mt312_div(u32 a, u32 b)
140 return (a + (b / 2)) / b; 141 return (a + (b / 2)) / b;
141} 142}
142 143
143static int mt312_reset(struct mt312_state* state, const u8 full) 144static int mt312_reset(struct mt312_state *state, const u8 full)
144{ 145{
145 return mt312_writereg(state, RESET, full ? 0x80 : 0x40); 146 return mt312_writereg(state, RESET, full ? 0x80 : 0x40);
146} 147}
147 148
148static int mt312_get_inversion(struct mt312_state* state, 149static int mt312_get_inversion(struct mt312_state *state,
149 fe_spectral_inversion_t *i) 150 fe_spectral_inversion_t *i)
150{ 151{
151 int ret; 152 int ret;
152 u8 vit_mode; 153 u8 vit_mode;
153 154
154 if ((ret = mt312_readreg(state, VIT_MODE, &vit_mode)) < 0) 155 ret = mt312_readreg(state, VIT_MODE, &vit_mode);
156 if (ret < 0)
155 return ret; 157 return ret;
156 158
157 if (vit_mode & 0x80) /* auto inversion was used */ 159 if (vit_mode & 0x80) /* auto inversion was used */
@@ -160,7 +162,7 @@ static int mt312_get_inversion(struct mt312_state* state,
160 return 0; 162 return 0;
161} 163}
162 164
163static int mt312_get_symbol_rate(struct mt312_state* state, u32 *sr) 165static int mt312_get_symbol_rate(struct mt312_state *state, u32 *sr)
164{ 166{
165 int ret; 167 int ret;
166 u8 sym_rate_h; 168 u8 sym_rate_h;
@@ -169,37 +171,44 @@ static int mt312_get_symbol_rate(struct mt312_state* state, u32 *sr)
169 u16 monitor; 171 u16 monitor;
170 u8 buf[2]; 172 u8 buf[2];
171 173
172 if ((ret = mt312_readreg(state, SYM_RATE_H, &sym_rate_h)) < 0) 174 ret = mt312_readreg(state, SYM_RATE_H, &sym_rate_h);
175 if (ret < 0)
173 return ret; 176 return ret;
174 177
175 if (sym_rate_h & 0x80) { /* symbol rate search was used */ 178 if (sym_rate_h & 0x80) {
176 if ((ret = mt312_writereg(state, MON_CTRL, 0x03)) < 0) 179 /* symbol rate search was used */
180 ret = mt312_writereg(state, MON_CTRL, 0x03);
181 if (ret < 0)
177 return ret; 182 return ret;
178 183
179 if ((ret = mt312_read(state, MONITOR_H, buf, sizeof(buf))) < 0) 184 ret = mt312_read(state, MONITOR_H, buf, sizeof(buf));
185 if (ret < 0)
180 return ret; 186 return ret;
181 187
182 monitor = (buf[0] << 8) | buf[1]; 188 monitor = (buf[0] << 8) | buf[1];
183 189
184 dprintk(KERN_DEBUG "sr(auto) = %u\n", 190 dprintk("sr(auto) = %u\n",
185 mt312_div(monitor * 15625, 4)); 191 mt312_div(monitor * 15625, 4));
186 } else { 192 } else {
187 if ((ret = mt312_writereg(state, MON_CTRL, 0x05)) < 0) 193 ret = mt312_writereg(state, MON_CTRL, 0x05);
194 if (ret < 0)
188 return ret; 195 return ret;
189 196
190 if ((ret = mt312_read(state, MONITOR_H, buf, sizeof(buf))) < 0) 197 ret = mt312_read(state, MONITOR_H, buf, sizeof(buf));
198 if (ret < 0)
191 return ret; 199 return ret;
192 200
193 dec_ratio = ((buf[0] >> 5) & 0x07) * 32; 201 dec_ratio = ((buf[0] >> 5) & 0x07) * 32;
194 202
195 if ((ret = mt312_read(state, SYM_RAT_OP_H, buf, sizeof(buf))) < 0) 203 ret = mt312_read(state, SYM_RAT_OP_H, buf, sizeof(buf));
204 if (ret < 0)
196 return ret; 205 return ret;
197 206
198 sym_rat_op = (buf[0] << 8) | buf[1]; 207 sym_rat_op = (buf[0] << 8) | buf[1];
199 208
200 dprintk(KERN_DEBUG "sym_rat_op=%d dec_ratio=%d\n", 209 dprintk("sym_rat_op=%d dec_ratio=%d\n",
201 sym_rat_op, dec_ratio); 210 sym_rat_op, dec_ratio);
202 dprintk(KERN_DEBUG "*sr(manual) = %lu\n", 211 dprintk("*sr(manual) = %lu\n",
203 (((MT312_PLL_CLK * 8192) / (sym_rat_op + 8192)) * 212 (((MT312_PLL_CLK * 8192) / (sym_rat_op + 8192)) *
204 2) - dec_ratio); 213 2) - dec_ratio);
205 } 214 }
@@ -207,7 +216,7 @@ static int mt312_get_symbol_rate(struct mt312_state* state, u32 *sr)
207 return 0; 216 return 0;
208} 217}
209 218
210static int mt312_get_code_rate(struct mt312_state* state, fe_code_rate_t *cr) 219static int mt312_get_code_rate(struct mt312_state *state, fe_code_rate_t *cr)
211{ 220{
212 const fe_code_rate_t fec_tab[8] = 221 const fe_code_rate_t fec_tab[8] =
213 { FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_6_7, FEC_7_8, 222 { FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_6_7, FEC_7_8,
@@ -216,7 +225,8 @@ static int mt312_get_code_rate(struct mt312_state* state, fe_code_rate_t *cr)
216 int ret; 225 int ret;
217 u8 fec_status; 226 u8 fec_status;
218 227
219 if ((ret = mt312_readreg(state, FEC_STATUS, &fec_status)) < 0) 228 ret = mt312_readreg(state, FEC_STATUS, &fec_status);
229 if (ret < 0)
220 return ret; 230 return ret;
221 231
222 *cr = fec_tab[(fec_status >> 4) & 0x07]; 232 *cr = fec_tab[(fec_status >> 4) & 0x07];
@@ -224,61 +234,72 @@ static int mt312_get_code_rate(struct mt312_state* state, fe_code_rate_t *cr)
224 return 0; 234 return 0;
225} 235}
226 236
227static int mt312_initfe(struct dvb_frontend* fe) 237static int mt312_initfe(struct dvb_frontend *fe)
228{ 238{
229 struct mt312_state *state = fe->demodulator_priv; 239 struct mt312_state *state = fe->demodulator_priv;
230 int ret; 240 int ret;
231 u8 buf[2]; 241 u8 buf[2];
232 242
233 /* wake up */ 243 /* wake up */
234 if ((ret = mt312_writereg(state, CONFIG, (state->frequency == 60 ? 0x88 : 0x8c))) < 0) 244 ret = mt312_writereg(state, CONFIG,
245 (state->frequency == 60 ? 0x88 : 0x8c));
246 if (ret < 0)
235 return ret; 247 return ret;
236 248
237 /* wait at least 150 usec */ 249 /* wait at least 150 usec */
238 udelay(150); 250 udelay(150);
239 251
240 /* full reset */ 252 /* full reset */
241 if ((ret = mt312_reset(state, 1)) < 0) 253 ret = mt312_reset(state, 1);
254 if (ret < 0)
242 return ret; 255 return ret;
243 256
244// Per datasheet, write correct values. 09/28/03 ACCJr. 257/* Per datasheet, write correct values. 09/28/03 ACCJr.
245// If we don't do this, we won't get FE_HAS_VITERBI in the VP310. 258 * If we don't do this, we won't get FE_HAS_VITERBI in the VP310. */
246 { 259 {
247 u8 buf_def[8]={0x14, 0x12, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00}; 260 u8 buf_def[8] = { 0x14, 0x12, 0x03, 0x02,
261 0x01, 0x00, 0x00, 0x00 };
248 262
249 if ((ret = mt312_write(state, VIT_SETUP, buf_def, sizeof(buf_def))) < 0) 263 ret = mt312_write(state, VIT_SETUP, buf_def, sizeof(buf_def));
264 if (ret < 0)
250 return ret; 265 return ret;
251 } 266 }
252 267
253 /* SYS_CLK */ 268 /* SYS_CLK */
254 buf[0] = mt312_div((state->frequency == 60 ? MT312_LPOWER_SYS_CLK : MT312_SYS_CLK) * 2, 1000000); 269 buf[0] = mt312_div((state->frequency == 60 ? MT312_LPOWER_SYS_CLK :
270 MT312_SYS_CLK) * 2, 1000000);
255 271
256 /* DISEQC_RATIO */ 272 /* DISEQC_RATIO */
257 buf[1] = mt312_div(MT312_PLL_CLK, 15000 * 4); 273 buf[1] = mt312_div(MT312_PLL_CLK, 15000 * 4);
258 274
259 if ((ret = mt312_write(state, SYS_CLK, buf, sizeof(buf))) < 0) 275 ret = mt312_write(state, SYS_CLK, buf, sizeof(buf));
276 if (ret < 0)
260 return ret; 277 return ret;
261 278
262 if ((ret = mt312_writereg(state, SNR_THS_HIGH, 0x32)) < 0) 279 ret = mt312_writereg(state, SNR_THS_HIGH, 0x32);
280 if (ret < 0)
263 return ret; 281 return ret;
264 282
265 if ((ret = mt312_writereg(state, OP_CTRL, 0x53)) < 0) 283 ret = mt312_writereg(state, OP_CTRL, 0x53);
284 if (ret < 0)
266 return ret; 285 return ret;
267 286
268 /* TS_SW_LIM */ 287 /* TS_SW_LIM */
269 buf[0] = 0x8c; 288 buf[0] = 0x8c;
270 buf[1] = 0x98; 289 buf[1] = 0x98;
271 290
272 if ((ret = mt312_write(state, TS_SW_LIM_L, buf, sizeof(buf))) < 0) 291 ret = mt312_write(state, TS_SW_LIM_L, buf, sizeof(buf));
292 if (ret < 0)
273 return ret; 293 return ret;
274 294
275 if ((ret = mt312_writereg(state, CS_SW_LIM, 0x69)) < 0) 295 ret = mt312_writereg(state, CS_SW_LIM, 0x69);
296 if (ret < 0)
276 return ret; 297 return ret;
277 298
278 return 0; 299 return 0;
279} 300}
280 301
281static int mt312_send_master_cmd(struct dvb_frontend* fe, 302static int mt312_send_master_cmd(struct dvb_frontend *fe,
282 struct dvb_diseqc_master_cmd *c) 303 struct dvb_diseqc_master_cmd *c)
283{ 304{
284 struct mt312_state *state = fe->demodulator_priv; 305 struct mt312_state *state = fe->demodulator_priv;
@@ -288,29 +309,31 @@ static int mt312_send_master_cmd(struct dvb_frontend* fe,
288 if ((c->msg_len == 0) || (c->msg_len > sizeof(c->msg))) 309 if ((c->msg_len == 0) || (c->msg_len > sizeof(c->msg)))
289 return -EINVAL; 310 return -EINVAL;
290 311
291 if ((ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode)) < 0) 312 ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode);
313 if (ret < 0)
292 return ret; 314 return ret;
293 315
294 if ((ret = 316 ret = mt312_write(state, (0x80 | DISEQC_INSTR), c->msg, c->msg_len);
295 mt312_write(state, (0x80 | DISEQC_INSTR), c->msg, c->msg_len)) < 0) 317 if (ret < 0)
296 return ret; 318 return ret;
297 319
298 if ((ret = 320 ret = mt312_writereg(state, DISEQC_MODE,
299 mt312_writereg(state, DISEQC_MODE, 321 (diseqc_mode & 0x40) | ((c->msg_len - 1) << 3)
300 (diseqc_mode & 0x40) | ((c->msg_len - 1) << 3) 322 | 0x04);
301 | 0x04)) < 0) 323 if (ret < 0)
302 return ret; 324 return ret;
303 325
304 /* set DISEQC_MODE[2:0] to zero if a return message is expected */ 326 /* set DISEQC_MODE[2:0] to zero if a return message is expected */
305 if (c->msg[0] & 0x02) 327 if (c->msg[0] & 0x02) {
306 if ((ret = 328 ret = mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40));
307 mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40))) < 0) 329 if (ret < 0)
308 return ret; 330 return ret;
331 }
309 332
310 return 0; 333 return 0;
311} 334}
312 335
313static int mt312_send_burst(struct dvb_frontend* fe, const fe_sec_mini_cmd_t c) 336static int mt312_send_burst(struct dvb_frontend *fe, const fe_sec_mini_cmd_t c)
314{ 337{
315 struct mt312_state *state = fe->demodulator_priv; 338 struct mt312_state *state = fe->demodulator_priv;
316 const u8 mini_tab[2] = { 0x02, 0x03 }; 339 const u8 mini_tab[2] = { 0x02, 0x03 };
@@ -321,18 +344,19 @@ static int mt312_send_burst(struct dvb_frontend* fe, const fe_sec_mini_cmd_t c)
321 if (c > SEC_MINI_B) 344 if (c > SEC_MINI_B)
322 return -EINVAL; 345 return -EINVAL;
323 346
324 if ((ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode)) < 0) 347 ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode);
348 if (ret < 0)
325 return ret; 349 return ret;
326 350
327 if ((ret = 351 ret = mt312_writereg(state, DISEQC_MODE,
328 mt312_writereg(state, DISEQC_MODE, 352 (diseqc_mode & 0x40) | mini_tab[c]);
329 (diseqc_mode & 0x40) | mini_tab[c])) < 0) 353 if (ret < 0)
330 return ret; 354 return ret;
331 355
332 return 0; 356 return 0;
333} 357}
334 358
335static int mt312_set_tone(struct dvb_frontend* fe, const fe_sec_tone_mode_t t) 359static int mt312_set_tone(struct dvb_frontend *fe, const fe_sec_tone_mode_t t)
336{ 360{
337 struct mt312_state *state = fe->demodulator_priv; 361 struct mt312_state *state = fe->demodulator_priv;
338 const u8 tone_tab[2] = { 0x01, 0x00 }; 362 const u8 tone_tab[2] = { 0x01, 0x00 };
@@ -343,18 +367,19 @@ static int mt312_set_tone(struct dvb_frontend* fe, const fe_sec_tone_mode_t t)
343 if (t > SEC_TONE_OFF) 367 if (t > SEC_TONE_OFF)
344 return -EINVAL; 368 return -EINVAL;
345 369
346 if ((ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode)) < 0) 370 ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode);
371 if (ret < 0)
347 return ret; 372 return ret;
348 373
349 if ((ret = 374 ret = mt312_writereg(state, DISEQC_MODE,
350 mt312_writereg(state, DISEQC_MODE, 375 (diseqc_mode & 0x40) | tone_tab[t]);
351 (diseqc_mode & 0x40) | tone_tab[t])) < 0) 376 if (ret < 0)
352 return ret; 377 return ret;
353 378
354 return 0; 379 return 0;
355} 380}
356 381
357static int mt312_set_voltage(struct dvb_frontend* fe, const fe_sec_voltage_t v) 382static int mt312_set_voltage(struct dvb_frontend *fe, const fe_sec_voltage_t v)
358{ 383{
359 struct mt312_state *state = fe->demodulator_priv; 384 struct mt312_state *state = fe->demodulator_priv;
360 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 }; 385 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 };
@@ -365,7 +390,7 @@ static int mt312_set_voltage(struct dvb_frontend* fe, const fe_sec_voltage_t v)
365 return mt312_writereg(state, DISEQC_MODE, volt_tab[v]); 390 return mt312_writereg(state, DISEQC_MODE, volt_tab[v]);
366} 391}
367 392
368static int mt312_read_status(struct dvb_frontend* fe, fe_status_t *s) 393static int mt312_read_status(struct dvb_frontend *fe, fe_status_t *s)
369{ 394{
370 struct mt312_state *state = fe->demodulator_priv; 395 struct mt312_state *state = fe->demodulator_priv;
371 int ret; 396 int ret;
@@ -373,10 +398,12 @@ static int mt312_read_status(struct dvb_frontend* fe, fe_status_t *s)
373 398
374 *s = 0; 399 *s = 0;
375 400
376 if ((ret = mt312_read(state, QPSK_STAT_H, status, sizeof(status))) < 0) 401 ret = mt312_read(state, QPSK_STAT_H, status, sizeof(status));
402 if (ret < 0)
377 return ret; 403 return ret;
378 404
379 dprintk(KERN_DEBUG "QPSK_STAT_H: 0x%02x, QPSK_STAT_L: 0x%02x, FEC_STATUS: 0x%02x\n", status[0], status[1], status[2]); 405 dprintk("QPSK_STAT_H: 0x%02x, QPSK_STAT_L: 0x%02x,"
406 " FEC_STATUS: 0x%02x\n", status[0], status[1], status[2]);
380 407
381 if (status[0] & 0xc0) 408 if (status[0] & 0xc0)
382 *s |= FE_HAS_SIGNAL; /* signal noise ratio */ 409 *s |= FE_HAS_SIGNAL; /* signal noise ratio */
@@ -392,13 +419,14 @@ static int mt312_read_status(struct dvb_frontend* fe, fe_status_t *s)
392 return 0; 419 return 0;
393} 420}
394 421
395static int mt312_read_ber(struct dvb_frontend* fe, u32 *ber) 422static int mt312_read_ber(struct dvb_frontend *fe, u32 *ber)
396{ 423{
397 struct mt312_state *state = fe->demodulator_priv; 424 struct mt312_state *state = fe->demodulator_priv;
398 int ret; 425 int ret;
399 u8 buf[3]; 426 u8 buf[3];
400 427
401 if ((ret = mt312_read(state, RS_BERCNT_H, buf, 3)) < 0) 428 ret = mt312_read(state, RS_BERCNT_H, buf, 3);
429 if (ret < 0)
402 return ret; 430 return ret;
403 431
404 *ber = ((buf[0] << 16) | (buf[1] << 8) | buf[2]) * 64; 432 *ber = ((buf[0] << 16) | (buf[1] << 8) | buf[2]) * 64;
@@ -406,7 +434,8 @@ static int mt312_read_ber(struct dvb_frontend* fe, u32 *ber)
406 return 0; 434 return 0;
407} 435}
408 436
409static int mt312_read_signal_strength(struct dvb_frontend* fe, u16 *signal_strength) 437static int mt312_read_signal_strength(struct dvb_frontend *fe,
438 u16 *signal_strength)
410{ 439{
411 struct mt312_state *state = fe->demodulator_priv; 440 struct mt312_state *state = fe->demodulator_priv;
412 int ret; 441 int ret;
@@ -414,7 +443,8 @@ static int mt312_read_signal_strength(struct dvb_frontend* fe, u16 *signal_stren
414 u16 agc; 443 u16 agc;
415 s16 err_db; 444 s16 err_db;
416 445
417 if ((ret = mt312_read(state, AGC_H, buf, sizeof(buf))) < 0) 446 ret = mt312_read(state, AGC_H, buf, sizeof(buf));
447 if (ret < 0)
418 return ret; 448 return ret;
419 449
420 agc = (buf[0] << 6) | (buf[1] >> 2); 450 agc = (buf[0] << 6) | (buf[1] >> 2);
@@ -422,18 +452,19 @@ static int mt312_read_signal_strength(struct dvb_frontend* fe, u16 *signal_stren
422 452
423 *signal_strength = agc; 453 *signal_strength = agc;
424 454
425 dprintk(KERN_DEBUG "agc=%08x err_db=%hd\n", agc, err_db); 455 dprintk("agc=%08x err_db=%hd\n", agc, err_db);
426 456
427 return 0; 457 return 0;
428} 458}
429 459
430static int mt312_read_snr(struct dvb_frontend* fe, u16 *snr) 460static int mt312_read_snr(struct dvb_frontend *fe, u16 *snr)
431{ 461{
432 struct mt312_state *state = fe->demodulator_priv; 462 struct mt312_state *state = fe->demodulator_priv;
433 int ret; 463 int ret;
434 u8 buf[2]; 464 u8 buf[2];
435 465
436 if ((ret = mt312_read(state, M_SNR_H, &buf, sizeof(buf))) < 0) 466 ret = mt312_read(state, M_SNR_H, &buf, sizeof(buf));
467 if (ret < 0)
437 return ret; 468 return ret;
438 469
439 *snr = 0xFFFF - ((((buf[0] & 0x7f) << 8) | buf[1]) << 1); 470 *snr = 0xFFFF - ((((buf[0] & 0x7f) << 8) | buf[1]) << 1);
@@ -441,13 +472,14 @@ static int mt312_read_snr(struct dvb_frontend* fe, u16 *snr)
441 return 0; 472 return 0;
442} 473}
443 474
444static int mt312_read_ucblocks(struct dvb_frontend* fe, u32 *ubc) 475static int mt312_read_ucblocks(struct dvb_frontend *fe, u32 *ubc)
445{ 476{
446 struct mt312_state *state = fe->demodulator_priv; 477 struct mt312_state *state = fe->demodulator_priv;
447 int ret; 478 int ret;
448 u8 buf[2]; 479 u8 buf[2];
449 480
450 if ((ret = mt312_read(state, RS_UBC_H, &buf, sizeof(buf))) < 0) 481 ret = mt312_read(state, RS_UBC_H, &buf, sizeof(buf));
482 if (ret < 0)
451 return ret; 483 return ret;
452 484
453 *ubc = (buf[0] << 8) | buf[1]; 485 *ubc = (buf[0] << 8) | buf[1];
@@ -455,7 +487,7 @@ static int mt312_read_ucblocks(struct dvb_frontend* fe, u32 *ubc)
455 return 0; 487 return 0;
456} 488}
457 489
458static int mt312_set_frontend(struct dvb_frontend* fe, 490static int mt312_set_frontend(struct dvb_frontend *fe,
459 struct dvb_frontend_parameters *p) 491 struct dvb_frontend_parameters *p)
460{ 492{
461 struct mt312_state *state = fe->demodulator_priv; 493 struct mt312_state *state = fe->demodulator_priv;
@@ -491,24 +523,28 @@ static int mt312_set_frontend(struct dvb_frontend* fe,
491 523
492 switch (state->id) { 524 switch (state->id) {
493 case ID_VP310: 525 case ID_VP310:
494 // For now we will do this only for the VP310. 526 /* For now we will do this only for the VP310.
495 // It should be better for the mt312 as well, but tunning will be slower. ACCJr 09/29/03 527 * It should be better for the mt312 as well,
528 * but tuning will be slower. ACCJr 09/29/03
529 */
496 ret = mt312_readreg(state, CONFIG, &config_val); 530 ret = mt312_readreg(state, CONFIG, &config_val);
497 if (ret < 0) 531 if (ret < 0)
498 return ret; 532 return ret;
499 if (p->u.qpsk.symbol_rate >= 30000000) //Note that 30MS/s should use 90MHz 533 if (p->u.qpsk.symbol_rate >= 30000000) {
500 { 534 /* Note that 30MS/s should use 90MHz */
501 if ((config_val & 0x0c) == 0x08) { //We are running 60MHz 535 if ((config_val & 0x0c) == 0x08) {
536 /* We are running 60MHz */
502 state->frequency = 90; 537 state->frequency = 90;
503 if ((ret = mt312_initfe(fe)) < 0) 538 ret = mt312_initfe(fe);
539 if (ret < 0)
504 return ret; 540 return ret;
505 } 541 }
506 } 542 } else {
507 else 543 if ((config_val & 0x0c) == 0x0C) {
508 { 544 /* We are running 90MHz */
509 if ((config_val & 0x0c) == 0x0C) { //We are running 90MHz
510 state->frequency = 60; 545 state->frequency = 60;
511 if ((ret = mt312_initfe(fe)) < 0) 546 ret = mt312_initfe(fe);
547 if (ret < 0)
512 return ret; 548 return ret;
513 } 549 }
514 } 550 }
@@ -523,7 +559,8 @@ static int mt312_set_frontend(struct dvb_frontend* fe,
523 559
524 if (fe->ops.tuner_ops.set_params) { 560 if (fe->ops.tuner_ops.set_params) {
525 fe->ops.tuner_ops.set_params(fe, p); 561 fe->ops.tuner_ops.set_params(fe, p);
526 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); 562 if (fe->ops.i2c_gate_ctrl)
563 fe->ops.i2c_gate_ctrl(fe, 0);
527 } 564 }
528 565
529 /* sr = (u16)(sr * 256.0 / 1000000.0) */ 566 /* sr = (u16)(sr * 256.0 / 1000000.0) */
@@ -545,7 +582,8 @@ static int mt312_set_frontend(struct dvb_frontend* fe,
545 /* GO */ 582 /* GO */
546 buf[4] = 0x01; 583 buf[4] = 0x01;
547 584
548 if ((ret = mt312_write(state, SYM_RATE_H, buf, sizeof(buf))) < 0) 585 ret = mt312_write(state, SYM_RATE_H, buf, sizeof(buf));
586 if (ret < 0)
549 return ret; 587 return ret;
550 588
551 mt312_reset(state, 0); 589 mt312_reset(state, 0);
@@ -553,27 +591,30 @@ static int mt312_set_frontend(struct dvb_frontend* fe,
553 return 0; 591 return 0;
554} 592}
555 593
556static int mt312_get_frontend(struct dvb_frontend* fe, 594static int mt312_get_frontend(struct dvb_frontend *fe,
557 struct dvb_frontend_parameters *p) 595 struct dvb_frontend_parameters *p)
558{ 596{
559 struct mt312_state *state = fe->demodulator_priv; 597 struct mt312_state *state = fe->demodulator_priv;
560 int ret; 598 int ret;
561 599
562 if ((ret = mt312_get_inversion(state, &p->inversion)) < 0) 600 ret = mt312_get_inversion(state, &p->inversion);
601 if (ret < 0)
563 return ret; 602 return ret;
564 603
565 if ((ret = mt312_get_symbol_rate(state, &p->u.qpsk.symbol_rate)) < 0) 604 ret = mt312_get_symbol_rate(state, &p->u.qpsk.symbol_rate);
605 if (ret < 0)
566 return ret; 606 return ret;
567 607
568 if ((ret = mt312_get_code_rate(state, &p->u.qpsk.fec_inner)) < 0) 608 ret = mt312_get_code_rate(state, &p->u.qpsk.fec_inner);
609 if (ret < 0)
569 return ret; 610 return ret;
570 611
571 return 0; 612 return 0;
572} 613}
573 614
574static int mt312_i2c_gate_ctrl(struct dvb_frontend* fe, int enable) 615static int mt312_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
575{ 616{
576 struct mt312_state* state = fe->demodulator_priv; 617 struct mt312_state *state = fe->demodulator_priv;
577 618
578 if (enable) { 619 if (enable) {
579 return mt312_writereg(state, GPP_CTRL, 0x40); 620 return mt312_writereg(state, GPP_CTRL, 0x40);
@@ -582,27 +623,31 @@ static int mt312_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
582 } 623 }
583} 624}
584 625
585static int mt312_sleep(struct dvb_frontend* fe) 626static int mt312_sleep(struct dvb_frontend *fe)
586{ 627{
587 struct mt312_state *state = fe->demodulator_priv; 628 struct mt312_state *state = fe->demodulator_priv;
588 int ret; 629 int ret;
589 u8 config; 630 u8 config;
590 631
591 /* reset all registers to defaults */ 632 /* reset all registers to defaults */
592 if ((ret = mt312_reset(state, 1)) < 0) 633 ret = mt312_reset(state, 1);
634 if (ret < 0)
593 return ret; 635 return ret;
594 636
595 if ((ret = mt312_readreg(state, CONFIG, &config)) < 0) 637 ret = mt312_readreg(state, CONFIG, &config);
638 if (ret < 0)
596 return ret; 639 return ret;
597 640
598 /* enter standby */ 641 /* enter standby */
599 if ((ret = mt312_writereg(state, CONFIG, config & 0x7f)) < 0) 642 ret = mt312_writereg(state, CONFIG, config & 0x7f);
643 if (ret < 0)
600 return ret; 644 return ret;
601 645
602 return 0; 646 return 0;
603} 647}
604 648
605static int mt312_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) 649static int mt312_get_tune_settings(struct dvb_frontend *fe,
650 struct dvb_frontend_tune_settings *fesettings)
606{ 651{
607 fesettings->min_delay_ms = 50; 652 fesettings->min_delay_ms = 50;
608 fesettings->step_size = 0; 653 fesettings->step_size = 0;
@@ -610,9 +655,9 @@ static int mt312_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_
610 return 0; 655 return 0;
611} 656}
612 657
613static void mt312_release(struct dvb_frontend* fe) 658static void mt312_release(struct dvb_frontend *fe)
614{ 659{
615 struct mt312_state* state = fe->demodulator_priv; 660 struct mt312_state *state = fe->demodulator_priv;
616 kfree(state); 661 kfree(state);
617} 662}
618 663
@@ -655,10 +700,10 @@ static struct dvb_frontend_ops vp310_mt312_ops = {
655 .set_voltage = mt312_set_voltage, 700 .set_voltage = mt312_set_voltage,
656}; 701};
657 702
658struct dvb_frontend* vp310_mt312_attach(const struct mt312_config* config, 703struct dvb_frontend *vp310_mt312_attach(const struct mt312_config *config,
659 struct i2c_adapter* i2c) 704 struct i2c_adapter *i2c)
660{ 705{
661 struct mt312_state* state = NULL; 706 struct mt312_state *state = NULL;
662 707
663 /* allocate memory for the internal state */ 708 /* allocate memory for the internal state */
664 state = kmalloc(sizeof(struct mt312_state), GFP_KERNEL); 709 state = kmalloc(sizeof(struct mt312_state), GFP_KERNEL);
@@ -674,7 +719,8 @@ struct dvb_frontend* vp310_mt312_attach(const struct mt312_config* config,
674 goto error; 719 goto error;
675 720
676 /* create dvb_frontend */ 721 /* create dvb_frontend */
677 memcpy(&state->frontend.ops, &vp310_mt312_ops, sizeof(struct dvb_frontend_ops)); 722 memcpy(&state->frontend.ops, &vp310_mt312_ops,
723 sizeof(struct dvb_frontend_ops));
678 state->frontend.demodulator_priv = state; 724 state->frontend.demodulator_priv = state;
679 725
680 switch (state->id) { 726 switch (state->id) {
@@ -687,7 +733,8 @@ struct dvb_frontend* vp310_mt312_attach(const struct mt312_config* config,
687 state->frequency = 60; 733 state->frequency = 60;
688 break; 734 break;
689 default: 735 default:
690 printk (KERN_WARNING "Only Zarlink VP310/MT312 are supported chips.\n"); 736 printk(KERN_WARNING "Only Zarlink VP310/MT312"
737 " are supported chips.\n");
691 goto error; 738 goto error;
692 } 739 }
693 740
@@ -697,6 +744,7 @@ error:
697 kfree(state); 744 kfree(state);
698 return NULL; 745 return NULL;
699} 746}
747EXPORT_SYMBOL(vp310_mt312_attach);
700 748
701module_param(debug, int, 0644); 749module_param(debug, int, 0644);
702MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); 750MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
@@ -705,4 +753,3 @@ MODULE_DESCRIPTION("Zarlink VP310/MT312 DVB-S Demodulator driver");
705MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>"); 753MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>");
706MODULE_LICENSE("GPL"); 754MODULE_LICENSE("GPL");
707 755
708EXPORT_SYMBOL(vp310_mt312_attach);
diff --git a/drivers/media/dvb/frontends/mt312.h b/drivers/media/dvb/frontends/mt312.h
index cf9a1505ad4b..f17cb93ba9ba 100644
--- a/drivers/media/dvb/frontends/mt312.h
+++ b/drivers/media/dvb/frontends/mt312.h
@@ -28,22 +28,21 @@
28 28
29#include <linux/dvb/frontend.h> 29#include <linux/dvb/frontend.h>
30 30
31struct mt312_config 31struct mt312_config {
32{
33 /* the demodulator's i2c address */ 32 /* the demodulator's i2c address */
34 u8 demod_address; 33 u8 demod_address;
35}; 34};
36 35
37#if defined(CONFIG_DVB_MT312) || (defined(CONFIG_DVB_MT312_MODULE) && defined(MODULE)) 36#if defined(CONFIG_DVB_MT312) || (defined(CONFIG_DVB_MT312_MODULE) && defined(MODULE))
38struct dvb_frontend* vp310_mt312_attach(const struct mt312_config* config, 37struct dvb_frontend *vp310_mt312_attach(const struct mt312_config *config,
39 struct i2c_adapter* i2c); 38 struct i2c_adapter *i2c);
40#else 39#else
41static inline struct dvb_frontend* vp310_mt312_attach(const struct mt312_config* config, 40static inline struct dvb_frontend *vp310_mt312_attach(
42 struct i2c_adapter* i2c) 41 const struct mt312_config *config, struct i2c_adapter *i2c)
43{ 42{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 43 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
45 return NULL; 44 return NULL;
46} 45}
47#endif // CONFIG_DVB_MT312 46#endif /* CONFIG_DVB_MT312 */
48 47
49#endif // MT312_H 48#endif /* MT312_H */
diff --git a/drivers/media/dvb/frontends/mt352.c b/drivers/media/dvb/frontends/mt352.c
index 5dd9b731f6f2..7cd190b6f015 100644
--- a/drivers/media/dvb/frontends/mt352.c
+++ b/drivers/media/dvb/frontends/mt352.c
@@ -152,7 +152,13 @@ static void mt352_calc_input_freq(struct mt352_state* state,
152 if (state->config.if2) 152 if (state->config.if2)
153 if2 = state->config.if2; 153 if2 = state->config.if2;
154 154
155 ife = (2*adc_clock - if2); 155 if (adc_clock >= if2 * 2)
156 ife = if2;
157 else {
158 ife = adc_clock - (if2 % adc_clock);
159 if (ife > adc_clock / 2)
160 ife = adc_clock - ife;
161 }
156 value = -16374 * ife / adc_clock; 162 value = -16374 * ife / adc_clock;
157 dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n", 163 dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
158 __FUNCTION__, if2, ife, adc_clock, value, value & 0x3fff); 164 __FUNCTION__, if2, ife, adc_clock, value, value & 0x3fff);
diff --git a/drivers/media/dvb/frontends/or51132.c b/drivers/media/dvb/frontends/or51132.c
index b314a1f2deed..1d2d28ce823d 100644
--- a/drivers/media/dvb/frontends/or51132.c
+++ b/drivers/media/dvb/frontends/or51132.c
@@ -564,7 +564,7 @@ struct dvb_frontend* or51132_attach(const struct or51132_config* config,
564 /* Allocate memory for the internal state */ 564 /* Allocate memory for the internal state */
565 state = kmalloc(sizeof(struct or51132_state), GFP_KERNEL); 565 state = kmalloc(sizeof(struct or51132_state), GFP_KERNEL);
566 if (state == NULL) 566 if (state == NULL)
567 goto error; 567 return NULL;
568 568
569 /* Setup the state */ 569 /* Setup the state */
570 state->config = config; 570 state->config = config;
@@ -576,10 +576,6 @@ struct dvb_frontend* or51132_attach(const struct or51132_config* config,
576 memcpy(&state->frontend.ops, &or51132_ops, sizeof(struct dvb_frontend_ops)); 576 memcpy(&state->frontend.ops, &or51132_ops, sizeof(struct dvb_frontend_ops));
577 state->frontend.demodulator_priv = state; 577 state->frontend.demodulator_priv = state;
578 return &state->frontend; 578 return &state->frontend;
579
580error:
581 kfree(state);
582 return NULL;
583} 579}
584 580
585static struct dvb_frontend_ops or51132_ops = { 581static struct dvb_frontend_ops or51132_ops = {
diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
index f02bd9445955..6a6b0d727c6f 100644
--- a/drivers/media/dvb/frontends/or51211.c
+++ b/drivers/media/dvb/frontends/or51211.c
@@ -529,7 +529,7 @@ struct dvb_frontend* or51211_attach(const struct or51211_config* config,
529 /* Allocate memory for the internal state */ 529 /* Allocate memory for the internal state */
530 state = kmalloc(sizeof(struct or51211_state), GFP_KERNEL); 530 state = kmalloc(sizeof(struct or51211_state), GFP_KERNEL);
531 if (state == NULL) 531 if (state == NULL)
532 goto error; 532 return NULL;
533 533
534 /* Setup the state */ 534 /* Setup the state */
535 state->config = config; 535 state->config = config;
@@ -541,10 +541,6 @@ struct dvb_frontend* or51211_attach(const struct or51211_config* config,
541 memcpy(&state->frontend.ops, &or51211_ops, sizeof(struct dvb_frontend_ops)); 541 memcpy(&state->frontend.ops, &or51211_ops, sizeof(struct dvb_frontend_ops));
542 state->frontend.demodulator_priv = state; 542 state->frontend.demodulator_priv = state;
543 return &state->frontend; 543 return &state->frontend;
544
545error:
546 kfree(state);
547 return NULL;
548} 544}
549 545
550static struct dvb_frontend_ops or51211_ops = { 546static struct dvb_frontend_ops or51211_ops = {
diff --git a/drivers/media/dvb/frontends/s5h1409.c b/drivers/media/dvb/frontends/s5h1409.c
index 562d9208857a..819433485d3b 100644
--- a/drivers/media/dvb/frontends/s5h1409.c
+++ b/drivers/media/dvb/frontends/s5h1409.c
@@ -42,6 +42,7 @@ struct s5h1409_state {
42 fe_modulation_t current_modulation; 42 fe_modulation_t current_modulation;
43 43
44 u32 current_frequency; 44 u32 current_frequency;
45 int if_freq;
45 46
46 u32 is_qam_locked; 47 u32 is_qam_locked;
47 u32 qam_state; 48 u32 qam_state;
@@ -97,7 +98,7 @@ static struct init_tab {
97 { 0xac, 0x1003, }, 98 { 0xac, 0x1003, },
98 { 0xad, 0x103f, }, 99 { 0xad, 0x103f, },
99 { 0xe2, 0x0100, }, 100 { 0xe2, 0x0100, },
100 { 0xe3, 0x0000, }, 101 { 0xe3, 0x1000, },
101 { 0x28, 0x1010, }, 102 { 0x28, 0x1010, },
102 { 0xb1, 0x000e, }, 103 { 0xb1, 0x000e, },
103}; 104};
@@ -348,28 +349,32 @@ static int s5h1409_softreset(struct dvb_frontend* fe)
348 return 0; 349 return 0;
349} 350}
350 351
352#define S5H1409_VSB_IF_FREQ 5380
353#define S5H1409_QAM_IF_FREQ state->config->qam_if
354
351static int s5h1409_set_if_freq(struct dvb_frontend* fe, int KHz) 355static int s5h1409_set_if_freq(struct dvb_frontend* fe, int KHz)
352{ 356{
353 struct s5h1409_state* state = fe->demodulator_priv; 357 struct s5h1409_state* state = fe->demodulator_priv;
354 int ret = 0;
355 358
356 dprintk("%s(%d KHz)\n", __FUNCTION__, KHz); 359 dprintk("%s(%d KHz)\n", __FUNCTION__, KHz);
357 360
358 if( (KHz == 44000) || (KHz == 5380) ) { 361 switch (KHz) {
359 s5h1409_writereg(state, 0x87, 0x01be); 362 case 4000:
360 s5h1409_writereg(state, 0x88, 0x0436);
361 s5h1409_writereg(state, 0x89, 0x054d);
362 } else
363 if (KHz == 4000) {
364 s5h1409_writereg(state, 0x87, 0x014b); 363 s5h1409_writereg(state, 0x87, 0x014b);
365 s5h1409_writereg(state, 0x88, 0x0cb5); 364 s5h1409_writereg(state, 0x88, 0x0cb5);
366 s5h1409_writereg(state, 0x89, 0x03e2); 365 s5h1409_writereg(state, 0x89, 0x03e2);
367 } else { 366 break;
368 printk("%s() Invalid arg = %d KHz\n", __FUNCTION__, KHz); 367 case 5380:
369 ret = -1; 368 case 44000:
369 default:
370 s5h1409_writereg(state, 0x87, 0x01be);
371 s5h1409_writereg(state, 0x88, 0x0436);
372 s5h1409_writereg(state, 0x89, 0x054d);
373 break;
370 } 374 }
375 state->if_freq = KHz;
371 376
372 return ret; 377 return 0;
373} 378}
374 379
375static int s5h1409_set_spectralinversion(struct dvb_frontend* fe, int inverted) 380static int s5h1409_set_spectralinversion(struct dvb_frontend* fe, int inverted)
@@ -394,11 +399,15 @@ static int s5h1409_enable_modulation(struct dvb_frontend* fe,
394 switch(m) { 399 switch(m) {
395 case VSB_8: 400 case VSB_8:
396 dprintk("%s() VSB_8\n", __FUNCTION__); 401 dprintk("%s() VSB_8\n", __FUNCTION__);
402 if (state->if_freq != S5H1409_VSB_IF_FREQ)
403 s5h1409_set_if_freq(fe, S5H1409_VSB_IF_FREQ);
397 s5h1409_writereg(state, 0xf4, 0); 404 s5h1409_writereg(state, 0xf4, 0);
398 break; 405 break;
399 case QAM_64: 406 case QAM_64:
400 case QAM_256: 407 case QAM_256:
401 dprintk("%s() QAM_AUTO (64/256)\n", __FUNCTION__); 408 dprintk("%s() QAM_AUTO (64/256)\n", __FUNCTION__);
409 if (state->if_freq != S5H1409_QAM_IF_FREQ)
410 s5h1409_set_if_freq(fe, S5H1409_QAM_IF_FREQ);
402 s5h1409_writereg(state, 0xf4, 1); 411 s5h1409_writereg(state, 0xf4, 1);
403 s5h1409_writereg(state, 0x85, 0x110); 412 s5h1409_writereg(state, 0x85, 0x110);
404 break; 413 break;
@@ -432,9 +441,11 @@ static int s5h1409_set_gpio(struct dvb_frontend* fe, int enable)
432 dprintk("%s(%d)\n", __FUNCTION__, enable); 441 dprintk("%s(%d)\n", __FUNCTION__, enable);
433 442
434 if (enable) 443 if (enable)
435 return s5h1409_writereg(state, 0xe3, 0x1100); 444 return s5h1409_writereg(state, 0xe3,
445 s5h1409_readreg(state, 0xe3) | 0x1100);
436 else 446 else
437 return s5h1409_writereg(state, 0xe3, 0x1000); 447 return s5h1409_writereg(state, 0xe3,
448 s5h1409_readreg(state, 0xe3) & 0xeeff);
438} 449}
439 450
440static int s5h1409_sleep(struct dvb_frontend* fe, int enable) 451static int s5h1409_sleep(struct dvb_frontend* fe, int enable)
@@ -504,13 +515,15 @@ static void s5h1409_set_qam_interleave_mode(struct dvb_frontend *fe)
504 s5h1409_writereg(state, 0x96, 0x20); 515 s5h1409_writereg(state, 0x96, 0x20);
505 s5h1409_writereg(state, 0xad, 516 s5h1409_writereg(state, 0xad,
506 ( ((reg1 & 0xf000) >> 4) | (reg2 & 0xf0ff)) ); 517 ( ((reg1 & 0xf000) >> 4) | (reg2 & 0xf0ff)) );
507 s5h1409_writereg(state, 0xab, 0x1100); 518 s5h1409_writereg(state, 0xab,
519 s5h1409_readreg(state, 0xab) & 0xeffe);
508 } 520 }
509 } else { 521 } else {
510 if (state->qam_state != 1) { 522 if (state->qam_state != 1) {
511 state->qam_state = 1; 523 state->qam_state = 1;
512 s5h1409_writereg(state, 0x96, 0x08); 524 s5h1409_writereg(state, 0x96, 0x08);
513 s5h1409_writereg(state, 0xab, 0x1101); 525 s5h1409_writereg(state, 0xab,
526 s5h1409_readreg(state, 0xab) | 0x1001);
514 } 527 }
515 } 528 }
516} 529}
@@ -547,6 +560,36 @@ static int s5h1409_set_frontend (struct dvb_frontend* fe,
547 return 0; 560 return 0;
548} 561}
549 562
563static int s5h1409_set_mpeg_timing(struct dvb_frontend *fe, int mode)
564{
565 struct s5h1409_state *state = fe->demodulator_priv;
566 u16 val;
567
568 dprintk("%s(%d)\n", __FUNCTION__, mode);
569
570 val = s5h1409_readreg(state, 0xac) & 0xcfff;
571 switch (mode) {
572 case S5H1409_MPEGTIMING_CONTINOUS_INVERTING_CLOCK:
573 val |= 0x0000;
574 break;
575 case S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK:
576 dprintk("%s(%d) Mode1 or Defaulting\n", __FUNCTION__, mode);
577 val |= 0x1000;
578 break;
579 case S5H1409_MPEGTIMING_NONCONTINOUS_INVERTING_CLOCK:
580 val |= 0x2000;
581 break;
582 case S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK:
583 val |= 0x3000;
584 break;
585 default:
586 return -EINVAL;
587 }
588
589 /* Configure MPEG Signal Timing charactistics */
590 return s5h1409_writereg(state, 0xac, val);
591}
592
550/* Reset the demod hardware and reset all of the configuration registers 593/* Reset the demod hardware and reset all of the configuration registers
551 to a default state. */ 594 to a default state. */
552static int s5h1409_init (struct dvb_frontend* fe) 595static int s5h1409_init (struct dvb_frontend* fe)
@@ -566,13 +609,16 @@ static int s5h1409_init (struct dvb_frontend* fe)
566 state->current_modulation = VSB_8; 609 state->current_modulation = VSB_8;
567 610
568 if (state->config->output_mode == S5H1409_SERIAL_OUTPUT) 611 if (state->config->output_mode == S5H1409_SERIAL_OUTPUT)
569 s5h1409_writereg(state, 0xab, 0x100); /* Serial */ 612 s5h1409_writereg(state, 0xab,
613 s5h1409_readreg(state, 0xab) | 0x100); /* Serial */
570 else 614 else
571 s5h1409_writereg(state, 0xab, 0x0); /* Parallel */ 615 s5h1409_writereg(state, 0xab,
616 s5h1409_readreg(state, 0xab) & 0xfeff); /* Parallel */
572 617
573 s5h1409_set_spectralinversion(fe, state->config->inversion); 618 s5h1409_set_spectralinversion(fe, state->config->inversion);
574 s5h1409_set_if_freq(fe, state->config->if_freq); 619 s5h1409_set_if_freq(fe, state->if_freq);
575 s5h1409_set_gpio(fe, state->config->gpio); 620 s5h1409_set_gpio(fe, state->config->gpio);
621 s5h1409_set_mpeg_timing(fe, state->config->mpeg_timing);
576 s5h1409_softreset(fe); 622 s5h1409_softreset(fe);
577 623
578 /* Note: Leaving the I2C gate closed. */ 624 /* Note: Leaving the I2C gate closed. */
@@ -741,6 +787,7 @@ struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config,
741 struct i2c_adapter* i2c) 787 struct i2c_adapter* i2c)
742{ 788{
743 struct s5h1409_state* state = NULL; 789 struct s5h1409_state* state = NULL;
790 u16 reg;
744 791
745 /* allocate memory for the internal state */ 792 /* allocate memory for the internal state */
746 state = kmalloc(sizeof(struct s5h1409_state), GFP_KERNEL); 793 state = kmalloc(sizeof(struct s5h1409_state), GFP_KERNEL);
@@ -751,9 +798,11 @@ struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config,
751 state->config = config; 798 state->config = config;
752 state->i2c = i2c; 799 state->i2c = i2c;
753 state->current_modulation = 0; 800 state->current_modulation = 0;
801 state->if_freq = S5H1409_VSB_IF_FREQ;
754 802
755 /* check if the demod exists */ 803 /* check if the demod exists */
756 if (s5h1409_readreg(state, 0x04) != 0x0066) 804 reg = s5h1409_readreg(state, 0x04);
805 if ((reg != 0x0066) && (reg != 0x007f))
757 goto error; 806 goto error;
758 807
759 /* create dvb_frontend */ 808 /* create dvb_frontend */
@@ -761,8 +810,14 @@ struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config,
761 sizeof(struct dvb_frontend_ops)); 810 sizeof(struct dvb_frontend_ops));
762 state->frontend.demodulator_priv = state; 811 state->frontend.demodulator_priv = state;
763 812
813 if (s5h1409_init(&state->frontend) != 0) {
814 printk(KERN_ERR "%s: Failed to initialize correctly\n",
815 __FUNCTION__);
816 goto error;
817 }
818
764 /* Note: Leaving the I2C gate open here. */ 819 /* Note: Leaving the I2C gate open here. */
765 s5h1409_writereg(state, 0xf3, 1); 820 s5h1409_i2c_gate_ctrl(&state->frontend, 1);
766 821
767 return &state->frontend; 822 return &state->frontend;
768 823
diff --git a/drivers/media/dvb/frontends/s5h1409.h b/drivers/media/dvb/frontends/s5h1409.h
index 20f9af1af445..f0bb13fe808b 100644
--- a/drivers/media/dvb/frontends/s5h1409.h
+++ b/drivers/media/dvb/frontends/s5h1409.h
@@ -39,8 +39,8 @@ struct s5h1409_config
39#define S5H1409_GPIO_ON 1 39#define S5H1409_GPIO_ON 1
40 u8 gpio; 40 u8 gpio;
41 41
42 /* IF Freq in KHz */ 42 /* IF Freq for QAM in KHz, VSB is hardcoded to 5380 */
43 u16 if_freq; 43 u16 qam_if;
44 44
45 /* Spectral Inversion */ 45 /* Spectral Inversion */
46#define S5H1409_INVERSION_OFF 0 46#define S5H1409_INVERSION_OFF 0
@@ -51,6 +51,13 @@ struct s5h1409_config
51#define S5H1409_TUNERLOCKING 0 51#define S5H1409_TUNERLOCKING 0
52#define S5H1409_DEMODLOCKING 1 52#define S5H1409_DEMODLOCKING 1
53 u8 status_mode; 53 u8 status_mode;
54
55 /* MPEG signal timing */
56#define S5H1409_MPEGTIMING_CONTINOUS_INVERTING_CLOCK 0
57#define S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK 1
58#define S5H1409_MPEGTIMING_NONCONTINOUS_INVERTING_CLOCK 2
59#define S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK 3
60 u16 mpeg_timing;
54}; 61};
55 62
56#if defined(CONFIG_DVB_S5H1409) || (defined(CONFIG_DVB_S5H1409_MODULE) && defined(MODULE)) 63#if defined(CONFIG_DVB_S5H1409) || (defined(CONFIG_DVB_S5H1409_MODULE) && defined(MODULE))
diff --git a/drivers/media/dvb/frontends/tda18271-common.c b/drivers/media/dvb/frontends/tda18271-common.c
new file mode 100644
index 000000000000..cebb6b90b7e0
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda18271-common.c
@@ -0,0 +1,653 @@
1/*
2 tda18271-common.c - driver for the Philips / NXP TDA18271 silicon tuner
3
4 Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include "tda18271-priv.h"
22
23static int tda18271_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
24{
25 struct tda18271_priv *priv = fe->tuner_priv;
26 enum tda18271_i2c_gate gate;
27 int ret = 0;
28
29 switch (priv->gate) {
30 case TDA18271_GATE_DIGITAL:
31 case TDA18271_GATE_ANALOG:
32 gate = priv->gate;
33 break;
34 case TDA18271_GATE_AUTO:
35 default:
36 switch (priv->mode) {
37 case TDA18271_DIGITAL:
38 gate = TDA18271_GATE_DIGITAL;
39 break;
40 case TDA18271_ANALOG:
41 default:
42 gate = TDA18271_GATE_ANALOG;
43 break;
44 }
45 }
46
47 switch (gate) {
48 case TDA18271_GATE_ANALOG:
49 if (fe->ops.analog_ops.i2c_gate_ctrl)
50 ret = fe->ops.analog_ops.i2c_gate_ctrl(fe, enable);
51 break;
52 case TDA18271_GATE_DIGITAL:
53 if (fe->ops.i2c_gate_ctrl)
54 ret = fe->ops.i2c_gate_ctrl(fe, enable);
55 break;
56 default:
57 ret = -EINVAL;
58 break;
59 }
60
61 return ret;
62};
63
64/*---------------------------------------------------------------------*/
65
66static void tda18271_dump_regs(struct dvb_frontend *fe, int extended)
67{
68 struct tda18271_priv *priv = fe->tuner_priv;
69 unsigned char *regs = priv->tda18271_regs;
70
71 tda_reg("=== TDA18271 REG DUMP ===\n");
72 tda_reg("ID_BYTE = 0x%02x\n", 0xff & regs[R_ID]);
73 tda_reg("THERMO_BYTE = 0x%02x\n", 0xff & regs[R_TM]);
74 tda_reg("POWER_LEVEL_BYTE = 0x%02x\n", 0xff & regs[R_PL]);
75 tda_reg("EASY_PROG_BYTE_1 = 0x%02x\n", 0xff & regs[R_EP1]);
76 tda_reg("EASY_PROG_BYTE_2 = 0x%02x\n", 0xff & regs[R_EP2]);
77 tda_reg("EASY_PROG_BYTE_3 = 0x%02x\n", 0xff & regs[R_EP3]);
78 tda_reg("EASY_PROG_BYTE_4 = 0x%02x\n", 0xff & regs[R_EP4]);
79 tda_reg("EASY_PROG_BYTE_5 = 0x%02x\n", 0xff & regs[R_EP5]);
80 tda_reg("CAL_POST_DIV_BYTE = 0x%02x\n", 0xff & regs[R_CPD]);
81 tda_reg("CAL_DIV_BYTE_1 = 0x%02x\n", 0xff & regs[R_CD1]);
82 tda_reg("CAL_DIV_BYTE_2 = 0x%02x\n", 0xff & regs[R_CD2]);
83 tda_reg("CAL_DIV_BYTE_3 = 0x%02x\n", 0xff & regs[R_CD3]);
84 tda_reg("MAIN_POST_DIV_BYTE = 0x%02x\n", 0xff & regs[R_MPD]);
85 tda_reg("MAIN_DIV_BYTE_1 = 0x%02x\n", 0xff & regs[R_MD1]);
86 tda_reg("MAIN_DIV_BYTE_2 = 0x%02x\n", 0xff & regs[R_MD2]);
87 tda_reg("MAIN_DIV_BYTE_3 = 0x%02x\n", 0xff & regs[R_MD3]);
88
89 /* only dump extended regs if DBG_ADV is set */
90 if (!(tda18271_debug & DBG_ADV))
91 return;
92
93 /* W indicates write-only registers.
94 * Register dump for write-only registers shows last value written. */
95
96 tda_reg("EXTENDED_BYTE_1 = 0x%02x\n", 0xff & regs[R_EB1]);
97 tda_reg("EXTENDED_BYTE_2 = 0x%02x\n", 0xff & regs[R_EB2]);
98 tda_reg("EXTENDED_BYTE_3 = 0x%02x\n", 0xff & regs[R_EB3]);
99 tda_reg("EXTENDED_BYTE_4 = 0x%02x\n", 0xff & regs[R_EB4]);
100 tda_reg("EXTENDED_BYTE_5 = 0x%02x\n", 0xff & regs[R_EB5]);
101 tda_reg("EXTENDED_BYTE_6 = 0x%02x\n", 0xff & regs[R_EB6]);
102 tda_reg("EXTENDED_BYTE_7 = 0x%02x\n", 0xff & regs[R_EB7]);
103 tda_reg("EXTENDED_BYTE_8 = 0x%02x\n", 0xff & regs[R_EB8]);
104 tda_reg("EXTENDED_BYTE_9 W = 0x%02x\n", 0xff & regs[R_EB9]);
105 tda_reg("EXTENDED_BYTE_10 = 0x%02x\n", 0xff & regs[R_EB10]);
106 tda_reg("EXTENDED_BYTE_11 = 0x%02x\n", 0xff & regs[R_EB11]);
107 tda_reg("EXTENDED_BYTE_12 = 0x%02x\n", 0xff & regs[R_EB12]);
108 tda_reg("EXTENDED_BYTE_13 = 0x%02x\n", 0xff & regs[R_EB13]);
109 tda_reg("EXTENDED_BYTE_14 = 0x%02x\n", 0xff & regs[R_EB14]);
110 tda_reg("EXTENDED_BYTE_15 = 0x%02x\n", 0xff & regs[R_EB15]);
111 tda_reg("EXTENDED_BYTE_16 W = 0x%02x\n", 0xff & regs[R_EB16]);
112 tda_reg("EXTENDED_BYTE_17 W = 0x%02x\n", 0xff & regs[R_EB17]);
113 tda_reg("EXTENDED_BYTE_18 = 0x%02x\n", 0xff & regs[R_EB18]);
114 tda_reg("EXTENDED_BYTE_19 W = 0x%02x\n", 0xff & regs[R_EB19]);
115 tda_reg("EXTENDED_BYTE_20 W = 0x%02x\n", 0xff & regs[R_EB20]);
116 tda_reg("EXTENDED_BYTE_21 = 0x%02x\n", 0xff & regs[R_EB21]);
117 tda_reg("EXTENDED_BYTE_22 = 0x%02x\n", 0xff & regs[R_EB22]);
118 tda_reg("EXTENDED_BYTE_23 = 0x%02x\n", 0xff & regs[R_EB23]);
119}
120
121int tda18271_read_regs(struct dvb_frontend *fe)
122{
123 struct tda18271_priv *priv = fe->tuner_priv;
124 unsigned char *regs = priv->tda18271_regs;
125 unsigned char buf = 0x00;
126 int ret;
127 struct i2c_msg msg[] = {
128 { .addr = priv->i2c_addr, .flags = 0,
129 .buf = &buf, .len = 1 },
130 { .addr = priv->i2c_addr, .flags = I2C_M_RD,
131 .buf = regs, .len = 16 }
132 };
133
134 tda18271_i2c_gate_ctrl(fe, 1);
135
136 /* read all registers */
137 ret = i2c_transfer(priv->i2c_adap, msg, 2);
138
139 tda18271_i2c_gate_ctrl(fe, 0);
140
141 if (ret != 2)
142 tda_err("ERROR: i2c_transfer returned: %d\n", ret);
143
144 if (tda18271_debug & DBG_REG)
145 tda18271_dump_regs(fe, 0);
146
147 return (ret == 2 ? 0 : ret);
148}
149
150int tda18271_read_extended(struct dvb_frontend *fe)
151{
152 struct tda18271_priv *priv = fe->tuner_priv;
153 unsigned char *regs = priv->tda18271_regs;
154 unsigned char regdump[TDA18271_NUM_REGS];
155 unsigned char buf = 0x00;
156 int ret, i;
157 struct i2c_msg msg[] = {
158 { .addr = priv->i2c_addr, .flags = 0,
159 .buf = &buf, .len = 1 },
160 { .addr = priv->i2c_addr, .flags = I2C_M_RD,
161 .buf = regdump, .len = TDA18271_NUM_REGS }
162 };
163
164 tda18271_i2c_gate_ctrl(fe, 1);
165
166 /* read all registers */
167 ret = i2c_transfer(priv->i2c_adap, msg, 2);
168
169 tda18271_i2c_gate_ctrl(fe, 0);
170
171 if (ret != 2)
172 tda_err("ERROR: i2c_transfer returned: %d\n", ret);
173
174 for (i = 0; i <= TDA18271_NUM_REGS; i++) {
175 /* don't update write-only registers */
176 if ((i != R_EB9) &&
177 (i != R_EB16) &&
178 (i != R_EB17) &&
179 (i != R_EB19) &&
180 (i != R_EB20))
181 regs[i] = regdump[i];
182 }
183
184 if (tda18271_debug & DBG_REG)
185 tda18271_dump_regs(fe, 1);
186
187 return (ret == 2 ? 0 : ret);
188}
189
190int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len)
191{
192 struct tda18271_priv *priv = fe->tuner_priv;
193 unsigned char *regs = priv->tda18271_regs;
194 unsigned char buf[TDA18271_NUM_REGS + 1];
195 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
196 .buf = buf, .len = len + 1 };
197 int i, ret;
198
199 BUG_ON((len == 0) || (idx + len > sizeof(buf)));
200
201 buf[0] = idx;
202 for (i = 1; i <= len; i++)
203 buf[i] = regs[idx - 1 + i];
204
205 tda18271_i2c_gate_ctrl(fe, 1);
206
207 /* write registers */
208 ret = i2c_transfer(priv->i2c_adap, &msg, 1);
209
210 tda18271_i2c_gate_ctrl(fe, 0);
211
212 if (ret != 1)
213 tda_err("ERROR: i2c_transfer returned: %d\n", ret);
214
215 return (ret == 1 ? 0 : ret);
216}
217
218/*---------------------------------------------------------------------*/
219
220int tda18271_init_regs(struct dvb_frontend *fe)
221{
222 struct tda18271_priv *priv = fe->tuner_priv;
223 unsigned char *regs = priv->tda18271_regs;
224
225 tda_dbg("initializing registers for device @ %d-%04x\n",
226 i2c_adapter_id(priv->i2c_adap), priv->i2c_addr);
227
228 /* initialize registers */
229 switch (priv->id) {
230 case TDA18271HDC1:
231 regs[R_ID] = 0x83;
232 break;
233 case TDA18271HDC2:
234 regs[R_ID] = 0x84;
235 break;
236 };
237
238 regs[R_TM] = 0x08;
239 regs[R_PL] = 0x80;
240 regs[R_EP1] = 0xc6;
241 regs[R_EP2] = 0xdf;
242 regs[R_EP3] = 0x16;
243 regs[R_EP4] = 0x60;
244 regs[R_EP5] = 0x80;
245 regs[R_CPD] = 0x80;
246 regs[R_CD1] = 0x00;
247 regs[R_CD2] = 0x00;
248 regs[R_CD3] = 0x00;
249 regs[R_MPD] = 0x00;
250 regs[R_MD1] = 0x00;
251 regs[R_MD2] = 0x00;
252 regs[R_MD3] = 0x00;
253
254 switch (priv->id) {
255 case TDA18271HDC1:
256 regs[R_EB1] = 0xff;
257 break;
258 case TDA18271HDC2:
259 regs[R_EB1] = 0xfc;
260 break;
261 };
262
263 regs[R_EB2] = 0x01;
264 regs[R_EB3] = 0x84;
265 regs[R_EB4] = 0x41;
266 regs[R_EB5] = 0x01;
267 regs[R_EB6] = 0x84;
268 regs[R_EB7] = 0x40;
269 regs[R_EB8] = 0x07;
270 regs[R_EB9] = 0x00;
271 regs[R_EB10] = 0x00;
272 regs[R_EB11] = 0x96;
273
274 switch (priv->id) {
275 case TDA18271HDC1:
276 regs[R_EB12] = 0x0f;
277 break;
278 case TDA18271HDC2:
279 regs[R_EB12] = 0x33;
280 break;
281 };
282
283 regs[R_EB13] = 0xc1;
284 regs[R_EB14] = 0x00;
285 regs[R_EB15] = 0x8f;
286 regs[R_EB16] = 0x00;
287 regs[R_EB17] = 0x00;
288
289 switch (priv->id) {
290 case TDA18271HDC1:
291 regs[R_EB18] = 0x00;
292 break;
293 case TDA18271HDC2:
294 regs[R_EB18] = 0x8c;
295 break;
296 };
297
298 regs[R_EB19] = 0x00;
299 regs[R_EB20] = 0x20;
300
301 switch (priv->id) {
302 case TDA18271HDC1:
303 regs[R_EB21] = 0x33;
304 break;
305 case TDA18271HDC2:
306 regs[R_EB21] = 0xb3;
307 break;
308 };
309
310 regs[R_EB22] = 0x48;
311 regs[R_EB23] = 0xb0;
312
313 tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS);
314
315 /* setup agc1 gain */
316 regs[R_EB17] = 0x00;
317 tda18271_write_regs(fe, R_EB17, 1);
318 regs[R_EB17] = 0x03;
319 tda18271_write_regs(fe, R_EB17, 1);
320 regs[R_EB17] = 0x43;
321 tda18271_write_regs(fe, R_EB17, 1);
322 regs[R_EB17] = 0x4c;
323 tda18271_write_regs(fe, R_EB17, 1);
324
325 /* setup agc2 gain */
326 if ((priv->id) == TDA18271HDC1) {
327 regs[R_EB20] = 0xa0;
328 tda18271_write_regs(fe, R_EB20, 1);
329 regs[R_EB20] = 0xa7;
330 tda18271_write_regs(fe, R_EB20, 1);
331 regs[R_EB20] = 0xe7;
332 tda18271_write_regs(fe, R_EB20, 1);
333 regs[R_EB20] = 0xec;
334 tda18271_write_regs(fe, R_EB20, 1);
335 }
336
337 /* image rejection calibration */
338
339 /* low-band */
340 regs[R_EP3] = 0x1f;
341 regs[R_EP4] = 0x66;
342 regs[R_EP5] = 0x81;
343 regs[R_CPD] = 0xcc;
344 regs[R_CD1] = 0x6c;
345 regs[R_CD2] = 0x00;
346 regs[R_CD3] = 0x00;
347 regs[R_MPD] = 0xcd;
348 regs[R_MD1] = 0x77;
349 regs[R_MD2] = 0x08;
350 regs[R_MD3] = 0x00;
351
352 switch (priv->id) {
353 case TDA18271HDC1:
354 tda18271_write_regs(fe, R_EP3, 11);
355 break;
356 case TDA18271HDC2:
357 tda18271_write_regs(fe, R_EP3, 12);
358 break;
359 };
360
361 if ((priv->id) == TDA18271HDC2) {
362 /* main pll cp source on */
363 regs[R_EB4] = 0x61;
364 tda18271_write_regs(fe, R_EB4, 1);
365 msleep(1);
366
367 /* main pll cp source off */
368 regs[R_EB4] = 0x41;
369 tda18271_write_regs(fe, R_EB4, 1);
370 }
371
372 msleep(5); /* pll locking */
373
374 /* launch detector */
375 tda18271_write_regs(fe, R_EP1, 1);
376 msleep(5); /* wanted low measurement */
377
378 regs[R_EP5] = 0x85;
379 regs[R_CPD] = 0xcb;
380 regs[R_CD1] = 0x66;
381 regs[R_CD2] = 0x70;
382
383 tda18271_write_regs(fe, R_EP3, 7);
384 msleep(5); /* pll locking */
385
386 /* launch optimization algorithm */
387 tda18271_write_regs(fe, R_EP2, 1);
388 msleep(30); /* image low optimization completion */
389
390 /* mid-band */
391 regs[R_EP5] = 0x82;
392 regs[R_CPD] = 0xa8;
393 regs[R_CD2] = 0x00;
394 regs[R_MPD] = 0xa9;
395 regs[R_MD1] = 0x73;
396 regs[R_MD2] = 0x1a;
397
398 tda18271_write_regs(fe, R_EP3, 11);
399 msleep(5); /* pll locking */
400
401 tda18271_write_regs(fe, R_EP1, 1);
402 msleep(5); /* wanted mid measurement */
403
404 regs[R_EP5] = 0x86;
405 regs[R_CPD] = 0xa8;
406 regs[R_CD1] = 0x66;
407 regs[R_CD2] = 0xa0;
408
409 tda18271_write_regs(fe, R_EP3, 7);
410 msleep(5); /* pll locking */
411
412 /* launch optimization algorithm */
413 tda18271_write_regs(fe, R_EP2, 1);
414 msleep(30); /* image mid optimization completion */
415
416 /* high-band */
417 regs[R_EP5] = 0x83;
418 regs[R_CPD] = 0x98;
419 regs[R_CD1] = 0x65;
420 regs[R_CD2] = 0x00;
421 regs[R_MPD] = 0x99;
422 regs[R_MD1] = 0x71;
423 regs[R_MD2] = 0xcd;
424
425 tda18271_write_regs(fe, R_EP3, 11);
426 msleep(5); /* pll locking */
427
428 /* launch detector */
429 tda18271_write_regs(fe, R_EP1, 1);
430 msleep(5); /* wanted high measurement */
431
432 regs[R_EP5] = 0x87;
433 regs[R_CD1] = 0x65;
434 regs[R_CD2] = 0x50;
435
436 tda18271_write_regs(fe, R_EP3, 7);
437 msleep(5); /* pll locking */
438
439 /* launch optimization algorithm */
440 tda18271_write_regs(fe, R_EP2, 1);
441 msleep(30); /* image high optimization completion */
442
443 /* return to normal mode */
444 regs[R_EP4] = 0x64;
445 tda18271_write_regs(fe, R_EP4, 1);
446
447 /* synchronize */
448 tda18271_write_regs(fe, R_EP1, 1);
449
450 return 0;
451}
452
453/*---------------------------------------------------------------------*/
454
455/*
456 * Standby modes, EP3 [7:5]
457 *
458 * | SM || SM_LT || SM_XT || mode description
459 * |=====\\=======\\=======\\===================================
460 * | 0 || 0 || 0 || normal mode
461 * |-----||-------||-------||-----------------------------------
462 * | || || || standby mode w/ slave tuner output
463 * | 1 || 0 || 0 || & loop thru & xtal oscillator on
464 * |-----||-------||-------||-----------------------------------
465 * | 1 || 1 || 0 || standby mode w/ xtal oscillator on
466 * |-----||-------||-------||-----------------------------------
467 * | 1 || 1 || 1 || power off
468 *
469 */
470
471int tda18271_set_standby_mode(struct dvb_frontend *fe,
472 int sm, int sm_lt, int sm_xt)
473{
474 struct tda18271_priv *priv = fe->tuner_priv;
475 unsigned char *regs = priv->tda18271_regs;
476
477 tda_dbg("sm = %d, sm_lt = %d, sm_xt = %d\n", sm, sm_lt, sm_xt);
478
479 regs[R_EP3] &= ~0xe0; /* clear sm, sm_lt, sm_xt */
480 regs[R_EP3] |= sm ? (1 << 7) : 0 |
481 sm_lt ? (1 << 6) : 0 |
482 sm_xt ? (1 << 5) : 0;
483
484 tda18271_write_regs(fe, R_EP3, 1);
485
486 return 0;
487}
488
489/*---------------------------------------------------------------------*/
490
491int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq)
492{
493 /* sets main post divider & divider bytes, but does not write them */
494 struct tda18271_priv *priv = fe->tuner_priv;
495 unsigned char *regs = priv->tda18271_regs;
496 u8 d, pd;
497 u32 div;
498
499 int ret = tda18271_lookup_pll_map(fe, MAIN_PLL, &freq, &pd, &d);
500 if (ret < 0)
501 goto fail;
502
503 regs[R_MPD] = (0x77 & pd);
504
505 switch (priv->mode) {
506 case TDA18271_ANALOG:
507 regs[R_MPD] &= ~0x08;
508 break;
509 case TDA18271_DIGITAL:
510 regs[R_MPD] |= 0x08;
511 break;
512 }
513
514 div = ((d * (freq / 1000)) << 7) / 125;
515
516 regs[R_MD1] = 0x7f & (div >> 16);
517 regs[R_MD2] = 0xff & (div >> 8);
518 regs[R_MD3] = 0xff & div;
519fail:
520 return ret;
521}
522
523int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq)
524{
525 /* sets cal post divider & divider bytes, but does not write them */
526 struct tda18271_priv *priv = fe->tuner_priv;
527 unsigned char *regs = priv->tda18271_regs;
528 u8 d, pd;
529 u32 div;
530
531 int ret = tda18271_lookup_pll_map(fe, CAL_PLL, &freq, &pd, &d);
532 if (ret < 0)
533 goto fail;
534
535 regs[R_CPD] = pd;
536
537 div = ((d * (freq / 1000)) << 7) / 125;
538
539 regs[R_CD1] = 0x7f & (div >> 16);
540 regs[R_CD2] = 0xff & (div >> 8);
541 regs[R_CD3] = 0xff & div;
542fail:
543 return ret;
544}
545
546/*---------------------------------------------------------------------*/
547
548int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq)
549{
550 /* sets bp filter bits, but does not write them */
551 struct tda18271_priv *priv = fe->tuner_priv;
552 unsigned char *regs = priv->tda18271_regs;
553 u8 val;
554
555 int ret = tda18271_lookup_map(fe, BP_FILTER, freq, &val);
556 if (ret < 0)
557 goto fail;
558
559 regs[R_EP1] &= ~0x07; /* clear bp filter bits */
560 regs[R_EP1] |= (0x07 & val);
561fail:
562 return ret;
563}
564
565int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq)
566{
567 /* sets K & M bits, but does not write them */
568 struct tda18271_priv *priv = fe->tuner_priv;
569 unsigned char *regs = priv->tda18271_regs;
570 u8 val;
571
572 int ret = tda18271_lookup_map(fe, RF_CAL_KMCO, freq, &val);
573 if (ret < 0)
574 goto fail;
575
576 regs[R_EB13] &= ~0x7c; /* clear k & m bits */
577 regs[R_EB13] |= (0x7c & val);
578fail:
579 return ret;
580}
581
582int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq)
583{
584 /* sets rf band bits, but does not write them */
585 struct tda18271_priv *priv = fe->tuner_priv;
586 unsigned char *regs = priv->tda18271_regs;
587 u8 val;
588
589 int ret = tda18271_lookup_map(fe, RF_BAND, freq, &val);
590 if (ret < 0)
591 goto fail;
592
593 regs[R_EP2] &= ~0xe0; /* clear rf band bits */
594 regs[R_EP2] |= (0xe0 & (val << 5));
595fail:
596 return ret;
597}
598
599int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq)
600{
601 /* sets gain taper bits, but does not write them */
602 struct tda18271_priv *priv = fe->tuner_priv;
603 unsigned char *regs = priv->tda18271_regs;
604 u8 val;
605
606 int ret = tda18271_lookup_map(fe, GAIN_TAPER, freq, &val);
607 if (ret < 0)
608 goto fail;
609
610 regs[R_EP2] &= ~0x1f; /* clear gain taper bits */
611 regs[R_EP2] |= (0x1f & val);
612fail:
613 return ret;
614}
615
616int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq)
617{
618 /* sets IR Meas bits, but does not write them */
619 struct tda18271_priv *priv = fe->tuner_priv;
620 unsigned char *regs = priv->tda18271_regs;
621 u8 val;
622
623 int ret = tda18271_lookup_map(fe, IR_MEASURE, freq, &val);
624 if (ret < 0)
625 goto fail;
626
627 regs[R_EP5] &= ~0x07;
628 regs[R_EP5] |= (0x07 & val);
629fail:
630 return ret;
631}
632
633int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq)
634{
635 /* sets rf cal byte (RFC_Cprog), but does not write it */
636 struct tda18271_priv *priv = fe->tuner_priv;
637 unsigned char *regs = priv->tda18271_regs;
638 u8 val;
639
640 tda18271_lookup_map(fe, RF_CAL, freq, &val);
641
642 regs[R_EB14] = val;
643
644 return 0;
645}
646
647/*
648 * Overrides for Emacs so that we follow Linus's tabbing style.
649 * ---------------------------------------------------------------------------
650 * Local variables:
651 * c-basic-offset: 8
652 * End:
653 */
diff --git a/drivers/media/dvb/frontends/tda18271-fe.c b/drivers/media/dvb/frontends/tda18271-fe.c
new file mode 100644
index 000000000000..dfe72aaec380
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda18271-fe.c
@@ -0,0 +1,1225 @@
1/*
2 tda18271-fe.c - driver for the Philips / NXP TDA18271 silicon tuner
3
4 Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/delay.h>
22#include <linux/videodev2.h>
23#include "tda18271-priv.h"
24
25int tda18271_debug;
26module_param_named(debug, tda18271_debug, int, 0644);
27MODULE_PARM_DESC(debug, "set debug level "
28 "(info=1, map=2, reg=4, adv=8, cal=16 (or-able))");
29
30static int tda18271_cal_on_startup;
31module_param_named(cal, tda18271_cal_on_startup, int, 0644);
32MODULE_PARM_DESC(cal, "perform RF tracking filter calibration on startup");
33
34static LIST_HEAD(tda18271_list);
35static DEFINE_MUTEX(tda18271_list_mutex);
36
37/*---------------------------------------------------------------------*/
38
39static int tda18271_ir_cal_init(struct dvb_frontend *fe)
40{
41 struct tda18271_priv *priv = fe->tuner_priv;
42 unsigned char *regs = priv->tda18271_regs;
43
44 tda18271_read_regs(fe);
45
46 /* test IR_CAL_OK to see if we need init */
47 if ((regs[R_EP1] & 0x08) == 0)
48 tda18271_init_regs(fe);
49
50 return 0;
51}
52
53/* ------------------------------------------------------------------ */
54
55static int tda18271_channel_configuration(struct dvb_frontend *fe,
56 u32 ifc, u32 freq, u32 bw, u8 std,
57 int radio)
58{
59 struct tda18271_priv *priv = fe->tuner_priv;
60 unsigned char *regs = priv->tda18271_regs;
61 u32 N;
62
63 /* update TV broadcast parameters */
64
65 /* set standard */
66 regs[R_EP3] &= ~0x1f; /* clear std bits */
67 regs[R_EP3] |= std;
68
69 /* set cal mode to normal */
70 regs[R_EP4] &= ~0x03;
71
72 /* update IF output level & IF notch frequency */
73 regs[R_EP4] &= ~0x1c; /* clear if level bits */
74
75 switch (priv->mode) {
76 case TDA18271_ANALOG:
77 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
78 break;
79 case TDA18271_DIGITAL:
80 regs[R_EP4] |= 0x04; /* IF level = 1 */
81 regs[R_MPD] |= 0x80; /* IF notch = 1 */
82 break;
83 }
84
85 if (radio)
86 regs[R_EP4] |= 0x80;
87 else
88 regs[R_EP4] &= ~0x80;
89
90 /* update RF_TOP / IF_TOP */
91 switch (priv->mode) {
92 case TDA18271_ANALOG:
93 regs[R_EB22] = 0x2c;
94 break;
95 case TDA18271_DIGITAL:
96 regs[R_EB22] = 0x37;
97 break;
98 }
99 tda18271_write_regs(fe, R_EB22, 1);
100
101 /* --------------------------------------------------------------- */
102
103 /* disable Power Level Indicator */
104 regs[R_EP1] |= 0x40;
105
106 /* frequency dependent parameters */
107
108 tda18271_calc_ir_measure(fe, &freq);
109
110 tda18271_calc_bp_filter(fe, &freq);
111
112 tda18271_calc_rf_band(fe, &freq);
113
114 tda18271_calc_gain_taper(fe, &freq);
115
116 /* --------------------------------------------------------------- */
117
118 /* dual tuner and agc1 extra configuration */
119
120 /* main vco when Master, cal vco when slave */
121 regs[R_EB1] |= 0x04; /* FIXME: assumes master */
122
123 /* agc1 always active */
124 regs[R_EB1] &= ~0x02;
125
126 /* agc1 has priority on agc2 */
127 regs[R_EB1] &= ~0x01;
128
129 tda18271_write_regs(fe, R_EB1, 1);
130
131 /* --------------------------------------------------------------- */
132
133 N = freq + ifc;
134
135 /* FIXME: assumes master */
136 tda18271_calc_main_pll(fe, N);
137 tda18271_write_regs(fe, R_MPD, 4);
138
139 tda18271_write_regs(fe, R_TM, 7);
140
141 /* main pll charge pump source */
142 regs[R_EB4] |= 0x20;
143 tda18271_write_regs(fe, R_EB4, 1);
144
145 msleep(1);
146
147 /* normal operation for the main pll */
148 regs[R_EB4] &= ~0x20;
149 tda18271_write_regs(fe, R_EB4, 1);
150
151 msleep(5);
152
153 return 0;
154}
155
156static int tda18271_read_thermometer(struct dvb_frontend *fe)
157{
158 struct tda18271_priv *priv = fe->tuner_priv;
159 unsigned char *regs = priv->tda18271_regs;
160 int tm;
161
162 /* switch thermometer on */
163 regs[R_TM] |= 0x10;
164 tda18271_write_regs(fe, R_TM, 1);
165
166 /* read thermometer info */
167 tda18271_read_regs(fe);
168
169 if ((((regs[R_TM] & 0x0f) == 0x00) && ((regs[R_TM] & 0x20) == 0x20)) ||
170 (((regs[R_TM] & 0x0f) == 0x08) && ((regs[R_TM] & 0x20) == 0x00))) {
171
172 if ((regs[R_TM] & 0x20) == 0x20)
173 regs[R_TM] &= ~0x20;
174 else
175 regs[R_TM] |= 0x20;
176
177 tda18271_write_regs(fe, R_TM, 1);
178
179 msleep(10); /* temperature sensing */
180
181 /* read thermometer info */
182 tda18271_read_regs(fe);
183 }
184
185 tm = tda18271_lookup_thermometer(fe);
186
187 /* switch thermometer off */
188 regs[R_TM] &= ~0x10;
189 tda18271_write_regs(fe, R_TM, 1);
190
191 /* set CAL mode to normal */
192 regs[R_EP4] &= ~0x03;
193 tda18271_write_regs(fe, R_EP4, 1);
194
195 return tm;
196}
197
198static int tda18271_rf_tracking_filters_correction(struct dvb_frontend *fe,
199 u32 freq)
200{
201 struct tda18271_priv *priv = fe->tuner_priv;
202 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state;
203 unsigned char *regs = priv->tda18271_regs;
204 int tm_current, rfcal_comp, approx, i;
205 u8 dc_over_dt, rf_tab;
206
207 /* power up */
208 tda18271_set_standby_mode(fe, 0, 0, 0);
209
210 /* read die current temperature */
211 tm_current = tda18271_read_thermometer(fe);
212
213 /* frequency dependent parameters */
214
215 tda18271_calc_rf_cal(fe, &freq);
216 rf_tab = regs[R_EB14];
217
218 i = tda18271_lookup_rf_band(fe, &freq, NULL);
219 if (i < 0)
220 return -EINVAL;
221
222 if ((0 == map[i].rf3) || (freq / 1000 < map[i].rf2)) {
223 approx = map[i].rf_a1 *
224 (freq / 1000 - map[i].rf1) + map[i].rf_b1 + rf_tab;
225 } else {
226 approx = map[i].rf_a2 *
227 (freq / 1000 - map[i].rf2) + map[i].rf_b2 + rf_tab;
228 }
229
230 if (approx < 0)
231 approx = 0;
232 if (approx > 255)
233 approx = 255;
234
235 tda18271_lookup_map(fe, RF_CAL_DC_OVER_DT, &freq, &dc_over_dt);
236
237 /* calculate temperature compensation */
238 rfcal_comp = dc_over_dt * (tm_current - priv->tm_rfcal);
239
240 regs[R_EB14] = approx + rfcal_comp;
241 tda18271_write_regs(fe, R_EB14, 1);
242
243 return 0;
244}
245
246static int tda18271_por(struct dvb_frontend *fe)
247{
248 struct tda18271_priv *priv = fe->tuner_priv;
249 unsigned char *regs = priv->tda18271_regs;
250
251 /* power up detector 1 */
252 regs[R_EB12] &= ~0x20;
253 tda18271_write_regs(fe, R_EB12, 1);
254
255 regs[R_EB18] &= ~0x80; /* turn agc1 loop on */
256 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
257 tda18271_write_regs(fe, R_EB18, 1);
258
259 regs[R_EB21] |= 0x03; /* set agc2_gain to -6 dB */
260
261 /* POR mode */
262 tda18271_set_standby_mode(fe, 1, 0, 0);
263
264 /* disable 1.5 MHz low pass filter */
265 regs[R_EB23] &= ~0x04; /* forcelp_fc2_en = 0 */
266 regs[R_EB23] &= ~0x02; /* XXX: lp_fc[2] = 0 */
267 tda18271_write_regs(fe, R_EB21, 3);
268
269 return 0;
270}
271
272static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
273{
274 struct tda18271_priv *priv = fe->tuner_priv;
275 unsigned char *regs = priv->tda18271_regs;
276 u32 N;
277
278 /* set CAL mode to normal */
279 regs[R_EP4] &= ~0x03;
280 tda18271_write_regs(fe, R_EP4, 1);
281
282 /* switch off agc1 */
283 regs[R_EP3] |= 0x40; /* sm_lt = 1 */
284
285 regs[R_EB18] |= 0x03; /* set agc1_gain to 15 dB */
286 tda18271_write_regs(fe, R_EB18, 1);
287
288 /* frequency dependent parameters */
289
290 tda18271_calc_bp_filter(fe, &freq);
291 tda18271_calc_gain_taper(fe, &freq);
292 tda18271_calc_rf_band(fe, &freq);
293 tda18271_calc_km(fe, &freq);
294
295 tda18271_write_regs(fe, R_EP1, 3);
296 tda18271_write_regs(fe, R_EB13, 1);
297
298 /* main pll charge pump source */
299 regs[R_EB4] |= 0x20;
300 tda18271_write_regs(fe, R_EB4, 1);
301
302 /* cal pll charge pump source */
303 regs[R_EB7] |= 0x20;
304 tda18271_write_regs(fe, R_EB7, 1);
305
306 /* force dcdc converter to 0 V */
307 regs[R_EB14] = 0x00;
308 tda18271_write_regs(fe, R_EB14, 1);
309
310 /* disable plls lock */
311 regs[R_EB20] &= ~0x20;
312 tda18271_write_regs(fe, R_EB20, 1);
313
314 /* set CAL mode to RF tracking filter calibration */
315 regs[R_EP4] |= 0x03;
316 tda18271_write_regs(fe, R_EP4, 2);
317
318 /* --------------------------------------------------------------- */
319
320 /* set the internal calibration signal */
321 N = freq;
322
323 tda18271_calc_main_pll(fe, N);
324 tda18271_write_regs(fe, R_MPD, 4);
325
326 /* downconvert internal calibration */
327 N += 1000000;
328
329 tda18271_calc_main_pll(fe, N);
330 tda18271_write_regs(fe, R_MPD, 4);
331
332 msleep(5);
333
334 tda18271_write_regs(fe, R_EP2, 1);
335 tda18271_write_regs(fe, R_EP1, 1);
336 tda18271_write_regs(fe, R_EP2, 1);
337 tda18271_write_regs(fe, R_EP1, 1);
338
339 /* --------------------------------------------------------------- */
340
341 /* normal operation for the main pll */
342 regs[R_EB4] &= ~0x20;
343 tda18271_write_regs(fe, R_EB4, 1);
344
345 /* normal operation for the cal pll */
346 regs[R_EB7] &= ~0x20;
347 tda18271_write_regs(fe, R_EB7, 1);
348
349 msleep(5); /* plls locking */
350
351 /* launch the rf tracking filters calibration */
352 regs[R_EB20] |= 0x20;
353 tda18271_write_regs(fe, R_EB20, 1);
354
355 msleep(60); /* calibration */
356
357 /* --------------------------------------------------------------- */
358
359 /* set CAL mode to normal */
360 regs[R_EP4] &= ~0x03;
361
362 /* switch on agc1 */
363 regs[R_EP3] &= ~0x40; /* sm_lt = 0 */
364
365 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
366 tda18271_write_regs(fe, R_EB18, 1);
367
368 tda18271_write_regs(fe, R_EP3, 2);
369
370 /* synchronization */
371 tda18271_write_regs(fe, R_EP1, 1);
372
373 /* get calibration result */
374 tda18271_read_extended(fe);
375
376 return regs[R_EB14];
377}
378
379static int tda18271_powerscan(struct dvb_frontend *fe,
380 u32 *freq_in, u32 *freq_out)
381{
382 struct tda18271_priv *priv = fe->tuner_priv;
383 unsigned char *regs = priv->tda18271_regs;
384 int sgn, bcal, count, wait;
385 u8 cid_target;
386 u16 count_limit;
387 u32 freq;
388
389 freq = *freq_in;
390
391 tda18271_calc_rf_band(fe, &freq);
392 tda18271_calc_rf_cal(fe, &freq);
393 tda18271_calc_gain_taper(fe, &freq);
394 tda18271_lookup_cid_target(fe, &freq, &cid_target, &count_limit);
395
396 tda18271_write_regs(fe, R_EP2, 1);
397 tda18271_write_regs(fe, R_EB14, 1);
398
399 /* downconvert frequency */
400 freq += 1000000;
401
402 tda18271_calc_main_pll(fe, freq);
403 tda18271_write_regs(fe, R_MPD, 4);
404
405 msleep(5); /* pll locking */
406
407 /* detection mode */
408 regs[R_EP4] &= ~0x03;
409 regs[R_EP4] |= 0x01;
410 tda18271_write_regs(fe, R_EP4, 1);
411
412 /* launch power detection measurement */
413 tda18271_write_regs(fe, R_EP2, 1);
414
415 /* read power detection info, stored in EB10 */
416 tda18271_read_extended(fe);
417
418 /* algorithm initialization */
419 sgn = 1;
420 *freq_out = *freq_in;
421 bcal = 0;
422 count = 0;
423 wait = false;
424
425 while ((regs[R_EB10] & 0x3f) < cid_target) {
426 /* downconvert updated freq to 1 MHz */
427 freq = *freq_in + (sgn * count) + 1000000;
428
429 tda18271_calc_main_pll(fe, freq);
430 tda18271_write_regs(fe, R_MPD, 4);
431
432 if (wait) {
433 msleep(5); /* pll locking */
434 wait = false;
435 } else
436 udelay(100); /* pll locking */
437
438 /* launch power detection measurement */
439 tda18271_write_regs(fe, R_EP2, 1);
440
441 /* read power detection info, stored in EB10 */
442 tda18271_read_extended(fe);
443
444 count += 200;
445
446 if (count < count_limit)
447 continue;
448
449 if (sgn <= 0)
450 break;
451
452 sgn = -1 * sgn;
453 count = 200;
454 wait = true;
455 }
456
457 if ((regs[R_EB10] & 0x3f) >= cid_target) {
458 bcal = 1;
459 *freq_out = freq - 1000000;
460 } else
461 bcal = 0;
462
463 tda_cal("bcal = %d, freq_in = %d, freq_out = %d (freq = %d)\n",
464 bcal, *freq_in, *freq_out, freq);
465
466 return bcal;
467}
468
469static int tda18271_powerscan_init(struct dvb_frontend *fe)
470{
471 struct tda18271_priv *priv = fe->tuner_priv;
472 unsigned char *regs = priv->tda18271_regs;
473
474 /* set standard to digital */
475 regs[R_EP3] &= ~0x1f; /* clear std bits */
476 regs[R_EP3] |= 0x12;
477
478 /* set cal mode to normal */
479 regs[R_EP4] &= ~0x03;
480
481 /* update IF output level & IF notch frequency */
482 regs[R_EP4] &= ~0x1c; /* clear if level bits */
483
484 tda18271_write_regs(fe, R_EP3, 2);
485
486 regs[R_EB18] &= ~0x03; /* set agc1_gain to 6 dB */
487 tda18271_write_regs(fe, R_EB18, 1);
488
489 regs[R_EB21] &= ~0x03; /* set agc2_gain to -15 dB */
490
491 /* 1.5 MHz low pass filter */
492 regs[R_EB23] |= 0x04; /* forcelp_fc2_en = 1 */
493 regs[R_EB23] |= 0x02; /* lp_fc[2] = 1 */
494
495 tda18271_write_regs(fe, R_EB21, 3);
496
497 return 0;
498}
499
500static int tda18271_rf_tracking_filters_init(struct dvb_frontend *fe, u32 freq)
501{
502 struct tda18271_priv *priv = fe->tuner_priv;
503 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state;
504 unsigned char *regs = priv->tda18271_regs;
505 int bcal, rf, i;
506#define RF1 0
507#define RF2 1
508#define RF3 2
509 u32 rf_default[3];
510 u32 rf_freq[3];
511 u8 prog_cal[3];
512 u8 prog_tab[3];
513
514 i = tda18271_lookup_rf_band(fe, &freq, NULL);
515
516 if (i < 0)
517 return i;
518
519 rf_default[RF1] = 1000 * map[i].rf1_def;
520 rf_default[RF2] = 1000 * map[i].rf2_def;
521 rf_default[RF3] = 1000 * map[i].rf3_def;
522
523 for (rf = RF1; rf <= RF3; rf++) {
524 if (0 == rf_default[rf])
525 return 0;
526 tda_cal("freq = %d, rf = %d\n", freq, rf);
527
528 /* look for optimized calibration frequency */
529 bcal = tda18271_powerscan(fe, &rf_default[rf], &rf_freq[rf]);
530
531 tda18271_calc_rf_cal(fe, &rf_freq[rf]);
532 prog_tab[rf] = regs[R_EB14];
533
534 if (1 == bcal)
535 prog_cal[rf] = tda18271_calibrate_rf(fe, rf_freq[rf]);
536 else
537 prog_cal[rf] = prog_tab[rf];
538
539 switch (rf) {
540 case RF1:
541 map[i].rf_a1 = 0;
542 map[i].rf_b1 = prog_cal[RF1] - prog_tab[RF1];
543 map[i].rf1 = rf_freq[RF1] / 1000;
544 break;
545 case RF2:
546 map[i].rf_a1 = (prog_cal[RF2] - prog_tab[RF2] -
547 prog_cal[RF1] + prog_tab[RF1]) /
548 ((rf_freq[RF2] - rf_freq[RF1]) / 1000);
549 map[i].rf2 = rf_freq[RF2] / 1000;
550 break;
551 case RF3:
552 map[i].rf_a2 = (prog_cal[RF3] - prog_tab[RF3] -
553 prog_cal[RF2] + prog_tab[RF2]) /
554 ((rf_freq[RF3] - rf_freq[RF2]) / 1000);
555 map[i].rf_b2 = prog_cal[RF2] - prog_tab[RF2];
556 map[i].rf3 = rf_freq[RF3] / 1000;
557 break;
558 default:
559 BUG();
560 }
561 }
562
563 return 0;
564}
565
566static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe)
567{
568 struct tda18271_priv *priv = fe->tuner_priv;
569 unsigned int i;
570
571 tda_info("tda18271: performing RF tracking filter calibration\n");
572
573 /* wait for die temperature stabilization */
574 msleep(200);
575
576 tda18271_powerscan_init(fe);
577
578 /* rf band calibration */
579 for (i = 0; priv->rf_cal_state[i].rfmax != 0; i++)
580 tda18271_rf_tracking_filters_init(fe, 1000 *
581 priv->rf_cal_state[i].rfmax);
582
583 priv->tm_rfcal = tda18271_read_thermometer(fe);
584
585 return 0;
586}
587
588/* ------------------------------------------------------------------ */
589
590static int tda18271_rf_cal_init(struct dvb_frontend *fe)
591{
592 struct tda18271_priv *priv = fe->tuner_priv;
593 unsigned char *regs = priv->tda18271_regs;
594
595 /* test RF_CAL_OK to see if we need init */
596 if ((regs[R_EP1] & 0x10) == 0)
597 priv->cal_initialized = false;
598
599 if (priv->cal_initialized)
600 return 0;
601
602 tda18271_calc_rf_filter_curve(fe);
603
604 tda18271_por(fe);
605
606 tda_info("tda18271: RF tracking filter calibration complete\n");
607
608 priv->cal_initialized = true;
609
610 return 0;
611}
612
613static int tda18271_init(struct dvb_frontend *fe)
614{
615 struct tda18271_priv *priv = fe->tuner_priv;
616
617 mutex_lock(&priv->lock);
618
619 /* power up */
620 tda18271_set_standby_mode(fe, 0, 0, 0);
621
622 /* initialization */
623 tda18271_ir_cal_init(fe);
624
625 if (priv->id == TDA18271HDC2)
626 tda18271_rf_cal_init(fe);
627
628 mutex_unlock(&priv->lock);
629
630 return 0;
631}
632
633static int tda18271c2_tune(struct dvb_frontend *fe,
634 u32 ifc, u32 freq, u32 bw, u8 std, int radio)
635{
636 struct tda18271_priv *priv = fe->tuner_priv;
637
638 tda_dbg("freq = %d, ifc = %d\n", freq, ifc);
639
640 tda18271_init(fe);
641
642 mutex_lock(&priv->lock);
643
644 tda18271_rf_tracking_filters_correction(fe, freq);
645
646 tda18271_channel_configuration(fe, ifc, freq, bw, std, radio);
647
648 mutex_unlock(&priv->lock);
649
650 return 0;
651}
652
653/* ------------------------------------------------------------------ */
654
655static int tda18271c1_tune(struct dvb_frontend *fe,
656 u32 ifc, u32 freq, u32 bw, u8 std, int radio)
657{
658 struct tda18271_priv *priv = fe->tuner_priv;
659 unsigned char *regs = priv->tda18271_regs;
660 u32 N = 0;
661
662 tda18271_init(fe);
663
664 mutex_lock(&priv->lock);
665
666 tda_dbg("freq = %d, ifc = %d\n", freq, ifc);
667
668 /* RF tracking filter calibration */
669
670 /* calculate bp filter */
671 tda18271_calc_bp_filter(fe, &freq);
672 tda18271_write_regs(fe, R_EP1, 1);
673
674 regs[R_EB4] &= 0x07;
675 regs[R_EB4] |= 0x60;
676 tda18271_write_regs(fe, R_EB4, 1);
677
678 regs[R_EB7] = 0x60;
679 tda18271_write_regs(fe, R_EB7, 1);
680
681 regs[R_EB14] = 0x00;
682 tda18271_write_regs(fe, R_EB14, 1);
683
684 regs[R_EB20] = 0xcc;
685 tda18271_write_regs(fe, R_EB20, 1);
686
687 /* set cal mode to RF tracking filter calibration */
688 regs[R_EP4] |= 0x03;
689
690 /* calculate cal pll */
691
692 switch (priv->mode) {
693 case TDA18271_ANALOG:
694 N = freq - 1250000;
695 break;
696 case TDA18271_DIGITAL:
697 N = freq + bw / 2;
698 break;
699 }
700
701 tda18271_calc_cal_pll(fe, N);
702
703 /* calculate main pll */
704
705 switch (priv->mode) {
706 case TDA18271_ANALOG:
707 N = freq - 250000;
708 break;
709 case TDA18271_DIGITAL:
710 N = freq + bw / 2 + 1000000;
711 break;
712 }
713
714 tda18271_calc_main_pll(fe, N);
715
716 tda18271_write_regs(fe, R_EP3, 11);
717 msleep(5); /* RF tracking filter calibration initialization */
718
719 /* search for K,M,CO for RF calibration */
720 tda18271_calc_km(fe, &freq);
721 tda18271_write_regs(fe, R_EB13, 1);
722
723 /* search for rf band */
724 tda18271_calc_rf_band(fe, &freq);
725
726 /* search for gain taper */
727 tda18271_calc_gain_taper(fe, &freq);
728
729 tda18271_write_regs(fe, R_EP2, 1);
730 tda18271_write_regs(fe, R_EP1, 1);
731 tda18271_write_regs(fe, R_EP2, 1);
732 tda18271_write_regs(fe, R_EP1, 1);
733
734 regs[R_EB4] &= 0x07;
735 regs[R_EB4] |= 0x40;
736 tda18271_write_regs(fe, R_EB4, 1);
737
738 regs[R_EB7] = 0x40;
739 tda18271_write_regs(fe, R_EB7, 1);
740 msleep(10);
741
742 regs[R_EB20] = 0xec;
743 tda18271_write_regs(fe, R_EB20, 1);
744 msleep(60); /* RF tracking filter calibration completion */
745
746 regs[R_EP4] &= ~0x03; /* set cal mode to normal */
747 tda18271_write_regs(fe, R_EP4, 1);
748
749 tda18271_write_regs(fe, R_EP1, 1);
750
751 /* RF tracking filter correction for VHF_Low band */
752 if (0 == tda18271_calc_rf_cal(fe, &freq))
753 tda18271_write_regs(fe, R_EB14, 1);
754
755 /* Channel Configuration */
756
757 switch (priv->mode) {
758 case TDA18271_ANALOG:
759 regs[R_EB22] = 0x2c;
760 break;
761 case TDA18271_DIGITAL:
762 regs[R_EB22] = 0x37;
763 break;
764 }
765 tda18271_write_regs(fe, R_EB22, 1);
766
767 regs[R_EP1] |= 0x40; /* set dis power level on */
768
769 /* set standard */
770 regs[R_EP3] &= ~0x1f; /* clear std bits */
771
772 /* see table 22 */
773 regs[R_EP3] |= std;
774
775 regs[R_EP4] &= ~0x03; /* set cal mode to normal */
776
777 regs[R_EP4] &= ~0x1c; /* clear if level bits */
778 switch (priv->mode) {
779 case TDA18271_ANALOG:
780 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
781 break;
782 case TDA18271_DIGITAL:
783 regs[R_EP4] |= 0x04;
784 regs[R_MPD] |= 0x80;
785 break;
786 }
787
788 if (radio)
789 regs[R_EP4] |= 0x80;
790 else
791 regs[R_EP4] &= ~0x80;
792
793 /* image rejection validity */
794 tda18271_calc_ir_measure(fe, &freq);
795
796 /* calculate MAIN PLL */
797 N = freq + ifc;
798
799 tda18271_calc_main_pll(fe, N);
800
801 tda18271_write_regs(fe, R_TM, 15);
802 msleep(5);
803 mutex_unlock(&priv->lock);
804
805 return 0;
806}
807
808static inline int tda18271_tune(struct dvb_frontend *fe,
809 u32 ifc, u32 freq, u32 bw, u8 std, int radio)
810{
811 struct tda18271_priv *priv = fe->tuner_priv;
812 int ret = -EINVAL;
813
814 switch (priv->id) {
815 case TDA18271HDC1:
816 ret = tda18271c1_tune(fe, ifc, freq, bw, std, radio);
817 break;
818 case TDA18271HDC2:
819 ret = tda18271c2_tune(fe, ifc, freq, bw, std, radio);
820 break;
821 }
822 return ret;
823}
824
825/* ------------------------------------------------------------------ */
826
827static int tda18271_set_params(struct dvb_frontend *fe,
828 struct dvb_frontend_parameters *params)
829{
830 struct tda18271_priv *priv = fe->tuner_priv;
831 struct tda18271_std_map *std_map = &priv->std;
832 int ret;
833 u8 std;
834 u16 sgIF;
835 u32 bw, freq = params->frequency;
836
837 priv->mode = TDA18271_DIGITAL;
838
839 if (fe->ops.info.type == FE_ATSC) {
840 switch (params->u.vsb.modulation) {
841 case VSB_8:
842 case VSB_16:
843 std = std_map->atsc_6.std_bits;
844 sgIF = std_map->atsc_6.if_freq;
845 break;
846 case QAM_64:
847 case QAM_256:
848 std = std_map->qam_6.std_bits;
849 sgIF = std_map->qam_6.if_freq;
850 break;
851 default:
852 tda_warn("modulation not set!\n");
853 return -EINVAL;
854 }
855#if 0
856 /* userspace request is already center adjusted */
857 freq += 1750000; /* Adjust to center (+1.75MHZ) */
858#endif
859 bw = 6000000;
860 } else if (fe->ops.info.type == FE_OFDM) {
861 switch (params->u.ofdm.bandwidth) {
862 case BANDWIDTH_6_MHZ:
863 bw = 6000000;
864 std = std_map->dvbt_6.std_bits;
865 sgIF = std_map->dvbt_6.if_freq;
866 break;
867 case BANDWIDTH_7_MHZ:
868 bw = 7000000;
869 std = std_map->dvbt_7.std_bits;
870 sgIF = std_map->dvbt_7.if_freq;
871 break;
872 case BANDWIDTH_8_MHZ:
873 bw = 8000000;
874 std = std_map->dvbt_8.std_bits;
875 sgIF = std_map->dvbt_8.if_freq;
876 break;
877 default:
878 tda_warn("bandwidth not set!\n");
879 return -EINVAL;
880 }
881 } else {
882 tda_warn("modulation type not supported!\n");
883 return -EINVAL;
884 }
885
886 /* When tuning digital, the analog demod must be tri-stated */
887 if (fe->ops.analog_ops.standby)
888 fe->ops.analog_ops.standby(fe);
889
890 ret = tda18271_tune(fe, sgIF * 1000, freq, bw, std, 0);
891
892 if (ret < 0)
893 goto fail;
894
895 priv->frequency = freq;
896 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ?
897 params->u.ofdm.bandwidth : 0;
898fail:
899 return ret;
900}
901
902static int tda18271_set_analog_params(struct dvb_frontend *fe,
903 struct analog_parameters *params)
904{
905 struct tda18271_priv *priv = fe->tuner_priv;
906 struct tda18271_std_map *std_map = &priv->std;
907 char *mode;
908 int ret, radio = 0;
909 u8 std;
910 u16 sgIF;
911 u32 freq = params->frequency * 62500;
912
913 priv->mode = TDA18271_ANALOG;
914
915 if (params->mode == V4L2_TUNER_RADIO) {
916 radio = 1;
917 freq = freq / 1000;
918 std = std_map->fm_radio.std_bits;
919 sgIF = std_map->fm_radio.if_freq;
920 mode = "fm";
921 } else if (params->std & V4L2_STD_MN) {
922 std = std_map->atv_mn.std_bits;
923 sgIF = std_map->atv_mn.if_freq;
924 mode = "MN";
925 } else if (params->std & V4L2_STD_B) {
926 std = std_map->atv_b.std_bits;
927 sgIF = std_map->atv_b.if_freq;
928 mode = "B";
929 } else if (params->std & V4L2_STD_GH) {
930 std = std_map->atv_gh.std_bits;
931 sgIF = std_map->atv_gh.if_freq;
932 mode = "GH";
933 } else if (params->std & V4L2_STD_PAL_I) {
934 std = std_map->atv_i.std_bits;
935 sgIF = std_map->atv_i.if_freq;
936 mode = "I";
937 } else if (params->std & V4L2_STD_DK) {
938 std = std_map->atv_dk.std_bits;
939 sgIF = std_map->atv_dk.if_freq;
940 mode = "DK";
941 } else if (params->std & V4L2_STD_SECAM_L) {
942 std = std_map->atv_l.std_bits;
943 sgIF = std_map->atv_l.if_freq;
944 mode = "L";
945 } else if (params->std & V4L2_STD_SECAM_LC) {
946 std = std_map->atv_lc.std_bits;
947 sgIF = std_map->atv_lc.if_freq;
948 mode = "L'";
949 } else {
950 std = std_map->atv_i.std_bits;
951 sgIF = std_map->atv_i.if_freq;
952 mode = "xx";
953 }
954
955 tda_dbg("setting tda18271 to system %s\n", mode);
956
957 ret = tda18271_tune(fe, sgIF * 1000, freq, 0, std, radio);
958
959 if (ret < 0)
960 goto fail;
961
962 priv->frequency = freq;
963 priv->bandwidth = 0;
964fail:
965 return ret;
966}
967
968static int tda18271_sleep(struct dvb_frontend *fe)
969{
970 struct tda18271_priv *priv = fe->tuner_priv;
971
972 mutex_lock(&priv->lock);
973
974 /* standby mode w/ slave tuner output
975 * & loop thru & xtal oscillator on */
976 tda18271_set_standby_mode(fe, 1, 0, 0);
977
978 mutex_unlock(&priv->lock);
979
980 return 0;
981}
982
983static int tda18271_release(struct dvb_frontend *fe)
984{
985 struct tda18271_priv *priv = fe->tuner_priv;
986
987 mutex_lock(&tda18271_list_mutex);
988
989 priv->count--;
990
991 if (!priv->count) {
992 tda_dbg("destroying instance @ %d-%04x\n",
993 i2c_adapter_id(priv->i2c_adap),
994 priv->i2c_addr);
995 list_del(&priv->tda18271_list);
996
997 kfree(priv);
998 }
999 mutex_unlock(&tda18271_list_mutex);
1000
1001 fe->tuner_priv = NULL;
1002
1003 return 0;
1004}
1005
1006static int tda18271_get_frequency(struct dvb_frontend *fe, u32 *frequency)
1007{
1008 struct tda18271_priv *priv = fe->tuner_priv;
1009 *frequency = priv->frequency;
1010 return 0;
1011}
1012
1013static int tda18271_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
1014{
1015 struct tda18271_priv *priv = fe->tuner_priv;
1016 *bandwidth = priv->bandwidth;
1017 return 0;
1018}
1019
1020/* ------------------------------------------------------------------ */
1021
1022#define tda18271_update_std(std_cfg, name) do { \
1023 if (map->std_cfg.if_freq + map->std_cfg.std_bits > 0) { \
1024 tda_dbg("Using custom std config for %s\n", name); \
1025 memcpy(&std->std_cfg, &map->std_cfg, \
1026 sizeof(struct tda18271_std_map_item)); \
1027 } } while (0)
1028
1029#define tda18271_dump_std_item(std_cfg, name) do { \
1030 tda_dbg("(%s) if freq = %d, std bits = 0x%02x\n", \
1031 name, std->std_cfg.if_freq, std->std_cfg.std_bits); \
1032 } while (0)
1033
1034static int tda18271_dump_std_map(struct dvb_frontend *fe)
1035{
1036 struct tda18271_priv *priv = fe->tuner_priv;
1037 struct tda18271_std_map *std = &priv->std;
1038
1039 tda_dbg("========== STANDARD MAP SETTINGS ==========\n");
1040 tda18271_dump_std_item(fm_radio, "fm");
1041 tda18271_dump_std_item(atv_b, "pal b");
1042 tda18271_dump_std_item(atv_dk, "pal dk");
1043 tda18271_dump_std_item(atv_gh, "pal gh");
1044 tda18271_dump_std_item(atv_i, "pal i");
1045 tda18271_dump_std_item(atv_l, "pal l");
1046 tda18271_dump_std_item(atv_lc, "pal l'");
1047 tda18271_dump_std_item(atv_mn, "atv mn");
1048 tda18271_dump_std_item(atsc_6, "atsc 6");
1049 tda18271_dump_std_item(dvbt_6, "dvbt 6");
1050 tda18271_dump_std_item(dvbt_7, "dvbt 7");
1051 tda18271_dump_std_item(dvbt_8, "dvbt 8");
1052 tda18271_dump_std_item(qam_6, "qam 6");
1053 tda18271_dump_std_item(qam_8, "qam 8");
1054
1055 return 0;
1056}
1057
1058static int tda18271_update_std_map(struct dvb_frontend *fe,
1059 struct tda18271_std_map *map)
1060{
1061 struct tda18271_priv *priv = fe->tuner_priv;
1062 struct tda18271_std_map *std = &priv->std;
1063
1064 if (!map)
1065 return -EINVAL;
1066
1067 tda18271_update_std(fm_radio, "fm");
1068 tda18271_update_std(atv_b, "atv b");
1069 tda18271_update_std(atv_dk, "atv dk");
1070 tda18271_update_std(atv_gh, "atv gh");
1071 tda18271_update_std(atv_i, "atv i");
1072 tda18271_update_std(atv_l, "atv l");
1073 tda18271_update_std(atv_lc, "atv l'");
1074 tda18271_update_std(atv_mn, "atv mn");
1075 tda18271_update_std(atsc_6, "atsc 6");
1076 tda18271_update_std(dvbt_6, "dvbt 6");
1077 tda18271_update_std(dvbt_7, "dvbt 7");
1078 tda18271_update_std(dvbt_8, "dvbt 8");
1079 tda18271_update_std(qam_6, "qam 6");
1080 tda18271_update_std(qam_8, "qam 8");
1081
1082 return 0;
1083}
1084
1085static int tda18271_get_id(struct dvb_frontend *fe)
1086{
1087 struct tda18271_priv *priv = fe->tuner_priv;
1088 unsigned char *regs = priv->tda18271_regs;
1089 char *name;
1090 int ret = 0;
1091
1092 mutex_lock(&priv->lock);
1093 tda18271_read_regs(fe);
1094 mutex_unlock(&priv->lock);
1095
1096 switch (regs[R_ID] & 0x7f) {
1097 case 3:
1098 name = "TDA18271HD/C1";
1099 priv->id = TDA18271HDC1;
1100 break;
1101 case 4:
1102 name = "TDA18271HD/C2";
1103 priv->id = TDA18271HDC2;
1104 break;
1105 default:
1106 name = "Unknown device";
1107 ret = -EINVAL;
1108 break;
1109 }
1110
1111 tda_info("%s detected @ %d-%04x%s\n", name,
1112 i2c_adapter_id(priv->i2c_adap), priv->i2c_addr,
1113 (0 == ret) ? "" : ", device not supported.");
1114
1115 return ret;
1116}
1117
1118static struct dvb_tuner_ops tda18271_tuner_ops = {
1119 .info = {
1120 .name = "NXP TDA18271HD",
1121 .frequency_min = 45000000,
1122 .frequency_max = 864000000,
1123 .frequency_step = 62500
1124 },
1125 .init = tda18271_init,
1126 .sleep = tda18271_sleep,
1127 .set_params = tda18271_set_params,
1128 .set_analog_params = tda18271_set_analog_params,
1129 .release = tda18271_release,
1130 .get_frequency = tda18271_get_frequency,
1131 .get_bandwidth = tda18271_get_bandwidth,
1132};
1133
1134struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1135 struct i2c_adapter *i2c,
1136 struct tda18271_config *cfg)
1137{
1138 struct tda18271_priv *priv = NULL;
1139 int state_found = 0;
1140
1141 mutex_lock(&tda18271_list_mutex);
1142
1143 list_for_each_entry(priv, &tda18271_list, tda18271_list) {
1144 if ((i2c_adapter_id(priv->i2c_adap) == i2c_adapter_id(i2c)) &&
1145 (priv->i2c_addr == addr)) {
1146 tda_dbg("attaching existing tuner @ %d-%04x\n",
1147 i2c_adapter_id(priv->i2c_adap),
1148 priv->i2c_addr);
1149 priv->count++;
1150 fe->tuner_priv = priv;
1151 state_found = 1;
1152 /* allow dvb driver to override i2c gate setting */
1153 if ((cfg) && (cfg->gate != TDA18271_GATE_ANALOG))
1154 priv->gate = cfg->gate;
1155 break;
1156 }
1157 }
1158 if (state_found == 0) {
1159 tda_dbg("creating new tuner instance @ %d-%04x\n",
1160 i2c_adapter_id(i2c), addr);
1161
1162 priv = kzalloc(sizeof(struct tda18271_priv), GFP_KERNEL);
1163 if (priv == NULL) {
1164 mutex_unlock(&tda18271_list_mutex);
1165 return NULL;
1166 }
1167
1168 priv->i2c_addr = addr;
1169 priv->i2c_adap = i2c;
1170 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
1171 priv->cal_initialized = false;
1172 mutex_init(&priv->lock);
1173 priv->count++;
1174
1175 fe->tuner_priv = priv;
1176
1177 list_add_tail(&priv->tda18271_list, &tda18271_list);
1178
1179 if (tda18271_get_id(fe) < 0)
1180 goto fail;
1181
1182 if (tda18271_assign_map_layout(fe) < 0)
1183 goto fail;
1184
1185 mutex_lock(&priv->lock);
1186 tda18271_init_regs(fe);
1187
1188 if ((tda18271_cal_on_startup) && (priv->id == TDA18271HDC2))
1189 tda18271_rf_cal_init(fe);
1190
1191 mutex_unlock(&priv->lock);
1192 }
1193
1194 /* override default std map with values in config struct */
1195 if ((cfg) && (cfg->std_map))
1196 tda18271_update_std_map(fe, cfg->std_map);
1197
1198 mutex_unlock(&tda18271_list_mutex);
1199
1200 memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops,
1201 sizeof(struct dvb_tuner_ops));
1202
1203 if (tda18271_debug & DBG_MAP)
1204 tda18271_dump_std_map(fe);
1205
1206 return fe;
1207fail:
1208 mutex_unlock(&tda18271_list_mutex);
1209
1210 tda18271_release(fe);
1211 return NULL;
1212}
1213EXPORT_SYMBOL_GPL(tda18271_attach);
1214MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver");
1215MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1216MODULE_LICENSE("GPL");
1217MODULE_VERSION("0.2");
1218
1219/*
1220 * Overrides for Emacs so that we follow Linus's tabbing style.
1221 * ---------------------------------------------------------------------------
1222 * Local variables:
1223 * c-basic-offset: 8
1224 * End:
1225 */
diff --git a/drivers/media/dvb/frontends/tda18271-priv.h b/drivers/media/dvb/frontends/tda18271-priv.h
new file mode 100644
index 000000000000..7b939a5325fb
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda18271-priv.h
@@ -0,0 +1,212 @@
1/*
2 tda18271-priv.h - private header for the NXP TDA18271 silicon tuner
3
4 Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __TDA18271_PRIV_H__
22#define __TDA18271_PRIV_H__
23
24#include <linux/kernel.h>
25#include <linux/types.h>
26#include <linux/mutex.h>
27#include "tda18271.h"
28
29#define R_ID 0x00 /* ID byte */
30#define R_TM 0x01 /* Thermo byte */
31#define R_PL 0x02 /* Power level byte */
32#define R_EP1 0x03 /* Easy Prog byte 1 */
33#define R_EP2 0x04 /* Easy Prog byte 2 */
34#define R_EP3 0x05 /* Easy Prog byte 3 */
35#define R_EP4 0x06 /* Easy Prog byte 4 */
36#define R_EP5 0x07 /* Easy Prog byte 5 */
37#define R_CPD 0x08 /* Cal Post-Divider byte */
38#define R_CD1 0x09 /* Cal Divider byte 1 */
39#define R_CD2 0x0a /* Cal Divider byte 2 */
40#define R_CD3 0x0b /* Cal Divider byte 3 */
41#define R_MPD 0x0c /* Main Post-Divider byte */
42#define R_MD1 0x0d /* Main Divider byte 1 */
43#define R_MD2 0x0e /* Main Divider byte 2 */
44#define R_MD3 0x0f /* Main Divider byte 3 */
45#define R_EB1 0x10 /* Extended byte 1 */
46#define R_EB2 0x11 /* Extended byte 2 */
47#define R_EB3 0x12 /* Extended byte 3 */
48#define R_EB4 0x13 /* Extended byte 4 */
49#define R_EB5 0x14 /* Extended byte 5 */
50#define R_EB6 0x15 /* Extended byte 6 */
51#define R_EB7 0x16 /* Extended byte 7 */
52#define R_EB8 0x17 /* Extended byte 8 */
53#define R_EB9 0x18 /* Extended byte 9 */
54#define R_EB10 0x19 /* Extended byte 10 */
55#define R_EB11 0x1a /* Extended byte 11 */
56#define R_EB12 0x1b /* Extended byte 12 */
57#define R_EB13 0x1c /* Extended byte 13 */
58#define R_EB14 0x1d /* Extended byte 14 */
59#define R_EB15 0x1e /* Extended byte 15 */
60#define R_EB16 0x1f /* Extended byte 16 */
61#define R_EB17 0x20 /* Extended byte 17 */
62#define R_EB18 0x21 /* Extended byte 18 */
63#define R_EB19 0x22 /* Extended byte 19 */
64#define R_EB20 0x23 /* Extended byte 20 */
65#define R_EB21 0x24 /* Extended byte 21 */
66#define R_EB22 0x25 /* Extended byte 22 */
67#define R_EB23 0x26 /* Extended byte 23 */
68
69#define TDA18271_NUM_REGS 39
70
71/*---------------------------------------------------------------------*/
72
73struct tda18271_rf_tracking_filter_cal {
74 u32 rfmax;
75 u8 rfband;
76 u32 rf1_def;
77 u32 rf2_def;
78 u32 rf3_def;
79 u32 rf1;
80 u32 rf2;
81 u32 rf3;
82 int rf_a1;
83 int rf_b1;
84 int rf_a2;
85 int rf_b2;
86};
87
88enum tda18271_mode {
89 TDA18271_ANALOG,
90 TDA18271_DIGITAL,
91};
92
93struct tda18271_map_layout;
94
95enum tda18271_ver {
96 TDA18271HDC1,
97 TDA18271HDC2,
98};
99
100struct tda18271_priv {
101 u8 i2c_addr;
102 struct i2c_adapter *i2c_adap;
103 unsigned char tda18271_regs[TDA18271_NUM_REGS];
104
105 struct list_head tda18271_list;
106
107 enum tda18271_mode mode;
108 enum tda18271_i2c_gate gate;
109 enum tda18271_ver id;
110
111 unsigned int count;
112 unsigned int tm_rfcal;
113 unsigned int cal_initialized:1;
114
115 struct tda18271_map_layout *maps;
116 struct tda18271_std_map std;
117 struct tda18271_rf_tracking_filter_cal rf_cal_state[8];
118
119 struct mutex lock;
120
121 u32 frequency;
122 u32 bandwidth;
123};
124
125/*---------------------------------------------------------------------*/
126
127extern int tda18271_debug;
128
129#define DBG_INFO 1
130#define DBG_MAP 2
131#define DBG_REG 4
132#define DBG_ADV 8
133#define DBG_CAL 16
134
135#define tda_printk(kern, fmt, arg...) \
136 printk(kern "%s: " fmt, __FUNCTION__, ##arg)
137
138#define dprintk(kern, lvl, fmt, arg...) do {\
139 if (tda18271_debug & lvl) \
140 tda_printk(kern, fmt, ##arg); } while (0)
141
142#define tda_info(fmt, arg...) printk(KERN_INFO fmt, ##arg)
143#define tda_warn(fmt, arg...) tda_printk(KERN_WARNING, fmt, ##arg)
144#define tda_err(fmt, arg...) tda_printk(KERN_ERR, fmt, ##arg)
145#define tda_dbg(fmt, arg...) dprintk(KERN_DEBUG, DBG_INFO, fmt, ##arg)
146#define tda_map(fmt, arg...) dprintk(KERN_DEBUG, DBG_MAP, fmt, ##arg)
147#define tda_reg(fmt, arg...) dprintk(KERN_DEBUG, DBG_REG, fmt, ##arg)
148#define tda_cal(fmt, arg...) dprintk(KERN_DEBUG, DBG_CAL, fmt, ##arg)
149
150/*---------------------------------------------------------------------*/
151
152enum tda18271_map_type {
153 /* tda18271_pll_map */
154 MAIN_PLL,
155 CAL_PLL,
156 /* tda18271_map */
157 RF_CAL,
158 RF_CAL_KMCO,
159 RF_CAL_DC_OVER_DT,
160 BP_FILTER,
161 RF_BAND,
162 GAIN_TAPER,
163 IR_MEASURE,
164};
165
166extern int tda18271_lookup_pll_map(struct dvb_frontend *fe,
167 enum tda18271_map_type map_type,
168 u32 *freq, u8 *post_div, u8 *div);
169extern int tda18271_lookup_map(struct dvb_frontend *fe,
170 enum tda18271_map_type map_type,
171 u32 *freq, u8 *val);
172
173extern int tda18271_lookup_thermometer(struct dvb_frontend *fe);
174
175extern int tda18271_lookup_rf_band(struct dvb_frontend *fe,
176 u32 *freq, u8 *rf_band);
177
178extern int tda18271_lookup_cid_target(struct dvb_frontend *fe,
179 u32 *freq, u8 *cid_target,
180 u16 *count_limit);
181
182extern int tda18271_assign_map_layout(struct dvb_frontend *fe);
183
184/*---------------------------------------------------------------------*/
185
186extern int tda18271_read_regs(struct dvb_frontend *fe);
187extern int tda18271_read_extended(struct dvb_frontend *fe);
188extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len);
189extern int tda18271_init_regs(struct dvb_frontend *fe);
190
191extern int tda18271_set_standby_mode(struct dvb_frontend *fe,
192 int sm, int sm_lt, int sm_xt);
193
194extern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq);
195extern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq);
196
197extern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq);
198extern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq);
199extern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq);
200extern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq);
201extern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq);
202extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq);
203
204#endif /* __TDA18271_PRIV_H__ */
205
206/*
207 * Overrides for Emacs so that we follow Linus's tabbing style.
208 * ---------------------------------------------------------------------------
209 * Local variables:
210 * c-basic-offset: 8
211 * End:
212 */
diff --git a/drivers/media/dvb/frontends/tda18271-tables.c b/drivers/media/dvb/frontends/tda18271-tables.c
new file mode 100644
index 000000000000..e94afcfdc5bc
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda18271-tables.c
@@ -0,0 +1,1285 @@
1/*
2 tda18271-tables.c - driver for the Philips / NXP TDA18271 silicon tuner
3
4 Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include "tda18271-priv.h"
22
23struct tda18271_pll_map {
24 u32 lomax;
25 u8 pd; /* post div */
26 u8 d; /* div */
27};
28
29struct tda18271_map {
30 u32 rfmax;
31 u8 val;
32};
33
34/*---------------------------------------------------------------------*/
35
36static struct tda18271_pll_map tda18271c1_main_pll[] = {
37 { .lomax = 32000, .pd = 0x5f, .d = 0xf0 },
38 { .lomax = 35000, .pd = 0x5e, .d = 0xe0 },
39 { .lomax = 37000, .pd = 0x5d, .d = 0xd0 },
40 { .lomax = 41000, .pd = 0x5c, .d = 0xc0 },
41 { .lomax = 44000, .pd = 0x5b, .d = 0xb0 },
42 { .lomax = 49000, .pd = 0x5a, .d = 0xa0 },
43 { .lomax = 54000, .pd = 0x59, .d = 0x90 },
44 { .lomax = 61000, .pd = 0x58, .d = 0x80 },
45 { .lomax = 65000, .pd = 0x4f, .d = 0x78 },
46 { .lomax = 70000, .pd = 0x4e, .d = 0x70 },
47 { .lomax = 75000, .pd = 0x4d, .d = 0x68 },
48 { .lomax = 82000, .pd = 0x4c, .d = 0x60 },
49 { .lomax = 89000, .pd = 0x4b, .d = 0x58 },
50 { .lomax = 98000, .pd = 0x4a, .d = 0x50 },
51 { .lomax = 109000, .pd = 0x49, .d = 0x48 },
52 { .lomax = 123000, .pd = 0x48, .d = 0x40 },
53 { .lomax = 131000, .pd = 0x3f, .d = 0x3c },
54 { .lomax = 141000, .pd = 0x3e, .d = 0x38 },
55 { .lomax = 151000, .pd = 0x3d, .d = 0x34 },
56 { .lomax = 164000, .pd = 0x3c, .d = 0x30 },
57 { .lomax = 179000, .pd = 0x3b, .d = 0x2c },
58 { .lomax = 197000, .pd = 0x3a, .d = 0x28 },
59 { .lomax = 219000, .pd = 0x39, .d = 0x24 },
60 { .lomax = 246000, .pd = 0x38, .d = 0x20 },
61 { .lomax = 263000, .pd = 0x2f, .d = 0x1e },
62 { .lomax = 282000, .pd = 0x2e, .d = 0x1c },
63 { .lomax = 303000, .pd = 0x2d, .d = 0x1a },
64 { .lomax = 329000, .pd = 0x2c, .d = 0x18 },
65 { .lomax = 359000, .pd = 0x2b, .d = 0x16 },
66 { .lomax = 395000, .pd = 0x2a, .d = 0x14 },
67 { .lomax = 438000, .pd = 0x29, .d = 0x12 },
68 { .lomax = 493000, .pd = 0x28, .d = 0x10 },
69 { .lomax = 526000, .pd = 0x1f, .d = 0x0f },
70 { .lomax = 564000, .pd = 0x1e, .d = 0x0e },
71 { .lomax = 607000, .pd = 0x1d, .d = 0x0d },
72 { .lomax = 658000, .pd = 0x1c, .d = 0x0c },
73 { .lomax = 718000, .pd = 0x1b, .d = 0x0b },
74 { .lomax = 790000, .pd = 0x1a, .d = 0x0a },
75 { .lomax = 877000, .pd = 0x19, .d = 0x09 },
76 { .lomax = 987000, .pd = 0x18, .d = 0x08 },
77 { .lomax = 0, .pd = 0x00, .d = 0x00 }, /* end */
78};
79
80static struct tda18271_pll_map tda18271c2_main_pll[] = {
81 { .lomax = 33125, .pd = 0x57, .d = 0xf0 },
82 { .lomax = 35500, .pd = 0x56, .d = 0xe0 },
83 { .lomax = 38188, .pd = 0x55, .d = 0xd0 },
84 { .lomax = 41375, .pd = 0x54, .d = 0xc0 },
85 { .lomax = 45125, .pd = 0x53, .d = 0xb0 },
86 { .lomax = 49688, .pd = 0x52, .d = 0xa0 },
87 { .lomax = 55188, .pd = 0x51, .d = 0x90 },
88 { .lomax = 62125, .pd = 0x50, .d = 0x80 },
89 { .lomax = 66250, .pd = 0x47, .d = 0x78 },
90 { .lomax = 71000, .pd = 0x46, .d = 0x70 },
91 { .lomax = 76375, .pd = 0x45, .d = 0x68 },
92 { .lomax = 82750, .pd = 0x44, .d = 0x60 },
93 { .lomax = 90250, .pd = 0x43, .d = 0x58 },
94 { .lomax = 99375, .pd = 0x42, .d = 0x50 },
95 { .lomax = 110375, .pd = 0x41, .d = 0x48 },
96 { .lomax = 124250, .pd = 0x40, .d = 0x40 },
97 { .lomax = 132500, .pd = 0x37, .d = 0x3c },
98 { .lomax = 142000, .pd = 0x36, .d = 0x38 },
99 { .lomax = 152750, .pd = 0x35, .d = 0x34 },
100 { .lomax = 165500, .pd = 0x34, .d = 0x30 },
101 { .lomax = 180500, .pd = 0x33, .d = 0x2c },
102 { .lomax = 198750, .pd = 0x32, .d = 0x28 },
103 { .lomax = 220750, .pd = 0x31, .d = 0x24 },
104 { .lomax = 248500, .pd = 0x30, .d = 0x20 },
105 { .lomax = 265000, .pd = 0x27, .d = 0x1e },
106 { .lomax = 284000, .pd = 0x26, .d = 0x1c },
107 { .lomax = 305500, .pd = 0x25, .d = 0x1a },
108 { .lomax = 331000, .pd = 0x24, .d = 0x18 },
109 { .lomax = 361000, .pd = 0x23, .d = 0x16 },
110 { .lomax = 397500, .pd = 0x22, .d = 0x14 },
111 { .lomax = 441500, .pd = 0x21, .d = 0x12 },
112 { .lomax = 497000, .pd = 0x20, .d = 0x10 },
113 { .lomax = 530000, .pd = 0x17, .d = 0x0f },
114 { .lomax = 568000, .pd = 0x16, .d = 0x0e },
115 { .lomax = 611000, .pd = 0x15, .d = 0x0d },
116 { .lomax = 662000, .pd = 0x14, .d = 0x0c },
117 { .lomax = 722000, .pd = 0x13, .d = 0x0b },
118 { .lomax = 795000, .pd = 0x12, .d = 0x0a },
119 { .lomax = 883000, .pd = 0x11, .d = 0x09 },
120 { .lomax = 994000, .pd = 0x10, .d = 0x08 },
121 { .lomax = 0, .pd = 0x00, .d = 0x00 }, /* end */
122};
123
124static struct tda18271_pll_map tda18271c1_cal_pll[] = {
125 { .lomax = 33000, .pd = 0xdd, .d = 0xd0 },
126 { .lomax = 36000, .pd = 0xdc, .d = 0xc0 },
127 { .lomax = 40000, .pd = 0xdb, .d = 0xb0 },
128 { .lomax = 44000, .pd = 0xda, .d = 0xa0 },
129 { .lomax = 49000, .pd = 0xd9, .d = 0x90 },
130 { .lomax = 55000, .pd = 0xd8, .d = 0x80 },
131 { .lomax = 63000, .pd = 0xd3, .d = 0x70 },
132 { .lomax = 67000, .pd = 0xcd, .d = 0x68 },
133 { .lomax = 73000, .pd = 0xcc, .d = 0x60 },
134 { .lomax = 80000, .pd = 0xcb, .d = 0x58 },
135 { .lomax = 88000, .pd = 0xca, .d = 0x50 },
136 { .lomax = 98000, .pd = 0xc9, .d = 0x48 },
137 { .lomax = 110000, .pd = 0xc8, .d = 0x40 },
138 { .lomax = 126000, .pd = 0xc3, .d = 0x38 },
139 { .lomax = 135000, .pd = 0xbd, .d = 0x34 },
140 { .lomax = 147000, .pd = 0xbc, .d = 0x30 },
141 { .lomax = 160000, .pd = 0xbb, .d = 0x2c },
142 { .lomax = 176000, .pd = 0xba, .d = 0x28 },
143 { .lomax = 196000, .pd = 0xb9, .d = 0x24 },
144 { .lomax = 220000, .pd = 0xb8, .d = 0x20 },
145 { .lomax = 252000, .pd = 0xb3, .d = 0x1c },
146 { .lomax = 271000, .pd = 0xad, .d = 0x1a },
147 { .lomax = 294000, .pd = 0xac, .d = 0x18 },
148 { .lomax = 321000, .pd = 0xab, .d = 0x16 },
149 { .lomax = 353000, .pd = 0xaa, .d = 0x14 },
150 { .lomax = 392000, .pd = 0xa9, .d = 0x12 },
151 { .lomax = 441000, .pd = 0xa8, .d = 0x10 },
152 { .lomax = 505000, .pd = 0xa3, .d = 0x0e },
153 { .lomax = 543000, .pd = 0x9d, .d = 0x0d },
154 { .lomax = 589000, .pd = 0x9c, .d = 0x0c },
155 { .lomax = 642000, .pd = 0x9b, .d = 0x0b },
156 { .lomax = 707000, .pd = 0x9a, .d = 0x0a },
157 { .lomax = 785000, .pd = 0x99, .d = 0x09 },
158 { .lomax = 883000, .pd = 0x98, .d = 0x08 },
159 { .lomax = 1010000, .pd = 0x93, .d = 0x07 },
160 { .lomax = 0, .pd = 0x00, .d = 0x00 }, /* end */
161};
162
163static struct tda18271_pll_map tda18271c2_cal_pll[] = {
164 { .lomax = 33813, .pd = 0xdd, .d = 0xd0 },
165 { .lomax = 36625, .pd = 0xdc, .d = 0xc0 },
166 { .lomax = 39938, .pd = 0xdb, .d = 0xb0 },
167 { .lomax = 43938, .pd = 0xda, .d = 0xa0 },
168 { .lomax = 48813, .pd = 0xd9, .d = 0x90 },
169 { .lomax = 54938, .pd = 0xd8, .d = 0x80 },
170 { .lomax = 62813, .pd = 0xd3, .d = 0x70 },
171 { .lomax = 67625, .pd = 0xcd, .d = 0x68 },
172 { .lomax = 73250, .pd = 0xcc, .d = 0x60 },
173 { .lomax = 79875, .pd = 0xcb, .d = 0x58 },
174 { .lomax = 87875, .pd = 0xca, .d = 0x50 },
175 { .lomax = 97625, .pd = 0xc9, .d = 0x48 },
176 { .lomax = 109875, .pd = 0xc8, .d = 0x40 },
177 { .lomax = 125625, .pd = 0xc3, .d = 0x38 },
178 { .lomax = 135250, .pd = 0xbd, .d = 0x34 },
179 { .lomax = 146500, .pd = 0xbc, .d = 0x30 },
180 { .lomax = 159750, .pd = 0xbb, .d = 0x2c },
181 { .lomax = 175750, .pd = 0xba, .d = 0x28 },
182 { .lomax = 195250, .pd = 0xb9, .d = 0x24 },
183 { .lomax = 219750, .pd = 0xb8, .d = 0x20 },
184 { .lomax = 251250, .pd = 0xb3, .d = 0x1c },
185 { .lomax = 270500, .pd = 0xad, .d = 0x1a },
186 { .lomax = 293000, .pd = 0xac, .d = 0x18 },
187 { .lomax = 319500, .pd = 0xab, .d = 0x16 },
188 { .lomax = 351500, .pd = 0xaa, .d = 0x14 },
189 { .lomax = 390500, .pd = 0xa9, .d = 0x12 },
190 { .lomax = 439500, .pd = 0xa8, .d = 0x10 },
191 { .lomax = 502500, .pd = 0xa3, .d = 0x0e },
192 { .lomax = 541000, .pd = 0x9d, .d = 0x0d },
193 { .lomax = 586000, .pd = 0x9c, .d = 0x0c },
194 { .lomax = 639000, .pd = 0x9b, .d = 0x0b },
195 { .lomax = 703000, .pd = 0x9a, .d = 0x0a },
196 { .lomax = 781000, .pd = 0x99, .d = 0x09 },
197 { .lomax = 879000, .pd = 0x98, .d = 0x08 },
198 { .lomax = 0, .pd = 0x00, .d = 0x00 }, /* end */
199};
200
201static struct tda18271_map tda18271_bp_filter[] = {
202 { .rfmax = 62000, .val = 0x00 },
203 { .rfmax = 84000, .val = 0x01 },
204 { .rfmax = 100000, .val = 0x02 },
205 { .rfmax = 140000, .val = 0x03 },
206 { .rfmax = 170000, .val = 0x04 },
207 { .rfmax = 180000, .val = 0x05 },
208 { .rfmax = 865000, .val = 0x06 },
209 { .rfmax = 0, .val = 0x00 }, /* end */
210};
211
212static struct tda18271_map tda18271c1_km[] = {
213 { .rfmax = 61100, .val = 0x74 },
214 { .rfmax = 350000, .val = 0x40 },
215 { .rfmax = 720000, .val = 0x30 },
216 { .rfmax = 865000, .val = 0x40 },
217 { .rfmax = 0, .val = 0x00 }, /* end */
218};
219
220static struct tda18271_map tda18271c2_km[] = {
221 { .rfmax = 47900, .val = 0x38 },
222 { .rfmax = 61100, .val = 0x44 },
223 { .rfmax = 350000, .val = 0x30 },
224 { .rfmax = 720000, .val = 0x24 },
225 { .rfmax = 865000, .val = 0x3c },
226 { .rfmax = 0, .val = 0x00 }, /* end */
227};
228
229static struct tda18271_map tda18271_rf_band[] = {
230 { .rfmax = 47900, .val = 0x00 },
231 { .rfmax = 61100, .val = 0x01 },
232/* { .rfmax = 152600, .val = 0x02 }, */
233 { .rfmax = 121200, .val = 0x02 },
234 { .rfmax = 164700, .val = 0x03 },
235 { .rfmax = 203500, .val = 0x04 },
236 { .rfmax = 457800, .val = 0x05 },
237 { .rfmax = 865000, .val = 0x06 },
238 { .rfmax = 0, .val = 0x00 }, /* end */
239};
240
241static struct tda18271_map tda18271_gain_taper[] = {
242 { .rfmax = 45400, .val = 0x1f },
243 { .rfmax = 45800, .val = 0x1e },
244 { .rfmax = 46200, .val = 0x1d },
245 { .rfmax = 46700, .val = 0x1c },
246 { .rfmax = 47100, .val = 0x1b },
247 { .rfmax = 47500, .val = 0x1a },
248 { .rfmax = 47900, .val = 0x19 },
249 { .rfmax = 49600, .val = 0x17 },
250 { .rfmax = 51200, .val = 0x16 },
251 { .rfmax = 52900, .val = 0x15 },
252 { .rfmax = 54500, .val = 0x14 },
253 { .rfmax = 56200, .val = 0x13 },
254 { .rfmax = 57800, .val = 0x12 },
255 { .rfmax = 59500, .val = 0x11 },
256 { .rfmax = 61100, .val = 0x10 },
257 { .rfmax = 67600, .val = 0x0d },
258 { .rfmax = 74200, .val = 0x0c },
259 { .rfmax = 80700, .val = 0x0b },
260 { .rfmax = 87200, .val = 0x0a },
261 { .rfmax = 93800, .val = 0x09 },
262 { .rfmax = 100300, .val = 0x08 },
263 { .rfmax = 106900, .val = 0x07 },
264 { .rfmax = 113400, .val = 0x06 },
265 { .rfmax = 119900, .val = 0x05 },
266 { .rfmax = 126500, .val = 0x04 },
267 { .rfmax = 133000, .val = 0x03 },
268 { .rfmax = 139500, .val = 0x02 },
269 { .rfmax = 146100, .val = 0x01 },
270 { .rfmax = 152600, .val = 0x00 },
271 { .rfmax = 154300, .val = 0x1f },
272 { .rfmax = 156100, .val = 0x1e },
273 { .rfmax = 157800, .val = 0x1d },
274 { .rfmax = 159500, .val = 0x1c },
275 { .rfmax = 161200, .val = 0x1b },
276 { .rfmax = 163000, .val = 0x1a },
277 { .rfmax = 164700, .val = 0x19 },
278 { .rfmax = 170200, .val = 0x17 },
279 { .rfmax = 175800, .val = 0x16 },
280 { .rfmax = 181300, .val = 0x15 },
281 { .rfmax = 186900, .val = 0x14 },
282 { .rfmax = 192400, .val = 0x13 },
283 { .rfmax = 198000, .val = 0x12 },
284 { .rfmax = 203500, .val = 0x11 },
285 { .rfmax = 216200, .val = 0x14 },
286 { .rfmax = 228900, .val = 0x13 },
287 { .rfmax = 241600, .val = 0x12 },
288 { .rfmax = 254400, .val = 0x11 },
289 { .rfmax = 267100, .val = 0x10 },
290 { .rfmax = 279800, .val = 0x0f },
291 { .rfmax = 292500, .val = 0x0e },
292 { .rfmax = 305200, .val = 0x0d },
293 { .rfmax = 317900, .val = 0x0c },
294 { .rfmax = 330700, .val = 0x0b },
295 { .rfmax = 343400, .val = 0x0a },
296 { .rfmax = 356100, .val = 0x09 },
297 { .rfmax = 368800, .val = 0x08 },
298 { .rfmax = 381500, .val = 0x07 },
299 { .rfmax = 394200, .val = 0x06 },
300 { .rfmax = 406900, .val = 0x05 },
301 { .rfmax = 419700, .val = 0x04 },
302 { .rfmax = 432400, .val = 0x03 },
303 { .rfmax = 445100, .val = 0x02 },
304 { .rfmax = 457800, .val = 0x01 },
305 { .rfmax = 476300, .val = 0x19 },
306 { .rfmax = 494800, .val = 0x18 },
307 { .rfmax = 513300, .val = 0x17 },
308 { .rfmax = 531800, .val = 0x16 },
309 { .rfmax = 550300, .val = 0x15 },
310 { .rfmax = 568900, .val = 0x14 },
311 { .rfmax = 587400, .val = 0x13 },
312 { .rfmax = 605900, .val = 0x12 },
313 { .rfmax = 624400, .val = 0x11 },
314 { .rfmax = 642900, .val = 0x10 },
315 { .rfmax = 661400, .val = 0x0f },
316 { .rfmax = 679900, .val = 0x0e },
317 { .rfmax = 698400, .val = 0x0d },
318 { .rfmax = 716900, .val = 0x0c },
319 { .rfmax = 735400, .val = 0x0b },
320 { .rfmax = 753900, .val = 0x0a },
321 { .rfmax = 772500, .val = 0x09 },
322 { .rfmax = 791000, .val = 0x08 },
323 { .rfmax = 809500, .val = 0x07 },
324 { .rfmax = 828000, .val = 0x06 },
325 { .rfmax = 846500, .val = 0x05 },
326 { .rfmax = 865000, .val = 0x04 },
327 { .rfmax = 0, .val = 0x00 }, /* end */
328};
329
330static struct tda18271_map tda18271c1_rf_cal[] = {
331 { .rfmax = 41000, .val = 0x1e },
332 { .rfmax = 43000, .val = 0x30 },
333 { .rfmax = 45000, .val = 0x43 },
334 { .rfmax = 46000, .val = 0x4d },
335 { .rfmax = 47000, .val = 0x54 },
336 { .rfmax = 47900, .val = 0x64 },
337 { .rfmax = 49100, .val = 0x20 },
338 { .rfmax = 50000, .val = 0x22 },
339 { .rfmax = 51000, .val = 0x2a },
340 { .rfmax = 53000, .val = 0x32 },
341 { .rfmax = 55000, .val = 0x35 },
342 { .rfmax = 56000, .val = 0x3c },
343 { .rfmax = 57000, .val = 0x3f },
344 { .rfmax = 58000, .val = 0x48 },
345 { .rfmax = 59000, .val = 0x4d },
346 { .rfmax = 60000, .val = 0x58 },
347 { .rfmax = 61100, .val = 0x5f },
348 { .rfmax = 0, .val = 0x00 }, /* end */
349};
350
351static struct tda18271_map tda18271c2_rf_cal[] = {
352 { .rfmax = 41000, .val = 0x0f },
353 { .rfmax = 43000, .val = 0x1c },
354 { .rfmax = 45000, .val = 0x2f },
355 { .rfmax = 46000, .val = 0x39 },
356 { .rfmax = 47000, .val = 0x40 },
357 { .rfmax = 47900, .val = 0x50 },
358 { .rfmax = 49100, .val = 0x16 },
359 { .rfmax = 50000, .val = 0x18 },
360 { .rfmax = 51000, .val = 0x20 },
361 { .rfmax = 53000, .val = 0x28 },
362 { .rfmax = 55000, .val = 0x2b },
363 { .rfmax = 56000, .val = 0x32 },
364 { .rfmax = 57000, .val = 0x35 },
365 { .rfmax = 58000, .val = 0x3e },
366 { .rfmax = 59000, .val = 0x43 },
367 { .rfmax = 60000, .val = 0x4e },
368 { .rfmax = 61100, .val = 0x55 },
369 { .rfmax = 63000, .val = 0x0f },
370 { .rfmax = 64000, .val = 0x11 },
371 { .rfmax = 65000, .val = 0x12 },
372 { .rfmax = 66000, .val = 0x15 },
373 { .rfmax = 67000, .val = 0x16 },
374 { .rfmax = 68000, .val = 0x17 },
375 { .rfmax = 70000, .val = 0x19 },
376 { .rfmax = 71000, .val = 0x1c },
377 { .rfmax = 72000, .val = 0x1d },
378 { .rfmax = 73000, .val = 0x1f },
379 { .rfmax = 74000, .val = 0x20 },
380 { .rfmax = 75000, .val = 0x21 },
381 { .rfmax = 76000, .val = 0x24 },
382 { .rfmax = 77000, .val = 0x25 },
383 { .rfmax = 78000, .val = 0x27 },
384 { .rfmax = 80000, .val = 0x28 },
385 { .rfmax = 81000, .val = 0x29 },
386 { .rfmax = 82000, .val = 0x2d },
387 { .rfmax = 83000, .val = 0x2e },
388 { .rfmax = 84000, .val = 0x2f },
389 { .rfmax = 85000, .val = 0x31 },
390 { .rfmax = 86000, .val = 0x33 },
391 { .rfmax = 87000, .val = 0x34 },
392 { .rfmax = 88000, .val = 0x35 },
393 { .rfmax = 89000, .val = 0x37 },
394 { .rfmax = 90000, .val = 0x38 },
395 { .rfmax = 91000, .val = 0x39 },
396 { .rfmax = 93000, .val = 0x3c },
397 { .rfmax = 94000, .val = 0x3e },
398 { .rfmax = 95000, .val = 0x3f },
399 { .rfmax = 96000, .val = 0x40 },
400 { .rfmax = 97000, .val = 0x42 },
401 { .rfmax = 99000, .val = 0x45 },
402 { .rfmax = 100000, .val = 0x46 },
403 { .rfmax = 102000, .val = 0x48 },
404 { .rfmax = 103000, .val = 0x4a },
405 { .rfmax = 105000, .val = 0x4d },
406 { .rfmax = 106000, .val = 0x4e },
407 { .rfmax = 107000, .val = 0x50 },
408 { .rfmax = 108000, .val = 0x51 },
409 { .rfmax = 110000, .val = 0x54 },
410 { .rfmax = 111000, .val = 0x56 },
411 { .rfmax = 112000, .val = 0x57 },
412 { .rfmax = 113000, .val = 0x58 },
413 { .rfmax = 114000, .val = 0x59 },
414 { .rfmax = 115000, .val = 0x5c },
415 { .rfmax = 116000, .val = 0x5d },
416 { .rfmax = 117000, .val = 0x5f },
417 { .rfmax = 119000, .val = 0x60 },
418 { .rfmax = 120000, .val = 0x64 },
419 { .rfmax = 121000, .val = 0x65 },
420 { .rfmax = 122000, .val = 0x66 },
421 { .rfmax = 123000, .val = 0x68 },
422 { .rfmax = 124000, .val = 0x69 },
423 { .rfmax = 125000, .val = 0x6c },
424 { .rfmax = 126000, .val = 0x6d },
425 { .rfmax = 127000, .val = 0x6e },
426 { .rfmax = 128000, .val = 0x70 },
427 { .rfmax = 129000, .val = 0x71 },
428 { .rfmax = 130000, .val = 0x75 },
429 { .rfmax = 131000, .val = 0x77 },
430 { .rfmax = 132000, .val = 0x78 },
431 { .rfmax = 133000, .val = 0x7b },
432 { .rfmax = 134000, .val = 0x7e },
433 { .rfmax = 135000, .val = 0x81 },
434 { .rfmax = 136000, .val = 0x82 },
435 { .rfmax = 137000, .val = 0x87 },
436 { .rfmax = 138000, .val = 0x88 },
437 { .rfmax = 139000, .val = 0x8d },
438 { .rfmax = 140000, .val = 0x8e },
439 { .rfmax = 141000, .val = 0x91 },
440 { .rfmax = 142000, .val = 0x95 },
441 { .rfmax = 143000, .val = 0x9a },
442 { .rfmax = 144000, .val = 0x9d },
443 { .rfmax = 145000, .val = 0xa1 },
444 { .rfmax = 146000, .val = 0xa2 },
445 { .rfmax = 147000, .val = 0xa4 },
446 { .rfmax = 148000, .val = 0xa9 },
447 { .rfmax = 149000, .val = 0xae },
448 { .rfmax = 150000, .val = 0xb0 },
449 { .rfmax = 151000, .val = 0xb1 },
450 { .rfmax = 152000, .val = 0xb7 },
451 { .rfmax = 153000, .val = 0xbd },
452 { .rfmax = 154000, .val = 0x20 },
453 { .rfmax = 155000, .val = 0x22 },
454 { .rfmax = 156000, .val = 0x24 },
455 { .rfmax = 157000, .val = 0x25 },
456 { .rfmax = 158000, .val = 0x27 },
457 { .rfmax = 159000, .val = 0x29 },
458 { .rfmax = 160000, .val = 0x2c },
459 { .rfmax = 161000, .val = 0x2d },
460 { .rfmax = 163000, .val = 0x2e },
461 { .rfmax = 164000, .val = 0x2f },
462 { .rfmax = 165000, .val = 0x30 },
463 { .rfmax = 166000, .val = 0x11 },
464 { .rfmax = 167000, .val = 0x12 },
465 { .rfmax = 168000, .val = 0x13 },
466 { .rfmax = 169000, .val = 0x14 },
467 { .rfmax = 170000, .val = 0x15 },
468 { .rfmax = 172000, .val = 0x16 },
469 { .rfmax = 173000, .val = 0x17 },
470 { .rfmax = 174000, .val = 0x18 },
471 { .rfmax = 175000, .val = 0x1a },
472 { .rfmax = 176000, .val = 0x1b },
473 { .rfmax = 178000, .val = 0x1d },
474 { .rfmax = 179000, .val = 0x1e },
475 { .rfmax = 180000, .val = 0x1f },
476 { .rfmax = 181000, .val = 0x20 },
477 { .rfmax = 182000, .val = 0x21 },
478 { .rfmax = 183000, .val = 0x22 },
479 { .rfmax = 184000, .val = 0x24 },
480 { .rfmax = 185000, .val = 0x25 },
481 { .rfmax = 186000, .val = 0x26 },
482 { .rfmax = 187000, .val = 0x27 },
483 { .rfmax = 188000, .val = 0x29 },
484 { .rfmax = 189000, .val = 0x2a },
485 { .rfmax = 190000, .val = 0x2c },
486 { .rfmax = 191000, .val = 0x2d },
487 { .rfmax = 192000, .val = 0x2e },
488 { .rfmax = 193000, .val = 0x2f },
489 { .rfmax = 194000, .val = 0x30 },
490 { .rfmax = 195000, .val = 0x33 },
491 { .rfmax = 196000, .val = 0x35 },
492 { .rfmax = 198000, .val = 0x36 },
493 { .rfmax = 200000, .val = 0x38 },
494 { .rfmax = 201000, .val = 0x3c },
495 { .rfmax = 202000, .val = 0x3d },
496 { .rfmax = 203500, .val = 0x3e },
497 { .rfmax = 206000, .val = 0x0e },
498 { .rfmax = 208000, .val = 0x0f },
499 { .rfmax = 212000, .val = 0x10 },
500 { .rfmax = 216000, .val = 0x11 },
501 { .rfmax = 217000, .val = 0x12 },
502 { .rfmax = 218000, .val = 0x13 },
503 { .rfmax = 220000, .val = 0x14 },
504 { .rfmax = 222000, .val = 0x15 },
505 { .rfmax = 225000, .val = 0x16 },
506 { .rfmax = 228000, .val = 0x17 },
507 { .rfmax = 231000, .val = 0x18 },
508 { .rfmax = 234000, .val = 0x19 },
509 { .rfmax = 235000, .val = 0x1a },
510 { .rfmax = 236000, .val = 0x1b },
511 { .rfmax = 237000, .val = 0x1c },
512 { .rfmax = 240000, .val = 0x1d },
513 { .rfmax = 242000, .val = 0x1f },
514 { .rfmax = 247000, .val = 0x20 },
515 { .rfmax = 249000, .val = 0x21 },
516 { .rfmax = 252000, .val = 0x22 },
517 { .rfmax = 253000, .val = 0x23 },
518 { .rfmax = 254000, .val = 0x24 },
519 { .rfmax = 256000, .val = 0x25 },
520 { .rfmax = 259000, .val = 0x26 },
521 { .rfmax = 262000, .val = 0x27 },
522 { .rfmax = 264000, .val = 0x28 },
523 { .rfmax = 267000, .val = 0x29 },
524 { .rfmax = 269000, .val = 0x2a },
525 { .rfmax = 271000, .val = 0x2b },
526 { .rfmax = 273000, .val = 0x2c },
527 { .rfmax = 275000, .val = 0x2d },
528 { .rfmax = 277000, .val = 0x2e },
529 { .rfmax = 279000, .val = 0x2f },
530 { .rfmax = 282000, .val = 0x30 },
531 { .rfmax = 284000, .val = 0x31 },
532 { .rfmax = 286000, .val = 0x32 },
533 { .rfmax = 287000, .val = 0x33 },
534 { .rfmax = 290000, .val = 0x34 },
535 { .rfmax = 293000, .val = 0x35 },
536 { .rfmax = 295000, .val = 0x36 },
537 { .rfmax = 297000, .val = 0x37 },
538 { .rfmax = 300000, .val = 0x38 },
539 { .rfmax = 303000, .val = 0x39 },
540 { .rfmax = 305000, .val = 0x3a },
541 { .rfmax = 306000, .val = 0x3b },
542 { .rfmax = 307000, .val = 0x3c },
543 { .rfmax = 310000, .val = 0x3d },
544 { .rfmax = 312000, .val = 0x3e },
545 { .rfmax = 315000, .val = 0x3f },
546 { .rfmax = 318000, .val = 0x40 },
547 { .rfmax = 320000, .val = 0x41 },
548 { .rfmax = 323000, .val = 0x42 },
549 { .rfmax = 324000, .val = 0x43 },
550 { .rfmax = 325000, .val = 0x44 },
551 { .rfmax = 327000, .val = 0x45 },
552 { .rfmax = 331000, .val = 0x46 },
553 { .rfmax = 334000, .val = 0x47 },
554 { .rfmax = 337000, .val = 0x48 },
555 { .rfmax = 339000, .val = 0x49 },
556 { .rfmax = 340000, .val = 0x4a },
557 { .rfmax = 341000, .val = 0x4b },
558 { .rfmax = 343000, .val = 0x4c },
559 { .rfmax = 345000, .val = 0x4d },
560 { .rfmax = 349000, .val = 0x4e },
561 { .rfmax = 352000, .val = 0x4f },
562 { .rfmax = 353000, .val = 0x50 },
563 { .rfmax = 355000, .val = 0x51 },
564 { .rfmax = 357000, .val = 0x52 },
565 { .rfmax = 359000, .val = 0x53 },
566 { .rfmax = 361000, .val = 0x54 },
567 { .rfmax = 362000, .val = 0x55 },
568 { .rfmax = 364000, .val = 0x56 },
569 { .rfmax = 368000, .val = 0x57 },
570 { .rfmax = 370000, .val = 0x58 },
571 { .rfmax = 372000, .val = 0x59 },
572 { .rfmax = 375000, .val = 0x5a },
573 { .rfmax = 376000, .val = 0x5b },
574 { .rfmax = 377000, .val = 0x5c },
575 { .rfmax = 379000, .val = 0x5d },
576 { .rfmax = 382000, .val = 0x5e },
577 { .rfmax = 384000, .val = 0x5f },
578 { .rfmax = 385000, .val = 0x60 },
579 { .rfmax = 386000, .val = 0x61 },
580 { .rfmax = 388000, .val = 0x62 },
581 { .rfmax = 390000, .val = 0x63 },
582 { .rfmax = 393000, .val = 0x64 },
583 { .rfmax = 394000, .val = 0x65 },
584 { .rfmax = 396000, .val = 0x66 },
585 { .rfmax = 397000, .val = 0x67 },
586 { .rfmax = 398000, .val = 0x68 },
587 { .rfmax = 400000, .val = 0x69 },
588 { .rfmax = 402000, .val = 0x6a },
589 { .rfmax = 403000, .val = 0x6b },
590 { .rfmax = 407000, .val = 0x6c },
591 { .rfmax = 408000, .val = 0x6d },
592 { .rfmax = 409000, .val = 0x6e },
593 { .rfmax = 410000, .val = 0x6f },
594 { .rfmax = 411000, .val = 0x70 },
595 { .rfmax = 412000, .val = 0x71 },
596 { .rfmax = 413000, .val = 0x72 },
597 { .rfmax = 414000, .val = 0x73 },
598 { .rfmax = 417000, .val = 0x74 },
599 { .rfmax = 418000, .val = 0x75 },
600 { .rfmax = 420000, .val = 0x76 },
601 { .rfmax = 422000, .val = 0x77 },
602 { .rfmax = 423000, .val = 0x78 },
603 { .rfmax = 424000, .val = 0x79 },
604 { .rfmax = 427000, .val = 0x7a },
605 { .rfmax = 428000, .val = 0x7b },
606 { .rfmax = 429000, .val = 0x7d },
607 { .rfmax = 432000, .val = 0x7f },
608 { .rfmax = 434000, .val = 0x80 },
609 { .rfmax = 435000, .val = 0x81 },
610 { .rfmax = 436000, .val = 0x83 },
611 { .rfmax = 437000, .val = 0x84 },
612 { .rfmax = 438000, .val = 0x85 },
613 { .rfmax = 439000, .val = 0x86 },
614 { .rfmax = 440000, .val = 0x87 },
615 { .rfmax = 441000, .val = 0x88 },
616 { .rfmax = 442000, .val = 0x89 },
617 { .rfmax = 445000, .val = 0x8a },
618 { .rfmax = 446000, .val = 0x8b },
619 { .rfmax = 447000, .val = 0x8c },
620 { .rfmax = 448000, .val = 0x8e },
621 { .rfmax = 449000, .val = 0x8f },
622 { .rfmax = 450000, .val = 0x90 },
623 { .rfmax = 452000, .val = 0x91 },
624 { .rfmax = 453000, .val = 0x93 },
625 { .rfmax = 454000, .val = 0x94 },
626 { .rfmax = 456000, .val = 0x96 },
627 { .rfmax = 457000, .val = 0x98 },
628 { .rfmax = 461000, .val = 0x11 },
629 { .rfmax = 468000, .val = 0x12 },
630 { .rfmax = 472000, .val = 0x13 },
631 { .rfmax = 473000, .val = 0x14 },
632 { .rfmax = 474000, .val = 0x15 },
633 { .rfmax = 481000, .val = 0x16 },
634 { .rfmax = 486000, .val = 0x17 },
635 { .rfmax = 491000, .val = 0x18 },
636 { .rfmax = 498000, .val = 0x19 },
637 { .rfmax = 499000, .val = 0x1a },
638 { .rfmax = 501000, .val = 0x1b },
639 { .rfmax = 506000, .val = 0x1c },
640 { .rfmax = 511000, .val = 0x1d },
641 { .rfmax = 516000, .val = 0x1e },
642 { .rfmax = 520000, .val = 0x1f },
643 { .rfmax = 521000, .val = 0x20 },
644 { .rfmax = 525000, .val = 0x21 },
645 { .rfmax = 529000, .val = 0x22 },
646 { .rfmax = 533000, .val = 0x23 },
647 { .rfmax = 539000, .val = 0x24 },
648 { .rfmax = 541000, .val = 0x25 },
649 { .rfmax = 547000, .val = 0x26 },
650 { .rfmax = 549000, .val = 0x27 },
651 { .rfmax = 551000, .val = 0x28 },
652 { .rfmax = 556000, .val = 0x29 },
653 { .rfmax = 561000, .val = 0x2a },
654 { .rfmax = 563000, .val = 0x2b },
655 { .rfmax = 565000, .val = 0x2c },
656 { .rfmax = 569000, .val = 0x2d },
657 { .rfmax = 571000, .val = 0x2e },
658 { .rfmax = 577000, .val = 0x2f },
659 { .rfmax = 580000, .val = 0x30 },
660 { .rfmax = 582000, .val = 0x31 },
661 { .rfmax = 584000, .val = 0x32 },
662 { .rfmax = 588000, .val = 0x33 },
663 { .rfmax = 591000, .val = 0x34 },
664 { .rfmax = 596000, .val = 0x35 },
665 { .rfmax = 598000, .val = 0x36 },
666 { .rfmax = 603000, .val = 0x37 },
667 { .rfmax = 604000, .val = 0x38 },
668 { .rfmax = 606000, .val = 0x39 },
669 { .rfmax = 612000, .val = 0x3a },
670 { .rfmax = 615000, .val = 0x3b },
671 { .rfmax = 617000, .val = 0x3c },
672 { .rfmax = 621000, .val = 0x3d },
673 { .rfmax = 622000, .val = 0x3e },
674 { .rfmax = 625000, .val = 0x3f },
675 { .rfmax = 632000, .val = 0x40 },
676 { .rfmax = 633000, .val = 0x41 },
677 { .rfmax = 634000, .val = 0x42 },
678 { .rfmax = 642000, .val = 0x43 },
679 { .rfmax = 643000, .val = 0x44 },
680 { .rfmax = 647000, .val = 0x45 },
681 { .rfmax = 650000, .val = 0x46 },
682 { .rfmax = 652000, .val = 0x47 },
683 { .rfmax = 657000, .val = 0x48 },
684 { .rfmax = 661000, .val = 0x49 },
685 { .rfmax = 662000, .val = 0x4a },
686 { .rfmax = 665000, .val = 0x4b },
687 { .rfmax = 667000, .val = 0x4c },
688 { .rfmax = 670000, .val = 0x4d },
689 { .rfmax = 673000, .val = 0x4e },
690 { .rfmax = 676000, .val = 0x4f },
691 { .rfmax = 677000, .val = 0x50 },
692 { .rfmax = 681000, .val = 0x51 },
693 { .rfmax = 683000, .val = 0x52 },
694 { .rfmax = 686000, .val = 0x53 },
695 { .rfmax = 688000, .val = 0x54 },
696 { .rfmax = 689000, .val = 0x55 },
697 { .rfmax = 691000, .val = 0x56 },
698 { .rfmax = 695000, .val = 0x57 },
699 { .rfmax = 698000, .val = 0x58 },
700 { .rfmax = 703000, .val = 0x59 },
701 { .rfmax = 704000, .val = 0x5a },
702 { .rfmax = 705000, .val = 0x5b },
703 { .rfmax = 707000, .val = 0x5c },
704 { .rfmax = 710000, .val = 0x5d },
705 { .rfmax = 712000, .val = 0x5e },
706 { .rfmax = 717000, .val = 0x5f },
707 { .rfmax = 718000, .val = 0x60 },
708 { .rfmax = 721000, .val = 0x61 },
709 { .rfmax = 722000, .val = 0x62 },
710 { .rfmax = 723000, .val = 0x63 },
711 { .rfmax = 725000, .val = 0x64 },
712 { .rfmax = 727000, .val = 0x65 },
713 { .rfmax = 730000, .val = 0x66 },
714 { .rfmax = 732000, .val = 0x67 },
715 { .rfmax = 735000, .val = 0x68 },
716 { .rfmax = 740000, .val = 0x69 },
717 { .rfmax = 741000, .val = 0x6a },
718 { .rfmax = 742000, .val = 0x6b },
719 { .rfmax = 743000, .val = 0x6c },
720 { .rfmax = 745000, .val = 0x6d },
721 { .rfmax = 747000, .val = 0x6e },
722 { .rfmax = 748000, .val = 0x6f },
723 { .rfmax = 750000, .val = 0x70 },
724 { .rfmax = 752000, .val = 0x71 },
725 { .rfmax = 754000, .val = 0x72 },
726 { .rfmax = 757000, .val = 0x73 },
727 { .rfmax = 758000, .val = 0x74 },
728 { .rfmax = 760000, .val = 0x75 },
729 { .rfmax = 763000, .val = 0x76 },
730 { .rfmax = 764000, .val = 0x77 },
731 { .rfmax = 766000, .val = 0x78 },
732 { .rfmax = 767000, .val = 0x79 },
733 { .rfmax = 768000, .val = 0x7a },
734 { .rfmax = 773000, .val = 0x7b },
735 { .rfmax = 774000, .val = 0x7c },
736 { .rfmax = 776000, .val = 0x7d },
737 { .rfmax = 777000, .val = 0x7e },
738 { .rfmax = 778000, .val = 0x7f },
739 { .rfmax = 779000, .val = 0x80 },
740 { .rfmax = 781000, .val = 0x81 },
741 { .rfmax = 783000, .val = 0x82 },
742 { .rfmax = 784000, .val = 0x83 },
743 { .rfmax = 785000, .val = 0x84 },
744 { .rfmax = 786000, .val = 0x85 },
745 { .rfmax = 793000, .val = 0x86 },
746 { .rfmax = 794000, .val = 0x87 },
747 { .rfmax = 795000, .val = 0x88 },
748 { .rfmax = 797000, .val = 0x89 },
749 { .rfmax = 799000, .val = 0x8a },
750 { .rfmax = 801000, .val = 0x8b },
751 { .rfmax = 802000, .val = 0x8c },
752 { .rfmax = 803000, .val = 0x8d },
753 { .rfmax = 804000, .val = 0x8e },
754 { .rfmax = 810000, .val = 0x90 },
755 { .rfmax = 811000, .val = 0x91 },
756 { .rfmax = 812000, .val = 0x92 },
757 { .rfmax = 814000, .val = 0x93 },
758 { .rfmax = 816000, .val = 0x94 },
759 { .rfmax = 817000, .val = 0x96 },
760 { .rfmax = 818000, .val = 0x97 },
761 { .rfmax = 820000, .val = 0x98 },
762 { .rfmax = 821000, .val = 0x99 },
763 { .rfmax = 822000, .val = 0x9a },
764 { .rfmax = 828000, .val = 0x9b },
765 { .rfmax = 829000, .val = 0x9d },
766 { .rfmax = 830000, .val = 0x9f },
767 { .rfmax = 831000, .val = 0xa0 },
768 { .rfmax = 833000, .val = 0xa1 },
769 { .rfmax = 835000, .val = 0xa2 },
770 { .rfmax = 836000, .val = 0xa3 },
771 { .rfmax = 837000, .val = 0xa4 },
772 { .rfmax = 838000, .val = 0xa6 },
773 { .rfmax = 840000, .val = 0xa8 },
774 { .rfmax = 842000, .val = 0xa9 },
775 { .rfmax = 845000, .val = 0xaa },
776 { .rfmax = 846000, .val = 0xab },
777 { .rfmax = 847000, .val = 0xad },
778 { .rfmax = 848000, .val = 0xae },
779 { .rfmax = 852000, .val = 0xaf },
780 { .rfmax = 853000, .val = 0xb0 },
781 { .rfmax = 858000, .val = 0xb1 },
782 { .rfmax = 860000, .val = 0xb2 },
783 { .rfmax = 861000, .val = 0xb3 },
784 { .rfmax = 862000, .val = 0xb4 },
785 { .rfmax = 863000, .val = 0xb6 },
786 { .rfmax = 864000, .val = 0xb8 },
787 { .rfmax = 865000, .val = 0xb9 },
788 { .rfmax = 0, .val = 0x00 }, /* end */
789};
790
791static struct tda18271_map tda18271_ir_measure[] = {
792 { .rfmax = 30000, .val = 4 },
793 { .rfmax = 200000, .val = 5 },
794 { .rfmax = 600000, .val = 6 },
795 { .rfmax = 865000, .val = 7 },
796 { .rfmax = 0, .val = 0 }, /* end */
797};
798
799static struct tda18271_map tda18271_rf_cal_dc_over_dt[] = {
800 { .rfmax = 47900, .val = 0x00 },
801 { .rfmax = 55000, .val = 0x00 },
802 { .rfmax = 61100, .val = 0x0a },
803 { .rfmax = 64000, .val = 0x0a },
804 { .rfmax = 82000, .val = 0x14 },
805 { .rfmax = 84000, .val = 0x19 },
806 { .rfmax = 119000, .val = 0x1c },
807 { .rfmax = 124000, .val = 0x20 },
808 { .rfmax = 129000, .val = 0x2a },
809 { .rfmax = 134000, .val = 0x32 },
810 { .rfmax = 139000, .val = 0x39 },
811 { .rfmax = 144000, .val = 0x3e },
812 { .rfmax = 149000, .val = 0x3f },
813 { .rfmax = 152600, .val = 0x40 },
814 { .rfmax = 154000, .val = 0x40 },
815 { .rfmax = 164700, .val = 0x41 },
816 { .rfmax = 203500, .val = 0x32 },
817 { .rfmax = 353000, .val = 0x19 },
818 { .rfmax = 356000, .val = 0x1a },
819 { .rfmax = 359000, .val = 0x1b },
820 { .rfmax = 363000, .val = 0x1c },
821 { .rfmax = 366000, .val = 0x1d },
822 { .rfmax = 369000, .val = 0x1e },
823 { .rfmax = 373000, .val = 0x1f },
824 { .rfmax = 376000, .val = 0x20 },
825 { .rfmax = 379000, .val = 0x21 },
826 { .rfmax = 383000, .val = 0x22 },
827 { .rfmax = 386000, .val = 0x23 },
828 { .rfmax = 389000, .val = 0x24 },
829 { .rfmax = 393000, .val = 0x25 },
830 { .rfmax = 396000, .val = 0x26 },
831 { .rfmax = 399000, .val = 0x27 },
832 { .rfmax = 402000, .val = 0x28 },
833 { .rfmax = 404000, .val = 0x29 },
834 { .rfmax = 407000, .val = 0x2a },
835 { .rfmax = 409000, .val = 0x2b },
836 { .rfmax = 412000, .val = 0x2c },
837 { .rfmax = 414000, .val = 0x2d },
838 { .rfmax = 417000, .val = 0x2e },
839 { .rfmax = 419000, .val = 0x2f },
840 { .rfmax = 422000, .val = 0x30 },
841 { .rfmax = 424000, .val = 0x31 },
842 { .rfmax = 427000, .val = 0x32 },
843 { .rfmax = 429000, .val = 0x33 },
844 { .rfmax = 432000, .val = 0x34 },
845 { .rfmax = 434000, .val = 0x35 },
846 { .rfmax = 437000, .val = 0x36 },
847 { .rfmax = 439000, .val = 0x37 },
848 { .rfmax = 442000, .val = 0x38 },
849 { .rfmax = 444000, .val = 0x39 },
850 { .rfmax = 447000, .val = 0x3a },
851 { .rfmax = 449000, .val = 0x3b },
852 { .rfmax = 457800, .val = 0x3c },
853 { .rfmax = 465000, .val = 0x0f },
854 { .rfmax = 477000, .val = 0x12 },
855 { .rfmax = 483000, .val = 0x14 },
856 { .rfmax = 502000, .val = 0x19 },
857 { .rfmax = 508000, .val = 0x1b },
858 { .rfmax = 519000, .val = 0x1c },
859 { .rfmax = 522000, .val = 0x1d },
860 { .rfmax = 524000, .val = 0x1e },
861 { .rfmax = 534000, .val = 0x1f },
862 { .rfmax = 549000, .val = 0x20 },
863 { .rfmax = 554000, .val = 0x22 },
864 { .rfmax = 584000, .val = 0x24 },
865 { .rfmax = 589000, .val = 0x26 },
866 { .rfmax = 658000, .val = 0x27 },
867 { .rfmax = 664000, .val = 0x2c },
868 { .rfmax = 669000, .val = 0x2d },
869 { .rfmax = 699000, .val = 0x2e },
870 { .rfmax = 704000, .val = 0x30 },
871 { .rfmax = 709000, .val = 0x31 },
872 { .rfmax = 714000, .val = 0x32 },
873 { .rfmax = 724000, .val = 0x33 },
874 { .rfmax = 729000, .val = 0x36 },
875 { .rfmax = 739000, .val = 0x38 },
876 { .rfmax = 744000, .val = 0x39 },
877 { .rfmax = 749000, .val = 0x3b },
878 { .rfmax = 754000, .val = 0x3c },
879 { .rfmax = 759000, .val = 0x3d },
880 { .rfmax = 764000, .val = 0x3e },
881 { .rfmax = 769000, .val = 0x3f },
882 { .rfmax = 774000, .val = 0x40 },
883 { .rfmax = 779000, .val = 0x41 },
884 { .rfmax = 784000, .val = 0x43 },
885 { .rfmax = 789000, .val = 0x46 },
886 { .rfmax = 794000, .val = 0x48 },
887 { .rfmax = 799000, .val = 0x4b },
888 { .rfmax = 804000, .val = 0x4f },
889 { .rfmax = 809000, .val = 0x54 },
890 { .rfmax = 814000, .val = 0x59 },
891 { .rfmax = 819000, .val = 0x5d },
892 { .rfmax = 824000, .val = 0x61 },
893 { .rfmax = 829000, .val = 0x68 },
894 { .rfmax = 834000, .val = 0x6e },
895 { .rfmax = 839000, .val = 0x75 },
896 { .rfmax = 844000, .val = 0x7e },
897 { .rfmax = 849000, .val = 0x82 },
898 { .rfmax = 854000, .val = 0x84 },
899 { .rfmax = 859000, .val = 0x8f },
900 { .rfmax = 865000, .val = 0x9a },
901 { .rfmax = 0, .val = 0x00 }, /* end */
902};
903
904/*---------------------------------------------------------------------*/
905
906struct tda18271_thermo_map {
907 u8 d;
908 u8 r0;
909 u8 r1;
910};
911
912static struct tda18271_thermo_map tda18271_thermometer[] = {
913 { .d = 0x00, .r0 = 60, .r1 = 92 },
914 { .d = 0x01, .r0 = 62, .r1 = 94 },
915 { .d = 0x02, .r0 = 66, .r1 = 98 },
916 { .d = 0x03, .r0 = 64, .r1 = 96 },
917 { .d = 0x04, .r0 = 74, .r1 = 106 },
918 { .d = 0x05, .r0 = 72, .r1 = 104 },
919 { .d = 0x06, .r0 = 68, .r1 = 100 },
920 { .d = 0x07, .r0 = 70, .r1 = 102 },
921 { .d = 0x08, .r0 = 90, .r1 = 122 },
922 { .d = 0x09, .r0 = 88, .r1 = 120 },
923 { .d = 0x0a, .r0 = 84, .r1 = 116 },
924 { .d = 0x0b, .r0 = 86, .r1 = 118 },
925 { .d = 0x0c, .r0 = 76, .r1 = 108 },
926 { .d = 0x0d, .r0 = 78, .r1 = 110 },
927 { .d = 0x0e, .r0 = 82, .r1 = 114 },
928 { .d = 0x0f, .r0 = 80, .r1 = 112 },
929 { .d = 0x00, .r0 = 0, .r1 = 0 }, /* end */
930};
931
932int tda18271_lookup_thermometer(struct dvb_frontend *fe)
933{
934 struct tda18271_priv *priv = fe->tuner_priv;
935 unsigned char *regs = priv->tda18271_regs;
936 int val, i = 0;
937
938 while (tda18271_thermometer[i].d < (regs[R_TM] & 0x0f)) {
939 if (tda18271_thermometer[i + 1].d == 0)
940 break;
941 i++;
942 }
943
944 if ((regs[R_TM] & 0x20) == 0x20)
945 val = tda18271_thermometer[i].r1;
946 else
947 val = tda18271_thermometer[i].r0;
948
949 tda_map("(%d) tm = %d\n", i, val);
950
951 return val;
952}
953
954/*---------------------------------------------------------------------*/
955
956struct tda18271_cid_target_map {
957 u32 rfmax;
958 u8 target;
959 u16 limit;
960};
961
962static struct tda18271_cid_target_map tda18271_cid_target[] = {
963 { .rfmax = 46000, .target = 0x04, .limit = 1800 },
964 { .rfmax = 52200, .target = 0x0a, .limit = 1500 },
965 { .rfmax = 79100, .target = 0x01, .limit = 4000 },
966 { .rfmax = 136800, .target = 0x18, .limit = 4000 },
967 { .rfmax = 156700, .target = 0x18, .limit = 4000 },
968 { .rfmax = 156700, .target = 0x18, .limit = 4000 },
969 { .rfmax = 186250, .target = 0x0a, .limit = 4000 },
970 { .rfmax = 230000, .target = 0x0a, .limit = 4000 },
971 { .rfmax = 345000, .target = 0x18, .limit = 4000 },
972 { .rfmax = 426000, .target = 0x0e, .limit = 4000 },
973 { .rfmax = 489500, .target = 0x1e, .limit = 4000 },
974 { .rfmax = 697500, .target = 0x32, .limit = 4000 },
975 { .rfmax = 842000, .target = 0x3a, .limit = 4000 },
976 { .rfmax = 0, .target = 0x00, .limit = 0 }, /* end */
977};
978
979int tda18271_lookup_cid_target(struct dvb_frontend *fe,
980 u32 *freq, u8 *cid_target, u16 *count_limit)
981{
982 int i = 0;
983
984 while ((tda18271_cid_target[i].rfmax * 1000) < *freq) {
985 if (tda18271_cid_target[i + 1].rfmax == 0)
986 break;
987 i++;
988 }
989 *cid_target = tda18271_cid_target[i].target;
990 *count_limit = tda18271_cid_target[i].limit;
991
992 tda_map("(%d) cid_target = %02x, count_limit = %d\n", i,
993 tda18271_cid_target[i].target, tda18271_cid_target[i].limit);
994
995 return 0;
996}
997
998/*---------------------------------------------------------------------*/
999
1000static struct tda18271_rf_tracking_filter_cal tda18271_rf_band_template[] = {
1001 { .rfmax = 47900, .rfband = 0x00,
1002 .rf1_def = 46000, .rf2_def = 0, .rf3_def = 0 },
1003 { .rfmax = 61100, .rfband = 0x01,
1004 .rf1_def = 52200, .rf2_def = 0, .rf3_def = 0 },
1005 { .rfmax = 152600, .rfband = 0x02,
1006 .rf1_def = 70100, .rf2_def = 136800, .rf3_def = 0 },
1007 { .rfmax = 164700, .rfband = 0x03,
1008 .rf1_def = 156700, .rf2_def = 0, .rf3_def = 0 },
1009 { .rfmax = 203500, .rfband = 0x04,
1010 .rf1_def = 186250, .rf2_def = 0, .rf3_def = 0 },
1011 { .rfmax = 457800, .rfband = 0x05,
1012 .rf1_def = 230000, .rf2_def = 345000, .rf3_def = 426000 },
1013 { .rfmax = 865000, .rfband = 0x06,
1014 .rf1_def = 489500, .rf2_def = 697500, .rf3_def = 842000 },
1015 { .rfmax = 0, .rfband = 0x00,
1016 .rf1_def = 0, .rf2_def = 0, .rf3_def = 0 }, /* end */
1017};
1018
1019int tda18271_lookup_rf_band(struct dvb_frontend *fe, u32 *freq, u8 *rf_band)
1020{
1021 struct tda18271_priv *priv = fe->tuner_priv;
1022 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state;
1023 int i = 0;
1024
1025 while ((map[i].rfmax * 1000) < *freq) {
1026 if (tda18271_debug & DBG_ADV)
1027 tda_map("(%d) rfmax = %d < freq = %d, "
1028 "rf1_def = %d, rf2_def = %d, rf3_def = %d, "
1029 "rf1 = %d, rf2 = %d, rf3 = %d, "
1030 "rf_a1 = %d, rf_a2 = %d, "
1031 "rf_b1 = %d, rf_b2 = %d\n",
1032 i, map[i].rfmax * 1000, *freq,
1033 map[i].rf1_def, map[i].rf2_def, map[i].rf3_def,
1034 map[i].rf1, map[i].rf2, map[i].rf3,
1035 map[i].rf_a1, map[i].rf_a2,
1036 map[i].rf_b1, map[i].rf_b2);
1037 if (map[i].rfmax == 0)
1038 return -EINVAL;
1039 i++;
1040 }
1041 if (rf_band)
1042 *rf_band = map[i].rfband;
1043
1044 tda_map("(%d) rf_band = %02x\n", i, map[i].rfband);
1045
1046 return i;
1047}
1048
1049/*---------------------------------------------------------------------*/
1050
1051struct tda18271_map_layout {
1052 struct tda18271_pll_map *main_pll;
1053 struct tda18271_pll_map *cal_pll;
1054
1055 struct tda18271_map *rf_cal;
1056 struct tda18271_map *rf_cal_kmco;
1057 struct tda18271_map *rf_cal_dc_over_dt;
1058
1059 struct tda18271_map *bp_filter;
1060 struct tda18271_map *rf_band;
1061 struct tda18271_map *gain_taper;
1062 struct tda18271_map *ir_measure;
1063};
1064
1065/*---------------------------------------------------------------------*/
1066
1067int tda18271_lookup_pll_map(struct dvb_frontend *fe,
1068 enum tda18271_map_type map_type,
1069 u32 *freq, u8 *post_div, u8 *div)
1070{
1071 struct tda18271_priv *priv = fe->tuner_priv;
1072 struct tda18271_pll_map *map = NULL;
1073 unsigned int i = 0;
1074 char *map_name;
1075 int ret = 0;
1076
1077 BUG_ON(!priv->maps);
1078
1079 switch (map_type) {
1080 case MAIN_PLL:
1081 map = priv->maps->main_pll;
1082 map_name = "main_pll";
1083 break;
1084 case CAL_PLL:
1085 map = priv->maps->cal_pll;
1086 map_name = "cal_pll";
1087 break;
1088 default:
1089 /* we should never get here */
1090 map_name = "undefined";
1091 break;
1092 }
1093
1094 if (!map) {
1095 tda_warn("%s map is not set!\n", map_name);
1096 ret = -EINVAL;
1097 goto fail;
1098 }
1099
1100 while ((map[i].lomax * 1000) < *freq) {
1101 if (map[i + 1].lomax == 0) {
1102 tda_map("%s: frequency (%d) out of range\n",
1103 map_name, *freq);
1104 ret = -ERANGE;
1105 break;
1106 }
1107 i++;
1108 }
1109 *post_div = map[i].pd;
1110 *div = map[i].d;
1111
1112 tda_map("(%d) %s: post div = 0x%02x, div = 0x%02x\n",
1113 i, map_name, *post_div, *div);
1114fail:
1115 return ret;
1116}
1117
1118int tda18271_lookup_map(struct dvb_frontend *fe,
1119 enum tda18271_map_type map_type,
1120 u32 *freq, u8 *val)
1121{
1122 struct tda18271_priv *priv = fe->tuner_priv;
1123 struct tda18271_map *map = NULL;
1124 unsigned int i = 0;
1125 char *map_name;
1126 int ret = 0;
1127
1128 BUG_ON(!priv->maps);
1129
1130 switch (map_type) {
1131 case BP_FILTER:
1132 map = priv->maps->bp_filter;
1133 map_name = "bp_filter";
1134 break;
1135 case RF_CAL_KMCO:
1136 map = priv->maps->rf_cal_kmco;
1137 map_name = "km";
1138 break;
1139 case RF_BAND:
1140 map = priv->maps->rf_band;
1141 map_name = "rf_band";
1142 break;
1143 case GAIN_TAPER:
1144 map = priv->maps->gain_taper;
1145 map_name = "gain_taper";
1146 break;
1147 case RF_CAL:
1148 map = priv->maps->rf_cal;
1149 map_name = "rf_cal";
1150 break;
1151 case IR_MEASURE:
1152 map = priv->maps->ir_measure;
1153 map_name = "ir_measure";
1154 break;
1155 case RF_CAL_DC_OVER_DT:
1156 map = priv->maps->rf_cal_dc_over_dt;
1157 map_name = "rf_cal_dc_over_dt";
1158 break;
1159 default:
1160 /* we should never get here */
1161 map_name = "undefined";
1162 break;
1163 }
1164
1165 if (!map) {
1166 tda_warn("%s map is not set!\n", map_name);
1167 ret = -EINVAL;
1168 goto fail;
1169 }
1170
1171 while ((map[i].rfmax * 1000) < *freq) {
1172 if (map[i + 1].rfmax == 0) {
1173 tda_map("%s: frequency (%d) out of range\n",
1174 map_name, *freq);
1175 ret = -ERANGE;
1176 break;
1177 }
1178 i++;
1179 }
1180 *val = map[i].val;
1181
1182 tda_map("(%d) %s: 0x%02x\n", i, map_name, *val);
1183fail:
1184 return ret;
1185}
1186
1187/*---------------------------------------------------------------------*/
1188
1189static struct tda18271_std_map tda18271c1_std_map = {
1190 .fm_radio = { .if_freq = 1250, .std_bits = 0x18 },
1191 .atv_b = { .if_freq = 6750, .std_bits = 0x0e },
1192 .atv_dk = { .if_freq = 7750, .std_bits = 0x0f },
1193 .atv_gh = { .if_freq = 7750, .std_bits = 0x0f },
1194 .atv_i = { .if_freq = 7750, .std_bits = 0x0f },
1195 .atv_l = { .if_freq = 7750, .std_bits = 0x0f },
1196 .atv_lc = { .if_freq = 1250, .std_bits = 0x0f },
1197 .atv_mn = { .if_freq = 5750, .std_bits = 0x0d },
1198 .atsc_6 = { .if_freq = 3250, .std_bits = 0x1c },
1199 .dvbt_6 = { .if_freq = 3300, .std_bits = 0x1c },
1200 .dvbt_7 = { .if_freq = 3800, .std_bits = 0x1d },
1201 .dvbt_8 = { .if_freq = 4300, .std_bits = 0x1e },
1202 .qam_6 = { .if_freq = 4000, .std_bits = 0x1d },
1203 .qam_8 = { .if_freq = 5000, .std_bits = 0x1f },
1204};
1205
1206static struct tda18271_std_map tda18271c2_std_map = {
1207 .fm_radio = { .if_freq = 1250, .std_bits = 0x18 },
1208 .atv_b = { .if_freq = 6000, .std_bits = 0x0d },
1209 .atv_dk = { .if_freq = 6900, .std_bits = 0x0e },
1210 .atv_gh = { .if_freq = 7100, .std_bits = 0x0e },
1211 .atv_i = { .if_freq = 7250, .std_bits = 0x0e },
1212 .atv_l = { .if_freq = 6900, .std_bits = 0x0e },
1213 .atv_lc = { .if_freq = 1250, .std_bits = 0x0e },
1214 .atv_mn = { .if_freq = 5400, .std_bits = 0x0c },
1215 .atsc_6 = { .if_freq = 3250, .std_bits = 0x1c },
1216 .dvbt_6 = { .if_freq = 3300, .std_bits = 0x1c },
1217 .dvbt_7 = { .if_freq = 3500, .std_bits = 0x1c },
1218 .dvbt_8 = { .if_freq = 4000, .std_bits = 0x1d },
1219 .qam_6 = { .if_freq = 4000, .std_bits = 0x1d },
1220 .qam_8 = { .if_freq = 5000, .std_bits = 0x1f },
1221};
1222
1223/*---------------------------------------------------------------------*/
1224
1225static struct tda18271_map_layout tda18271c1_map_layout = {
1226 .main_pll = tda18271c1_main_pll,
1227 .cal_pll = tda18271c1_cal_pll,
1228
1229 .rf_cal = tda18271c1_rf_cal,
1230 .rf_cal_kmco = tda18271c1_km,
1231
1232 .bp_filter = tda18271_bp_filter,
1233 .rf_band = tda18271_rf_band,
1234 .gain_taper = tda18271_gain_taper,
1235 .ir_measure = tda18271_ir_measure,
1236};
1237
1238static struct tda18271_map_layout tda18271c2_map_layout = {
1239 .main_pll = tda18271c2_main_pll,
1240 .cal_pll = tda18271c2_cal_pll,
1241
1242 .rf_cal = tda18271c2_rf_cal,
1243 .rf_cal_kmco = tda18271c2_km,
1244
1245 .rf_cal_dc_over_dt = tda18271_rf_cal_dc_over_dt,
1246
1247 .bp_filter = tda18271_bp_filter,
1248 .rf_band = tda18271_rf_band,
1249 .gain_taper = tda18271_gain_taper,
1250 .ir_measure = tda18271_ir_measure,
1251};
1252
1253int tda18271_assign_map_layout(struct dvb_frontend *fe)
1254{
1255 struct tda18271_priv *priv = fe->tuner_priv;
1256 int ret = 0;
1257
1258 switch (priv->id) {
1259 case TDA18271HDC1:
1260 priv->maps = &tda18271c1_map_layout;
1261 memcpy(&priv->std, &tda18271c1_std_map,
1262 sizeof(struct tda18271_std_map));
1263 break;
1264 case TDA18271HDC2:
1265 priv->maps = &tda18271c2_map_layout;
1266 memcpy(&priv->std, &tda18271c2_std_map,
1267 sizeof(struct tda18271_std_map));
1268 break;
1269 default:
1270 ret = -EINVAL;
1271 break;
1272 }
1273 memcpy(priv->rf_cal_state, &tda18271_rf_band_template,
1274 sizeof(tda18271_rf_band_template));
1275
1276 return ret;
1277}
1278
1279/*
1280 * Overrides for Emacs so that we follow Linus's tabbing style.
1281 * ---------------------------------------------------------------------------
1282 * Local variables:
1283 * c-basic-offset: 8
1284 * End:
1285 */
diff --git a/drivers/media/dvb/frontends/tda18271.h b/drivers/media/dvb/frontends/tda18271.h
new file mode 100644
index 000000000000..24b0e35a2ab3
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda18271.h
@@ -0,0 +1,78 @@
1/*
2 tda18271.h - header for the Philips / NXP TDA18271 silicon tuner
3
4 Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __TDA18271_H__
22#define __TDA18271_H__
23
24#include <linux/i2c.h>
25#include "dvb_frontend.h"
26
27struct tda18271_std_map_item {
28 u16 if_freq;
29 u8 std_bits;
30};
31
32struct tda18271_std_map {
33 struct tda18271_std_map_item fm_radio;
34 struct tda18271_std_map_item atv_b;
35 struct tda18271_std_map_item atv_dk;
36 struct tda18271_std_map_item atv_gh;
37 struct tda18271_std_map_item atv_i;
38 struct tda18271_std_map_item atv_l;
39 struct tda18271_std_map_item atv_lc;
40 struct tda18271_std_map_item atv_mn;
41 struct tda18271_std_map_item atsc_6;
42 struct tda18271_std_map_item dvbt_6;
43 struct tda18271_std_map_item dvbt_7;
44 struct tda18271_std_map_item dvbt_8;
45 struct tda18271_std_map_item qam_6;
46 struct tda18271_std_map_item qam_8;
47};
48
49enum tda18271_i2c_gate {
50 TDA18271_GATE_AUTO = 0,
51 TDA18271_GATE_ANALOG,
52 TDA18271_GATE_DIGITAL,
53};
54
55struct tda18271_config {
56 /* override default if freq / std settings (optional) */
57 struct tda18271_std_map *std_map;
58
59 /* use i2c gate provided by analog or digital demod */
60 enum tda18271_i2c_gate gate;
61};
62
63#if defined(CONFIG_DVB_TDA18271) || (defined(CONFIG_DVB_TDA18271_MODULE) && defined(MODULE))
64extern struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
65 struct i2c_adapter *i2c,
66 struct tda18271_config *cfg);
67#else
68static inline struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe,
69 u8 addr,
70 struct i2c_adapter *i2c,
71 struct tda18271_config *cfg)
72{
73 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
74 return NULL;
75}
76#endif
77
78#endif /* __TDA18271_H__ */
diff --git a/drivers/media/dvb/frontends/tda827x.c b/drivers/media/dvb/frontends/tda827x.c
index 256fc4bf500b..229b11987a58 100644
--- a/drivers/media/dvb/frontends/tda827x.c
+++ b/drivers/media/dvb/frontends/tda827x.c
@@ -19,12 +19,16 @@
19 */ 19 */
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/dvb/frontend.h>
23#include <asm/types.h> 22#include <asm/types.h>
23#include <linux/dvb/frontend.h>
24#include <linux/videodev2.h>
24 25
25#include "tda827x.h" 26#include "tda827x.h"
26 27
27static int debug = 0; 28static int debug = 0;
29module_param(debug, int, 0644);
30MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
31
28#define dprintk(args...) \ 32#define dprintk(args...) \
29 do { \ 33 do { \
30 if (debug) printk(KERN_DEBUG "tda827x: " args); \ 34 if (debug) printk(KERN_DEBUG "tda827x: " args); \
@@ -34,10 +38,57 @@ struct tda827x_priv {
34 int i2c_addr; 38 int i2c_addr;
35 struct i2c_adapter *i2c_adap; 39 struct i2c_adapter *i2c_adap;
36 struct tda827x_config *cfg; 40 struct tda827x_config *cfg;
41
42 unsigned int sgIF;
43 unsigned char lpsel;
44
37 u32 frequency; 45 u32 frequency;
38 u32 bandwidth; 46 u32 bandwidth;
39}; 47};
40 48
49static void tda827x_set_std(struct dvb_frontend *fe,
50 struct analog_parameters *params)
51{
52 struct tda827x_priv *priv = fe->tuner_priv;
53 char *mode;
54
55 priv->lpsel = 0;
56 if (params->std & V4L2_STD_MN) {
57 priv->sgIF = 92;
58 priv->lpsel = 1;
59 mode = "MN";
60 } else if (params->std & V4L2_STD_B) {
61 priv->sgIF = 108;
62 mode = "B";
63 } else if (params->std & V4L2_STD_GH) {
64 priv->sgIF = 124;
65 mode = "GH";
66 } else if (params->std & V4L2_STD_PAL_I) {
67 priv->sgIF = 124;
68 mode = "I";
69 } else if (params->std & V4L2_STD_DK) {
70 priv->sgIF = 124;
71 mode = "DK";
72 } else if (params->std & V4L2_STD_SECAM_L) {
73 priv->sgIF = 124;
74 mode = "L";
75 } else if (params->std & V4L2_STD_SECAM_LC) {
76 priv->sgIF = 20;
77 mode = "LC";
78 } else {
79 priv->sgIF = 124;
80 mode = "xx";
81 }
82
83 if (params->mode == V4L2_TUNER_RADIO)
84 priv->sgIF = 88; /* if frequency is 5.5 MHz */
85
86 dprintk("setting tda827x to system %s\n", mode);
87}
88
89
90/* ------------------------------------------------------------------ */
91
41struct tda827x_data { 92struct tda827x_data {
42 u32 lomax; 93 u32 lomax;
43 u8 spd; 94 u8 spd;
@@ -48,7 +99,7 @@ struct tda827x_data {
48 u8 div1p5; 99 u8 div1p5;
49}; 100};
50 101
51static const struct tda827x_data tda827x_dvbt[] = { 102static const struct tda827x_data tda827x_table[] = {
52 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, 103 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
53 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, 104 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
54 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, 105 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
@@ -106,21 +157,22 @@ static int tda827xo_set_params(struct dvb_frontend *fe,
106 tuner_freq = params->frequency + if_freq; 157 tuner_freq = params->frequency + if_freq;
107 158
108 i = 0; 159 i = 0;
109 while (tda827x_dvbt[i].lomax < tuner_freq) { 160 while (tda827x_table[i].lomax < tuner_freq) {
110 if(tda827x_dvbt[i + 1].lomax == 0) 161 if (tda827x_table[i + 1].lomax == 0)
111 break; 162 break;
112 i++; 163 i++;
113 } 164 }
114 165
115 N = ((tuner_freq + 125000) / 250000) << (tda827x_dvbt[i].spd + 2); 166 N = ((tuner_freq + 125000) / 250000) << (tda827x_table[i].spd + 2);
116 buf[0] = 0; 167 buf[0] = 0;
117 buf[1] = (N>>8) | 0x40; 168 buf[1] = (N>>8) | 0x40;
118 buf[2] = N & 0xff; 169 buf[2] = N & 0xff;
119 buf[3] = 0; 170 buf[3] = 0;
120 buf[4] = 0x52; 171 buf[4] = 0x52;
121 buf[5] = (tda827x_dvbt[i].spd << 6) + (tda827x_dvbt[i].div1p5 << 5) + 172 buf[5] = (tda827x_table[i].spd << 6) + (tda827x_table[i].div1p5 << 5) +
122 (tda827x_dvbt[i].bs << 3) + tda827x_dvbt[i].bp; 173 (tda827x_table[i].bs << 3) +
123 buf[6] = (tda827x_dvbt[i].gc3 << 4) + 0x8f; 174 tda827x_table[i].bp;
175 buf[6] = (tda827x_table[i].gc3 << 4) + 0x8f;
124 buf[7] = 0xbf; 176 buf[7] = 0xbf;
125 buf[8] = 0x2a; 177 buf[8] = 0x2a;
126 buf[9] = 0x05; 178 buf[9] = 0x05;
@@ -140,7 +192,7 @@ static int tda827xo_set_params(struct dvb_frontend *fe,
140 msleep(500); 192 msleep(500);
141 /* correct CP value */ 193 /* correct CP value */
142 buf[0] = 0x30; 194 buf[0] = 0x30;
143 buf[1] = 0x50 + tda827x_dvbt[i].cp; 195 buf[1] = 0x50 + tda827x_table[i].cp;
144 msg.len = 2; 196 msg.len = 2;
145 197
146 if (fe->ops.i2c_gate_ctrl) 198 if (fe->ops.i2c_gate_ctrl)
@@ -173,6 +225,102 @@ static int tda827xo_sleep(struct dvb_frontend *fe)
173 225
174/* ------------------------------------------------------------------ */ 226/* ------------------------------------------------------------------ */
175 227
228static int tda827xo_set_analog_params(struct dvb_frontend *fe,
229 struct analog_parameters *params)
230{
231 unsigned char tuner_reg[8];
232 unsigned char reg2[2];
233 u32 N;
234 int i;
235 struct tda827x_priv *priv = fe->tuner_priv;
236 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0 };
237 unsigned int freq = params->frequency;
238
239 tda827x_set_std(fe, params);
240
241 if (params->mode == V4L2_TUNER_RADIO)
242 freq = freq / 1000;
243
244 N = freq + priv->sgIF;
245
246 i = 0;
247 while (tda827x_table[i].lomax < N * 62500) {
248 if (tda827x_table[i + 1].lomax == 0)
249 break;
250 i++;
251 }
252
253 N = N << tda827x_table[i].spd;
254
255 tuner_reg[0] = 0;
256 tuner_reg[1] = (unsigned char)(N>>8);
257 tuner_reg[2] = (unsigned char) N;
258 tuner_reg[3] = 0x40;
259 tuner_reg[4] = 0x52 + (priv->lpsel << 5);
260 tuner_reg[5] = (tda827x_table[i].spd << 6) +
261 (tda827x_table[i].div1p5 << 5) +
262 (tda827x_table[i].bs << 3) + tda827x_table[i].bp;
263 tuner_reg[6] = 0x8f + (tda827x_table[i].gc3 << 4);
264 tuner_reg[7] = 0x8f;
265
266 msg.buf = tuner_reg;
267 msg.len = 8;
268 i2c_transfer(priv->i2c_adap, &msg, 1);
269
270 msg.buf = reg2;
271 msg.len = 2;
272 reg2[0] = 0x80;
273 reg2[1] = 0;
274 i2c_transfer(priv->i2c_adap, &msg, 1);
275
276 reg2[0] = 0x60;
277 reg2[1] = 0xbf;
278 i2c_transfer(priv->i2c_adap, &msg, 1);
279
280 reg2[0] = 0x30;
281 reg2[1] = tuner_reg[4] + 0x80;
282 i2c_transfer(priv->i2c_adap, &msg, 1);
283
284 msleep(1);
285 reg2[0] = 0x30;
286 reg2[1] = tuner_reg[4] + 4;
287 i2c_transfer(priv->i2c_adap, &msg, 1);
288
289 msleep(1);
290 reg2[0] = 0x30;
291 reg2[1] = tuner_reg[4];
292 i2c_transfer(priv->i2c_adap, &msg, 1);
293
294 msleep(550);
295 reg2[0] = 0x30;
296 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_table[i].cp;
297 i2c_transfer(priv->i2c_adap, &msg, 1);
298
299 reg2[0] = 0x60;
300 reg2[1] = 0x3f;
301 i2c_transfer(priv->i2c_adap, &msg, 1);
302
303 reg2[0] = 0x80;
304 reg2[1] = 0x08; /* Vsync en */
305 i2c_transfer(priv->i2c_adap, &msg, 1);
306
307 priv->frequency = freq * 62500;
308
309 return 0;
310}
311
312static void tda827xo_agcf(struct dvb_frontend *fe)
313{
314 struct tda827x_priv *priv = fe->tuner_priv;
315 unsigned char data[] = { 0x80, 0x0c };
316 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
317 .buf = data, .len = 2};
318
319 i2c_transfer(priv->i2c_adap, &msg, 1);
320}
321
322/* ------------------------------------------------------------------ */
323
176struct tda827xa_data { 324struct tda827xa_data {
177 u32 lomax; 325 u32 lomax;
178 u8 svco; 326 u8 svco;
@@ -212,6 +360,35 @@ static const struct tda827xa_data tda827xa_dvbt[] = {
212 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} 360 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
213}; 361};
214 362
363static struct tda827xa_data tda827xa_analog[] = {
364 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3},
365 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
366 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
367 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
368 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
369 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
370 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
371 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
372 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
373 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
374 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3},
375 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3},
376 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
377 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
378 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
379 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
380 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
381 { .lomax = 554000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
382 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
383 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
384 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
385 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
386 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
387 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
388 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
389 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
390};
391
215static int tda827xa_set_params(struct dvb_frontend *fe, 392static int tda827xa_set_params(struct dvb_frontend *fe,
216 struct dvb_frontend_parameters *params) 393 struct dvb_frontend_parameters *params)
217{ 394{
@@ -368,6 +545,163 @@ static int tda827xa_sleep(struct dvb_frontend *fe)
368 return 0; 545 return 0;
369} 546}
370 547
548/* ------------------------------------------------------------------ */
549
550static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
551 struct analog_parameters *params)
552{
553 struct tda827x_priv *priv = fe->tuner_priv;
554 unsigned char buf[] = {0x22, 0x01};
555 int arg;
556 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
557 .buf = buf, .len = sizeof(buf) };
558
559 if (NULL == priv->cfg) {
560 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
561 return;
562 }
563
564 if (priv->cfg->config) {
565 if (high)
566 dprintk("setting LNA to high gain\n");
567 else
568 dprintk("setting LNA to low gain\n");
569 }
570 switch (*priv->cfg->config) {
571 case 0: /* no LNA */
572 break;
573 case 1: /* switch is GPIO 0 of tda8290 */
574 case 2:
575 /* turn Vsync on */
576 if (params->std & V4L2_STD_MN)
577 arg = 1;
578 else
579 arg = 0;
580 if (priv->cfg->tuner_callback)
581 priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
582 1, arg);
583 buf[1] = high ? 0 : 1;
584 if (*priv->cfg->config == 2)
585 buf[1] = high ? 1 : 0;
586 i2c_transfer(priv->i2c_adap, &msg, 1);
587 break;
588 case 3: /* switch with GPIO of saa713x */
589 if (priv->cfg->tuner_callback)
590 priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
591 0, high);
592 break;
593 }
594}
595
596static int tda827xa_set_analog_params(struct dvb_frontend *fe,
597 struct analog_parameters *params)
598{
599 unsigned char tuner_reg[11];
600 u32 N;
601 int i;
602 struct tda827x_priv *priv = fe->tuner_priv;
603 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
604 .buf = tuner_reg, .len = sizeof(tuner_reg) };
605 unsigned int freq = params->frequency;
606
607 tda827x_set_std(fe, params);
608
609 tda827xa_lna_gain(fe, 1, params);
610 msleep(10);
611
612 if (params->mode == V4L2_TUNER_RADIO)
613 freq = freq / 1000;
614
615 N = freq + priv->sgIF;
616
617 i = 0;
618 while (tda827xa_analog[i].lomax < N * 62500) {
619 if (tda827xa_analog[i + 1].lomax == 0)
620 break;
621 i++;
622 }
623
624 N = N << tda827xa_analog[i].spd;
625
626 tuner_reg[0] = 0;
627 tuner_reg[1] = (unsigned char)(N>>8);
628 tuner_reg[2] = (unsigned char) N;
629 tuner_reg[3] = 0;
630 tuner_reg[4] = 0x16;
631 tuner_reg[5] = (tda827xa_analog[i].spd << 5) +
632 (tda827xa_analog[i].svco << 3) +
633 tda827xa_analog[i].sbs;
634 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
635 tuner_reg[7] = 0x1c;
636 tuner_reg[8] = 4;
637 tuner_reg[9] = 0x20;
638 tuner_reg[10] = 0x00;
639 msg.len = 11;
640 i2c_transfer(priv->i2c_adap, &msg, 1);
641
642 tuner_reg[0] = 0x90;
643 tuner_reg[1] = 0xff;
644 tuner_reg[2] = 0xe0;
645 tuner_reg[3] = 0;
646 tuner_reg[4] = 0x99 + (priv->lpsel << 1);
647 msg.len = 5;
648 i2c_transfer(priv->i2c_adap, &msg, 1);
649
650 tuner_reg[0] = 0xa0;
651 tuner_reg[1] = 0xc0;
652 msg.len = 2;
653 i2c_transfer(priv->i2c_adap, &msg, 1);
654
655 tuner_reg[0] = 0x30;
656 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
657 i2c_transfer(priv->i2c_adap, &msg, 1);
658
659 msg.flags = I2C_M_RD;
660 i2c_transfer(priv->i2c_adap, &msg, 1);
661 msg.flags = 0;
662 tuner_reg[1] >>= 4;
663 dprintk("AGC2 gain is: %d\n", tuner_reg[1]);
664 if (tuner_reg[1] < 1)
665 tda827xa_lna_gain(fe, 0, params);
666
667 msleep(100);
668 tuner_reg[0] = 0x60;
669 tuner_reg[1] = 0x3c;
670 i2c_transfer(priv->i2c_adap, &msg, 1);
671
672 msleep(163);
673 tuner_reg[0] = 0x50;
674 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
675 i2c_transfer(priv->i2c_adap, &msg, 1);
676
677 tuner_reg[0] = 0x80;
678 tuner_reg[1] = 0x28;
679 i2c_transfer(priv->i2c_adap, &msg, 1);
680
681 tuner_reg[0] = 0xb0;
682 tuner_reg[1] = 0x01;
683 i2c_transfer(priv->i2c_adap, &msg, 1);
684
685 tuner_reg[0] = 0xc0;
686 tuner_reg[1] = 0x19 + (priv->lpsel << 1);
687 i2c_transfer(priv->i2c_adap, &msg, 1);
688
689 priv->frequency = freq * 62500;
690
691 return 0;
692}
693
694static void tda827xa_agcf(struct dvb_frontend *fe)
695{
696 struct tda827x_priv *priv = fe->tuner_priv;
697 unsigned char data[] = {0x80, 0x2c};
698 struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0,
699 .buf = data, .len = 2};
700 i2c_transfer(priv->i2c_adap, &msg, 1);
701}
702
703/* ------------------------------------------------------------------ */
704
371static int tda827x_release(struct dvb_frontend *fe) 705static int tda827x_release(struct dvb_frontend *fe)
372{ 706{
373 kfree(fe->tuner_priv); 707 kfree(fe->tuner_priv);
@@ -430,6 +764,7 @@ static struct dvb_tuner_ops tda827xo_tuner_ops = {
430 .init = tda827x_initial_init, 764 .init = tda827x_initial_init,
431 .sleep = tda827x_initial_sleep, 765 .sleep = tda827x_initial_sleep,
432 .set_params = tda827xo_set_params, 766 .set_params = tda827xo_set_params,
767 .set_analog_params = tda827xo_set_analog_params,
433 .get_frequency = tda827x_get_frequency, 768 .get_frequency = tda827x_get_frequency,
434 .get_bandwidth = tda827x_get_bandwidth, 769 .get_bandwidth = tda827x_get_bandwidth,
435}; 770};
@@ -445,6 +780,7 @@ static struct dvb_tuner_ops tda827xa_tuner_ops = {
445 .init = tda827x_init, 780 .init = tda827x_init,
446 .sleep = tda827xa_sleep, 781 .sleep = tda827xa_sleep,
447 .set_params = tda827xa_set_params, 782 .set_params = tda827xa_set_params,
783 .set_analog_params = tda827xa_set_analog_params,
448 .get_frequency = tda827x_get_frequency, 784 .get_frequency = tda827x_get_frequency,
449 .get_bandwidth = tda827x_get_bandwidth, 785 .get_bandwidth = tda827x_get_bandwidth,
450}; 786};
@@ -465,9 +801,13 @@ static int tda827x_probe_version(struct dvb_frontend *fe)
465 dprintk("tda827x tuner found\n"); 801 dprintk("tda827x tuner found\n");
466 fe->ops.tuner_ops.init = tda827x_init; 802 fe->ops.tuner_ops.init = tda827x_init;
467 fe->ops.tuner_ops.sleep = tda827xo_sleep; 803 fe->ops.tuner_ops.sleep = tda827xo_sleep;
804 if (priv->cfg)
805 priv->cfg->agcf = tda827xo_agcf;
468 } else { 806 } else {
469 dprintk("tda827xa tuner found\n"); 807 dprintk("tda827xa tuner found\n");
470 memcpy(&fe->ops.tuner_ops, &tda827xa_tuner_ops, sizeof(struct dvb_tuner_ops)); 808 memcpy(&fe->ops.tuner_ops, &tda827xa_tuner_ops, sizeof(struct dvb_tuner_ops));
809 if (priv->cfg)
810 priv->cfg->agcf = tda827xa_agcf;
471 } 811 }
472 return 0; 812 return 0;
473} 813}
@@ -487,16 +827,13 @@ struct dvb_frontend *tda827x_attach(struct dvb_frontend *fe, int addr,
487 priv->i2c_adap = i2c; 827 priv->i2c_adap = i2c;
488 priv->cfg = cfg; 828 priv->cfg = cfg;
489 memcpy(&fe->ops.tuner_ops, &tda827xo_tuner_ops, sizeof(struct dvb_tuner_ops)); 829 memcpy(&fe->ops.tuner_ops, &tda827xo_tuner_ops, sizeof(struct dvb_tuner_ops));
490
491 fe->tuner_priv = priv; 830 fe->tuner_priv = priv;
492 831
832 dprintk("type set to %s\n", fe->ops.tuner_ops.info.name);
833
493 return fe; 834 return fe;
494} 835}
495 836EXPORT_SYMBOL_GPL(tda827x_attach);
496EXPORT_SYMBOL(tda827x_attach);
497
498module_param(debug, int, 0644);
499MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
500 837
501MODULE_DESCRIPTION("DVB TDA827x driver"); 838MODULE_DESCRIPTION("DVB TDA827x driver");
502MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>"); 839MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
diff --git a/drivers/media/dvb/frontends/tda827x.h b/drivers/media/dvb/frontends/tda827x.h
index 69e8263d6d59..92eb65b4012b 100644
--- a/drivers/media/dvb/frontends/tda827x.h
+++ b/drivers/media/dvb/frontends/tda827x.h
@@ -29,9 +29,16 @@
29 29
30struct tda827x_config 30struct tda827x_config
31{ 31{
32 /* saa7134 - provided callbacks */
32 void (*lna_gain) (struct dvb_frontend *fe, int high); 33 void (*lna_gain) (struct dvb_frontend *fe, int high);
33 int (*init) (struct dvb_frontend *fe); 34 int (*init) (struct dvb_frontend *fe);
34 int (*sleep) (struct dvb_frontend *fe); 35 int (*sleep) (struct dvb_frontend *fe);
36
37 /* interface to tda829x driver */
38 unsigned int *config;
39 int (*tuner_callback) (void *dev, int command, int arg);
40
41 void (*agcf)(struct dvb_frontend *fe);
35}; 42};
36 43
37 44
diff --git a/drivers/media/dvb/frontends/ves1820.c b/drivers/media/dvb/frontends/ves1820.c
index 60433b5011fd..8791701c8f25 100644
--- a/drivers/media/dvb/frontends/ves1820.c
+++ b/drivers/media/dvb/frontends/ves1820.c
@@ -65,7 +65,7 @@ static int ves1820_writereg(struct ves1820_state *state, u8 reg, u8 data)
65 ret = i2c_transfer(state->i2c, &msg, 1); 65 ret = i2c_transfer(state->i2c, &msg, 1);
66 66
67 if (ret != 1) 67 if (ret != 1)
68 printk("ves1820: %s(): writereg error (reg == 0x%02x," 68 printk("ves1820: %s(): writereg error (reg == 0x%02x, "
69 "val == 0x%02x, ret == %i)\n", __FUNCTION__, reg, data, ret); 69 "val == 0x%02x, ret == %i)\n", __FUNCTION__, reg, data, ret);
70 70
71 return (ret != 1) ? -EREMOTEIO : 0; 71 return (ret != 1) ? -EREMOTEIO : 0;
@@ -84,7 +84,7 @@ static u8 ves1820_readreg(struct ves1820_state *state, u8 reg)
84 ret = i2c_transfer(state->i2c, msg, 2); 84 ret = i2c_transfer(state->i2c, msg, 2);
85 85
86 if (ret != 2) 86 if (ret != 2)
87 printk("ves1820: %s(): readreg error (reg == 0x%02x," 87 printk("ves1820: %s(): readreg error (reg == 0x%02x, "
88 "ret == %i)\n", __FUNCTION__, reg, ret); 88 "ret == %i)\n", __FUNCTION__, reg, ret);
89 89
90 return b1[0]; 90 return b1[0];
diff --git a/drivers/media/dvb/frontends/xc5000.c b/drivers/media/dvb/frontends/xc5000.c
new file mode 100644
index 000000000000..f642ca200b59
--- /dev/null
+++ b/drivers/media/dvb/frontends/xc5000.c
@@ -0,0 +1,964 @@
1/*
2 * Driver for Xceive XC5000 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2007 Xceive Corporation
5 * Copyright (c) 2007 Steven Toth <stoth@hauppauge.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/videodev2.h>
26#include <linux/delay.h>
27#include <linux/dvb/frontend.h>
28#include <linux/i2c.h>
29
30#include "dvb_frontend.h"
31
32#include "xc5000.h"
33#include "xc5000_priv.h"
34
35static int debug;
36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
38
39#define dprintk(level,fmt, arg...) if (debug >= level) \
40 printk(KERN_INFO "%s: " fmt, "xc5000", ## arg)
41
42#define XC5000_DEFAULT_FIRMWARE "dvb-fe-xc5000-1.1.fw"
43#define XC5000_DEFAULT_FIRMWARE_SIZE 12332
44
45/* Misc Defines */
46#define MAX_TV_STANDARD 23
47#define XC_MAX_I2C_WRITE_LENGTH 64
48
49/* Signal Types */
50#define XC_RF_MODE_AIR 0
51#define XC_RF_MODE_CABLE 1
52
53/* Result codes */
54#define XC_RESULT_SUCCESS 0
55#define XC_RESULT_RESET_FAILURE 1
56#define XC_RESULT_I2C_WRITE_FAILURE 2
57#define XC_RESULT_I2C_READ_FAILURE 3
58#define XC_RESULT_OUT_OF_RANGE 5
59
60/* Product id */
61#define XC_PRODUCT_ID_FW_NOT_LOADED 0x2000
62#define XC_PRODUCT_ID_FW_LOADED 0x1388
63
64/* Registers */
65#define XREG_INIT 0x00
66#define XREG_VIDEO_MODE 0x01
67#define XREG_AUDIO_MODE 0x02
68#define XREG_RF_FREQ 0x03
69#define XREG_D_CODE 0x04
70#define XREG_IF_OUT 0x05
71#define XREG_SEEK_MODE 0x07
72#define XREG_POWER_DOWN 0x0A
73#define XREG_SIGNALSOURCE 0x0D /* 0=Air, 1=Cable */
74#define XREG_SMOOTHEDCVBS 0x0E
75#define XREG_XTALFREQ 0x0F
76#define XREG_FINERFFREQ 0x10
77#define XREG_DDIMODE 0x11
78
79#define XREG_ADC_ENV 0x00
80#define XREG_QUALITY 0x01
81#define XREG_FRAME_LINES 0x02
82#define XREG_HSYNC_FREQ 0x03
83#define XREG_LOCK 0x04
84#define XREG_FREQ_ERROR 0x05
85#define XREG_SNR 0x06
86#define XREG_VERSION 0x07
87#define XREG_PRODUCT_ID 0x08
88#define XREG_BUSY 0x09
89
90/*
91 Basic firmware description. This will remain with
92 the driver for documentation purposes.
93
94 This represents an I2C firmware file encoded as a
95 string of unsigned char. Format is as follows:
96
97 char[0 ]=len0_MSB -> len = len_MSB * 256 + len_LSB
98 char[1 ]=len0_LSB -> length of first write transaction
99 char[2 ]=data0 -> first byte to be sent
100 char[3 ]=data1
101 char[4 ]=data2
102 char[ ]=...
103 char[M ]=dataN -> last byte to be sent
104 char[M+1]=len1_MSB -> len = len_MSB * 256 + len_LSB
105 char[M+2]=len1_LSB -> length of second write transaction
106 char[M+3]=data0
107 char[M+4]=data1
108 ...
109 etc.
110
111 The [len] value should be interpreted as follows:
112
113 len= len_MSB _ len_LSB
114 len=1111_1111_1111_1111 : End of I2C_SEQUENCE
115 len=0000_0000_0000_0000 : Reset command: Do hardware reset
116 len=0NNN_NNNN_NNNN_NNNN : Normal transaction: number of bytes = {1:32767)
117 len=1WWW_WWWW_WWWW_WWWW : Wait command: wait for {1:32767} ms
118
119 For the RESET and WAIT commands, the two following bytes will contain
120 immediately the length of the following transaction.
121
122*/
123typedef struct {
124 char *Name;
125 u16 AudioMode;
126 u16 VideoMode;
127} XC_TV_STANDARD;
128
129/* Tuner standards */
130#define MN_NTSC_PAL_BTSC 0
131#define MN_NTSC_PAL_A2 1
132#define MN_NTSC_PAL_EIAJ 2
133#define MN_NTSC_PAL_Mono 3
134#define BG_PAL_A2 4
135#define BG_PAL_NICAM 5
136#define BG_PAL_MONO 6
137#define I_PAL_NICAM 7
138#define I_PAL_NICAM_MONO 8
139#define DK_PAL_A2 9
140#define DK_PAL_NICAM 10
141#define DK_PAL_MONO 11
142#define DK_SECAM_A2DK1 12
143#define DK_SECAM_A2LDK3 13
144#define DK_SECAM_A2MONO 14
145#define L_SECAM_NICAM 15
146#define LC_SECAM_NICAM 16
147#define DTV6 17
148#define DTV8 18
149#define DTV7_8 19
150#define DTV7 20
151#define FM_Radio_INPUT2 21
152#define FM_Radio_INPUT1 22
153
154XC_TV_STANDARD XC5000_Standard[MAX_TV_STANDARD] = {
155 {"M/N-NTSC/PAL-BTSC", 0x0400, 0x8020},
156 {"M/N-NTSC/PAL-A2", 0x0600, 0x8020},
157 {"M/N-NTSC/PAL-EIAJ", 0x0440, 0x8020},
158 {"M/N-NTSC/PAL-Mono", 0x0478, 0x8020},
159 {"B/G-PAL-A2", 0x0A00, 0x8049},
160 {"B/G-PAL-NICAM", 0x0C04, 0x8049},
161 {"B/G-PAL-MONO", 0x0878, 0x8059},
162 {"I-PAL-NICAM", 0x1080, 0x8009},
163 {"I-PAL-NICAM-MONO", 0x0E78, 0x8009},
164 {"D/K-PAL-A2", 0x1600, 0x8009},
165 {"D/K-PAL-NICAM", 0x0E80, 0x8009},
166 {"D/K-PAL-MONO", 0x1478, 0x8009},
167 {"D/K-SECAM-A2 DK1", 0x1200, 0x8009},
168 {"D/K-SECAM-A2 L/DK3",0x0E00, 0x8009},
169 {"D/K-SECAM-A2 MONO", 0x1478, 0x8009},
170 {"L-SECAM-NICAM", 0x8E82, 0x0009},
171 {"L'-SECAM-NICAM", 0x8E82, 0x4009},
172 {"DTV6", 0x00C0, 0x8002},
173 {"DTV8", 0x00C0, 0x800B},
174 {"DTV7/8", 0x00C0, 0x801B},
175 {"DTV7", 0x00C0, 0x8007},
176 {"FM Radio-INPUT2", 0x9802, 0x9002},
177 {"FM Radio-INPUT1", 0x0208, 0x9002}
178};
179
180static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len);
181static int xc5000_readregs(struct xc5000_priv *priv, u8 *buf, u8 len);
182static void xc5000_TunerReset(struct dvb_frontend *fe);
183
184static int xc_send_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
185{
186 return xc5000_writeregs(priv, buf, len)
187 ? XC_RESULT_I2C_WRITE_FAILURE : XC_RESULT_SUCCESS;
188}
189
190static int xc_read_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
191{
192 return xc5000_readregs(priv, buf, len)
193 ? XC_RESULT_I2C_READ_FAILURE : XC_RESULT_SUCCESS;
194}
195
196static int xc_reset(struct dvb_frontend *fe)
197{
198 xc5000_TunerReset(fe);
199 return XC_RESULT_SUCCESS;
200}
201
202static void xc_wait(int wait_ms)
203{
204 msleep(wait_ms);
205}
206
207static void xc5000_TunerReset(struct dvb_frontend *fe)
208{
209 struct xc5000_priv *priv = fe->tuner_priv;
210 int ret;
211
212 dprintk(1, "%s()\n", __FUNCTION__);
213
214 if (priv->cfg->tuner_callback) {
215 ret = priv->cfg->tuner_callback(priv->cfg->priv,
216 XC5000_TUNER_RESET, 0);
217 if (ret)
218 printk(KERN_ERR "xc5000: reset failed\n");
219 } else
220 printk(KERN_ERR "xc5000: no tuner reset callback function, fatal\n");
221}
222
223static int xc_write_reg(struct xc5000_priv *priv, u16 regAddr, u16 i2cData)
224{
225 u8 buf[4];
226 int WatchDogTimer = 5;
227 int result;
228
229 buf[0] = (regAddr >> 8) & 0xFF;
230 buf[1] = regAddr & 0xFF;
231 buf[2] = (i2cData >> 8) & 0xFF;
232 buf[3] = i2cData & 0xFF;
233 result = xc_send_i2c_data(priv, buf, 4);
234 if (result == XC_RESULT_SUCCESS) {
235 /* wait for busy flag to clear */
236 while ((WatchDogTimer > 0) && (result == XC_RESULT_SUCCESS)) {
237 buf[0] = 0;
238 buf[1] = XREG_BUSY;
239
240 result = xc_send_i2c_data(priv, buf, 2);
241 if (result == XC_RESULT_SUCCESS) {
242 result = xc_read_i2c_data(priv, buf, 2);
243 if (result == XC_RESULT_SUCCESS) {
244 if ((buf[0] == 0) && (buf[1] == 0)) {
245 /* busy flag cleared */
246 break;
247 } else {
248 xc_wait(100); /* wait 5 ms */
249 WatchDogTimer--;
250 }
251 }
252 }
253 }
254 }
255 if (WatchDogTimer < 0)
256 result = XC_RESULT_I2C_WRITE_FAILURE;
257
258 return result;
259}
260
261static int xc_read_reg(struct xc5000_priv *priv, u16 regAddr, u16 *i2cData)
262{
263 u8 buf[2];
264 int result;
265
266 buf[0] = (regAddr >> 8) & 0xFF;
267 buf[1] = regAddr & 0xFF;
268 result = xc_send_i2c_data(priv, buf, 2);
269 if (result != XC_RESULT_SUCCESS)
270 return result;
271
272 result = xc_read_i2c_data(priv, buf, 2);
273 if (result != XC_RESULT_SUCCESS)
274 return result;
275
276 *i2cData = buf[0] * 256 + buf[1];
277 return result;
278}
279
280static int xc_load_i2c_sequence(struct dvb_frontend *fe, u8 i2c_sequence[])
281{
282 struct xc5000_priv *priv = fe->tuner_priv;
283
284 int i, nbytes_to_send, result;
285 unsigned int len, pos, index;
286 u8 buf[XC_MAX_I2C_WRITE_LENGTH];
287
288 index=0;
289 while ((i2c_sequence[index]!=0xFF) || (i2c_sequence[index+1]!=0xFF)) {
290 len = i2c_sequence[index]* 256 + i2c_sequence[index+1];
291 if (len == 0x0000) {
292 /* RESET command */
293 result = xc_reset(fe);
294 index += 2;
295 if (result != XC_RESULT_SUCCESS)
296 return result;
297 } else if (len & 0x8000) {
298 /* WAIT command */
299 xc_wait(len & 0x7FFF);
300 index += 2;
301 } else {
302 /* Send i2c data whilst ensuring individual transactions
303 * do not exceed XC_MAX_I2C_WRITE_LENGTH bytes.
304 */
305 index += 2;
306 buf[0] = i2c_sequence[index];
307 buf[1] = i2c_sequence[index + 1];
308 pos = 2;
309 while (pos < len) {
310 if ((len - pos) > XC_MAX_I2C_WRITE_LENGTH - 2) {
311 nbytes_to_send = XC_MAX_I2C_WRITE_LENGTH;
312 } else {
313 nbytes_to_send = (len - pos + 2);
314 }
315 for (i=2; i<nbytes_to_send; i++) {
316 buf[i] = i2c_sequence[index + pos + i - 2];
317 }
318 result = xc_send_i2c_data(priv, buf, nbytes_to_send);
319
320 if (result != XC_RESULT_SUCCESS)
321 return result;
322
323 pos += nbytes_to_send - 2;
324 }
325 index += len;
326 }
327 }
328 return XC_RESULT_SUCCESS;
329}
330
331static int xc_initialize(struct xc5000_priv *priv)
332{
333 dprintk(1, "%s()\n", __FUNCTION__);
334 return xc_write_reg(priv, XREG_INIT, 0);
335}
336
337static int xc_SetTVStandard(struct xc5000_priv *priv,
338 u16 VideoMode, u16 AudioMode)
339{
340 int ret;
341 dprintk(1, "%s(0x%04x,0x%04x)\n", __FUNCTION__, VideoMode, AudioMode);
342 dprintk(1, "%s() Standard = %s\n",
343 __FUNCTION__,
344 XC5000_Standard[priv->video_standard].Name);
345
346 ret = xc_write_reg(priv, XREG_VIDEO_MODE, VideoMode);
347 if (ret == XC_RESULT_SUCCESS)
348 ret = xc_write_reg(priv, XREG_AUDIO_MODE, AudioMode);
349
350 return ret;
351}
352
353static int xc_shutdown(struct xc5000_priv *priv)
354{
355 return 0;
356 /* Fixme: cannot bring tuner back alive once shutdown
357 * without reloading the driver modules.
358 * return xc_write_reg(priv, XREG_POWER_DOWN, 0);
359 */
360}
361
362static int xc_SetSignalSource(struct xc5000_priv *priv, u16 rf_mode)
363{
364 dprintk(1, "%s(%d) Source = %s\n", __FUNCTION__, rf_mode,
365 rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE");
366
367 if ((rf_mode != XC_RF_MODE_AIR) && (rf_mode != XC_RF_MODE_CABLE))
368 {
369 rf_mode = XC_RF_MODE_CABLE;
370 printk(KERN_ERR
371 "%s(), Invalid mode, defaulting to CABLE",
372 __FUNCTION__);
373 }
374 return xc_write_reg(priv, XREG_SIGNALSOURCE, rf_mode);
375}
376
377static const struct dvb_tuner_ops xc5000_tuner_ops;
378
379static int xc_set_RF_frequency(struct xc5000_priv *priv, u32 freq_hz)
380{
381 u16 freq_code;
382
383 dprintk(1, "%s(%u)\n", __FUNCTION__, freq_hz);
384
385 if ((freq_hz > xc5000_tuner_ops.info.frequency_max) ||
386 (freq_hz < xc5000_tuner_ops.info.frequency_min))
387 return XC_RESULT_OUT_OF_RANGE;
388
389 freq_code = (u16)(freq_hz / 15625);
390
391 return xc_write_reg(priv, XREG_RF_FREQ, freq_code);
392}
393
394
395static int xc_set_IF_frequency(struct xc5000_priv *priv, u32 freq_khz)
396{
397 u32 freq_code = (freq_khz * 1024)/1000;
398 dprintk(1, "%s(freq_khz = %d) freq_code = 0x%x\n",
399 __FUNCTION__, freq_khz, freq_code);
400
401 return xc_write_reg(priv, XREG_IF_OUT, freq_code);
402}
403
404
405static int xc_get_ADC_Envelope(struct xc5000_priv *priv, u16 *adc_envelope)
406{
407 return xc_read_reg(priv, XREG_ADC_ENV, adc_envelope);
408}
409
410static int xc_get_frequency_error(struct xc5000_priv *priv, u32 *freq_error_hz)
411{
412 int result;
413 u16 regData;
414 u32 tmp;
415
416 result = xc_read_reg(priv, XREG_FREQ_ERROR, &regData);
417 if (result)
418 return result;
419
420 tmp = (u32)regData;
421 (*freq_error_hz) = (tmp * 15625) / 1000;
422 return result;
423}
424
425static int xc_get_lock_status(struct xc5000_priv *priv, u16 *lock_status)
426{
427 return xc_read_reg(priv, XREG_LOCK, lock_status);
428}
429
430static int xc_get_version(struct xc5000_priv *priv,
431 u8 *hw_majorversion, u8 *hw_minorversion,
432 u8 *fw_majorversion, u8 *fw_minorversion)
433{
434 u16 data;
435 int result;
436
437 result = xc_read_reg(priv, XREG_VERSION, &data);
438 if (result)
439 return result;
440
441 (*hw_majorversion) = (data >> 12) & 0x0F;
442 (*hw_minorversion) = (data >> 8) & 0x0F;
443 (*fw_majorversion) = (data >> 4) & 0x0F;
444 (*fw_minorversion) = data & 0x0F;
445
446 return 0;
447}
448
449static int xc_get_hsync_freq(struct xc5000_priv *priv, u32 *hsync_freq_hz)
450{
451 u16 regData;
452 int result;
453
454 result = xc_read_reg(priv, XREG_HSYNC_FREQ, &regData);
455 if (result)
456 return result;
457
458 (*hsync_freq_hz) = ((regData & 0x0fff) * 763)/100;
459 return result;
460}
461
462static int xc_get_frame_lines(struct xc5000_priv *priv, u16 *frame_lines)
463{
464 return xc_read_reg(priv, XREG_FRAME_LINES, frame_lines);
465}
466
467static int xc_get_quality(struct xc5000_priv *priv, u16 *quality)
468{
469 return xc_read_reg(priv, XREG_QUALITY, quality);
470}
471
472static u16 WaitForLock(struct xc5000_priv *priv)
473{
474 u16 lockState = 0;
475 int watchDogCount = 40;
476
477 while ((lockState == 0) && (watchDogCount > 0)) {
478 xc_get_lock_status(priv, &lockState);
479 if (lockState != 1) {
480 xc_wait(5);
481 watchDogCount--;
482 }
483 }
484 return lockState;
485}
486
487static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz)
488{
489 int found = 0;
490
491 dprintk(1, "%s(%u)\n", __FUNCTION__, freq_hz);
492
493 if (xc_set_RF_frequency(priv, freq_hz) != XC_RESULT_SUCCESS)
494 return 0;
495
496 if (WaitForLock(priv) == 1)
497 found = 1;
498
499 return found;
500}
501
502static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
503{
504 u8 buf[2] = { reg >> 8, reg & 0xff };
505 u8 bval[2] = { 0, 0 };
506 struct i2c_msg msg[2] = {
507 { .addr = priv->cfg->i2c_address,
508 .flags = 0, .buf = &buf[0], .len = 2 },
509 { .addr = priv->cfg->i2c_address,
510 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
511 };
512
513 if (i2c_transfer(priv->i2c, msg, 2) != 2) {
514 printk(KERN_WARNING "xc5000: I2C read failed\n");
515 return -EREMOTEIO;
516 }
517
518 *val = (bval[0] << 8) | bval[1];
519 return 0;
520}
521
522static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len)
523{
524 struct i2c_msg msg = { .addr = priv->cfg->i2c_address,
525 .flags = 0, .buf = buf, .len = len };
526
527 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
528 printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n",
529 (int)len);
530 return -EREMOTEIO;
531 }
532 return 0;
533}
534
535static int xc5000_readregs(struct xc5000_priv *priv, u8 *buf, u8 len)
536{
537 struct i2c_msg msg = { .addr = priv->cfg->i2c_address,
538 .flags = I2C_M_RD, .buf = buf, .len = len };
539
540 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
541 printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n",(int)len);
542 return -EREMOTEIO;
543 }
544 return 0;
545}
546
547static int xc5000_fwupload(struct dvb_frontend* fe)
548{
549 struct xc5000_priv *priv = fe->tuner_priv;
550 const struct firmware *fw;
551 int ret;
552
553 /* request the firmware, this will block and timeout */
554 printk(KERN_INFO "xc5000: waiting for firmware upload (%s)...\n",
555 XC5000_DEFAULT_FIRMWARE);
556
557 ret = request_firmware(&fw, XC5000_DEFAULT_FIRMWARE, &priv->i2c->dev);
558 if (ret) {
559 printk(KERN_ERR "xc5000: Upload failed. (file not found?)\n");
560 ret = XC_RESULT_RESET_FAILURE;
561 goto out;
562 } else {
563 printk(KERN_INFO "xc5000: firmware read %Zu bytes.\n",
564 fw->size);
565 ret = XC_RESULT_SUCCESS;
566 }
567
568 if (fw->size != XC5000_DEFAULT_FIRMWARE_SIZE) {
569 printk(KERN_ERR "xc5000: firmware incorrect size\n");
570 ret = XC_RESULT_RESET_FAILURE;
571 } else {
572 printk(KERN_INFO "xc5000: firmware upload\n");
573 ret = xc_load_i2c_sequence(fe, fw->data );
574 }
575
576out:
577 release_firmware(fw);
578 return ret;
579}
580
581static void xc_debug_dump(struct xc5000_priv *priv)
582{
583 u16 adc_envelope;
584 u32 freq_error_hz = 0;
585 u16 lock_status;
586 u32 hsync_freq_hz = 0;
587 u16 frame_lines;
588 u16 quality;
589 u8 hw_majorversion = 0, hw_minorversion = 0;
590 u8 fw_majorversion = 0, fw_minorversion = 0;
591
592 /* Wait for stats to stabilize.
593 * Frame Lines needs two frame times after initial lock
594 * before it is valid.
595 */
596 xc_wait(100);
597
598 xc_get_ADC_Envelope(priv, &adc_envelope);
599 dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope);
600
601 xc_get_frequency_error(priv, &freq_error_hz);
602 dprintk(1, "*** Frequency error = %d Hz\n", freq_error_hz);
603
604 xc_get_lock_status(priv, &lock_status);
605 dprintk(1, "*** Lock status (0-Wait, 1-Locked, 2-No-signal) = %d\n",
606 lock_status);
607
608 xc_get_version(priv, &hw_majorversion, &hw_minorversion,
609 &fw_majorversion, &fw_minorversion);
610 dprintk(1, "*** HW: V%02x.%02x, FW: V%02x.%02x\n",
611 hw_majorversion, hw_minorversion,
612 fw_majorversion, fw_minorversion);
613
614 xc_get_hsync_freq(priv, &hsync_freq_hz);
615 dprintk(1, "*** Horizontal sync frequency = %d Hz\n", hsync_freq_hz);
616
617 xc_get_frame_lines(priv, &frame_lines);
618 dprintk(1, "*** Frame lines = %d\n", frame_lines);
619
620 xc_get_quality(priv, &quality);
621 dprintk(1, "*** Quality (0:<8dB, 7:>56dB) = %d\n", quality);
622}
623
624static int xc5000_set_params(struct dvb_frontend *fe,
625 struct dvb_frontend_parameters *params)
626{
627 struct xc5000_priv *priv = fe->tuner_priv;
628 int ret;
629
630 dprintk(1, "%s() frequency=%d (Hz)\n", __FUNCTION__, params->frequency);
631
632 switch(params->u.vsb.modulation) {
633 case VSB_8:
634 case VSB_16:
635 dprintk(1, "%s() VSB modulation\n", __FUNCTION__);
636 priv->rf_mode = XC_RF_MODE_AIR;
637 priv->freq_hz = params->frequency - 1750000;
638 priv->bandwidth = BANDWIDTH_6_MHZ;
639 priv->video_standard = DTV6;
640 break;
641 case QAM_64:
642 case QAM_256:
643 case QAM_AUTO:
644 dprintk(1, "%s() QAM modulation\n", __FUNCTION__);
645 priv->rf_mode = XC_RF_MODE_CABLE;
646 priv->freq_hz = params->frequency - 1750000;
647 priv->bandwidth = BANDWIDTH_6_MHZ;
648 priv->video_standard = DTV6;
649 break;
650 default:
651 return -EINVAL;
652 }
653
654 dprintk(1, "%s() frequency=%d (compensated)\n",
655 __FUNCTION__, priv->freq_hz);
656
657 ret = xc_SetSignalSource(priv, priv->rf_mode);
658 if (ret != XC_RESULT_SUCCESS) {
659 printk(KERN_ERR
660 "xc5000: xc_SetSignalSource(%d) failed\n",
661 priv->rf_mode);
662 return -EREMOTEIO;
663 }
664
665 ret = xc_SetTVStandard(priv,
666 XC5000_Standard[priv->video_standard].VideoMode,
667 XC5000_Standard[priv->video_standard].AudioMode);
668 if (ret != XC_RESULT_SUCCESS) {
669 printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
670 return -EREMOTEIO;
671 }
672
673 ret = xc_set_IF_frequency(priv, priv->cfg->if_khz);
674 if (ret != XC_RESULT_SUCCESS) {
675 printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n",
676 priv->cfg->if_khz);
677 return -EIO;
678 }
679
680 xc_tune_channel(priv, priv->freq_hz);
681
682 if (debug)
683 xc_debug_dump(priv);
684
685 return 0;
686}
687
688static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe);
689
690static int xc5000_set_analog_params(struct dvb_frontend *fe,
691 struct analog_parameters *params)
692{
693 struct xc5000_priv *priv = fe->tuner_priv;
694 int ret;
695
696 if(priv->fwloaded == 0)
697 xc_load_fw_and_init_tuner(fe);
698
699 dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",
700 __FUNCTION__, params->frequency);
701
702 priv->rf_mode = XC_RF_MODE_CABLE; /* Fix me: it could be air. */
703
704 /* params->frequency is in units of 62.5khz */
705 priv->freq_hz = params->frequency * 62500;
706
707 /* FIX ME: Some video standards may have several possible audio
708 standards. We simply default to one of them here.
709 */
710 if(params->std & V4L2_STD_MN) {
711 /* default to BTSC audio standard */
712 priv->video_standard = MN_NTSC_PAL_BTSC;
713 goto tune_channel;
714 }
715
716 if(params->std & V4L2_STD_PAL_BG) {
717 /* default to NICAM audio standard */
718 priv->video_standard = BG_PAL_NICAM;
719 goto tune_channel;
720 }
721
722 if(params->std & V4L2_STD_PAL_I) {
723 /* default to NICAM audio standard */
724 priv->video_standard = I_PAL_NICAM;
725 goto tune_channel;
726 }
727
728 if(params->std & V4L2_STD_PAL_DK) {
729 /* default to NICAM audio standard */
730 priv->video_standard = DK_PAL_NICAM;
731 goto tune_channel;
732 }
733
734 if(params->std & V4L2_STD_SECAM_DK) {
735 /* default to A2 DK1 audio standard */
736 priv->video_standard = DK_SECAM_A2DK1;
737 goto tune_channel;
738 }
739
740 if(params->std & V4L2_STD_SECAM_L) {
741 priv->video_standard = L_SECAM_NICAM;
742 goto tune_channel;
743 }
744
745 if(params->std & V4L2_STD_SECAM_LC) {
746 priv->video_standard = LC_SECAM_NICAM;
747 goto tune_channel;
748 }
749
750tune_channel:
751 ret = xc_SetSignalSource(priv, priv->rf_mode);
752 if (ret != XC_RESULT_SUCCESS) {
753 printk(KERN_ERR
754 "xc5000: xc_SetSignalSource(%d) failed\n",
755 priv->rf_mode);
756 return -EREMOTEIO;
757 }
758
759 ret = xc_SetTVStandard(priv,
760 XC5000_Standard[priv->video_standard].VideoMode,
761 XC5000_Standard[priv->video_standard].AudioMode);
762 if (ret != XC_RESULT_SUCCESS) {
763 printk(KERN_ERR "xc5000: xc_SetTVStandard failed\n");
764 return -EREMOTEIO;
765 }
766
767 xc_tune_channel(priv, priv->freq_hz);
768
769 if (debug)
770 xc_debug_dump(priv);
771
772 return 0;
773}
774
775static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq)
776{
777 struct xc5000_priv *priv = fe->tuner_priv;
778 dprintk(1, "%s()\n", __FUNCTION__);
779 *freq = priv->freq_hz;
780 return 0;
781}
782
783static int xc5000_get_bandwidth(struct dvb_frontend *fe, u32 *bw)
784{
785 struct xc5000_priv *priv = fe->tuner_priv;
786 dprintk(1, "%s()\n", __FUNCTION__);
787
788 *bw = priv->bandwidth;
789 return 0;
790}
791
792static int xc5000_get_status(struct dvb_frontend *fe, u32 *status)
793{
794 struct xc5000_priv *priv = fe->tuner_priv;
795 u16 lock_status = 0;
796
797 xc_get_lock_status(priv, &lock_status);
798
799 dprintk(1, "%s() lock_status = 0x%08x\n", __FUNCTION__, lock_status);
800
801 *status = lock_status;
802
803 return 0;
804}
805
806static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe)
807{
808 struct xc5000_priv *priv = fe->tuner_priv;
809 int ret = 0;
810
811 if (priv->fwloaded == 0) {
812 ret = xc5000_fwupload(fe);
813 if (ret != XC_RESULT_SUCCESS)
814 return ret;
815 priv->fwloaded = 1;
816 }
817
818 /* Start the tuner self-calibration process */
819 ret |= xc_initialize(priv);
820
821 /* Wait for calibration to complete.
822 * We could continue but XC5000 will clock stretch subsequent
823 * I2C transactions until calibration is complete. This way we
824 * don't have to rely on clock stretching working.
825 */
826 xc_wait( 100 );
827
828 /* Default to "CABLE" mode */
829 ret |= xc_write_reg(priv, XREG_SIGNALSOURCE, XC_RF_MODE_CABLE);
830
831 return ret;
832}
833
834static int xc5000_sleep(struct dvb_frontend *fe)
835{
836 struct xc5000_priv *priv = fe->tuner_priv;
837 int ret;
838
839 dprintk(1, "%s()\n", __FUNCTION__);
840
841 /* On Pinnacle PCTV HD 800i, the tuner cannot be reinitialized
842 * once shutdown without reloading the driver. Maybe I am not
843 * doing something right.
844 *
845 */
846
847 ret = xc_shutdown(priv);
848 if(ret != XC_RESULT_SUCCESS) {
849 printk(KERN_ERR
850 "xc5000: %s() unable to shutdown tuner\n",
851 __FUNCTION__);
852 return -EREMOTEIO;
853 }
854 else {
855 /* priv->fwloaded = 0; */
856 return XC_RESULT_SUCCESS;
857 }
858}
859
860static int xc5000_init(struct dvb_frontend *fe)
861{
862 struct xc5000_priv *priv = fe->tuner_priv;
863 dprintk(1, "%s()\n", __FUNCTION__);
864
865 if (xc_load_fw_and_init_tuner(fe) != XC_RESULT_SUCCESS) {
866 printk(KERN_ERR "xc5000: Unable to initialise tuner\n");
867 return -EREMOTEIO;
868 }
869
870 if (debug)
871 xc_debug_dump(priv);
872
873 return 0;
874}
875
876static int xc5000_release(struct dvb_frontend *fe)
877{
878 dprintk(1, "%s()\n", __FUNCTION__);
879 kfree(fe->tuner_priv);
880 fe->tuner_priv = NULL;
881 return 0;
882}
883
884static const struct dvb_tuner_ops xc5000_tuner_ops = {
885 .info = {
886 .name = "Xceive XC5000",
887 .frequency_min = 1000000,
888 .frequency_max = 1023000000,
889 .frequency_step = 50000,
890 },
891
892 .release = xc5000_release,
893 .init = xc5000_init,
894 .sleep = xc5000_sleep,
895
896 .set_params = xc5000_set_params,
897 .set_analog_params = xc5000_set_analog_params,
898 .get_frequency = xc5000_get_frequency,
899 .get_bandwidth = xc5000_get_bandwidth,
900 .get_status = xc5000_get_status
901};
902
903struct dvb_frontend * xc5000_attach(struct dvb_frontend *fe,
904 struct i2c_adapter *i2c,
905 struct xc5000_config *cfg)
906{
907 struct xc5000_priv *priv = NULL;
908 u16 id = 0;
909
910 dprintk(1, "%s()\n", __FUNCTION__);
911
912 priv = kzalloc(sizeof(struct xc5000_priv), GFP_KERNEL);
913 if (priv == NULL)
914 return NULL;
915
916 priv->cfg = cfg;
917 priv->bandwidth = BANDWIDTH_6_MHZ;
918 priv->i2c = i2c;
919
920 /* Check if firmware has been loaded. It is possible that another
921 instance of the driver has loaded the firmware.
922 */
923 if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0) {
924 kfree(priv);
925 return NULL;
926 }
927
928 switch(id) {
929 case XC_PRODUCT_ID_FW_LOADED:
930 printk(KERN_INFO
931 "xc5000: Successfully identified at address 0x%02x\n",
932 cfg->i2c_address);
933 printk(KERN_INFO
934 "xc5000: Firmware has been loaded previously\n");
935 priv->fwloaded = 1;
936 break;
937 case XC_PRODUCT_ID_FW_NOT_LOADED:
938 printk(KERN_INFO
939 "xc5000: Successfully identified at address 0x%02x\n",
940 cfg->i2c_address);
941 printk(KERN_INFO
942 "xc5000: Firmware has not been loaded previously\n");
943 priv->fwloaded = 0;
944 break;
945 default:
946 printk(KERN_ERR
947 "xc5000: Device not found at addr 0x%02x (0x%x)\n",
948 cfg->i2c_address, id);
949 kfree(priv);
950 return NULL;
951 }
952
953 memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops,
954 sizeof(struct dvb_tuner_ops));
955
956 fe->tuner_priv = priv;
957
958 return fe;
959}
960EXPORT_SYMBOL(xc5000_attach);
961
962MODULE_AUTHOR("Steven Toth");
963MODULE_DESCRIPTION("Xceive xc5000 silicon tuner driver");
964MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/xc5000.h b/drivers/media/dvb/frontends/xc5000.h
new file mode 100644
index 000000000000..e0e84562aed1
--- /dev/null
+++ b/drivers/media/dvb/frontends/xc5000.h
@@ -0,0 +1,62 @@
1/*
2 * Driver for Xceive XC5000 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2007 Steven Toth <stoth@hauppauge.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 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#ifndef __XC5000_H__
23#define __XC5000_H__
24
25#include <linux/firmware.h>
26
27struct dvb_frontend;
28struct i2c_adapter;
29
30struct xc5000_config {
31 u8 i2c_address;
32 u32 if_khz;
33
34 /* For each bridge framework, when it attaches either analog or digital,
35 * it has to store a reference back to its _core equivalent structure,
36 * so that it can service the hardware by steering gpio's etc.
37 * Each bridge implementation is different so cast priv accordingly.
38 * The xc5000 driver cares not for this value, other than ensuring
39 * it's passed back to a bridge during tuner_callback().
40 */
41 void *priv;
42 int (*tuner_callback) (void *priv, int command, int arg);
43};
44
45/* xc5000 callback command */
46#define XC5000_TUNER_RESET 0
47
48#if defined(CONFIG_DVB_TUNER_XC5000) || defined(CONFIG_DVB_TUNER_XC5000_MODULE)
49extern struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe,
50 struct i2c_adapter *i2c,
51 struct xc5000_config *cfg);
52#else
53static inline struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe,
54 struct i2c_adapter *i2c,
55 struct xc5000_config *cfg)
56{
57 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
58 return NULL;
59}
60#endif // CONFIG_DVB_TUNER_XC5000
61
62#endif // __XC5000_H__
diff --git a/drivers/media/dvb/frontends/xc5000_priv.h b/drivers/media/dvb/frontends/xc5000_priv.h
new file mode 100644
index 000000000000..13b2d19341da
--- /dev/null
+++ b/drivers/media/dvb/frontends/xc5000_priv.h
@@ -0,0 +1,36 @@
1/*
2 * Driver for Xceive XC5000 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2007 Steven Toth <stoth@hauppauge.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 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#ifndef XC5000_PRIV_H
23#define XC5000_PRIV_H
24
25struct xc5000_priv {
26 struct xc5000_config *cfg;
27 struct i2c_adapter *i2c;
28
29 u32 freq_hz;
30 u32 bandwidth;
31 u8 video_standard;
32 u8 rf_mode;
33 u8 fwloaded;
34};
35
36#endif
diff --git a/drivers/media/dvb/frontends/zl10353.c b/drivers/media/dvb/frontends/zl10353.c
index 0106df4c55e8..276e3b631dc2 100644
--- a/drivers/media/dvb/frontends/zl10353.c
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for Zarlink DVB-T ZL10353 demodulator 2 * Driver for Zarlink DVB-T ZL10353 demodulator
3 * 3 *
4 * Copyright (C) 2006 Christopher Pascoe <c.pascoe@itee.uq.edu.au> 4 * Copyright (C) 2006, 2007 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
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
@@ -16,7 +16,7 @@
16 * 16 *
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.= 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#include <linux/kernel.h> 22#include <linux/kernel.h>
@@ -25,6 +25,7 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <asm/div64.h>
28 29
29#include "dvb_frontend.h" 30#include "dvb_frontend.h"
30#include "zl10353_priv.h" 31#include "zl10353_priv.h"
@@ -35,6 +36,8 @@ struct zl10353_state {
35 struct dvb_frontend frontend; 36 struct dvb_frontend frontend;
36 37
37 struct zl10353_config config; 38 struct zl10353_config config;
39
40 enum fe_bandwidth bandwidth;
38}; 41};
39 42
40static int debug; 43static int debug;
@@ -122,9 +125,10 @@ static void zl10353_calc_nominal_rate(struct dvb_frontend *fe,
122 enum fe_bandwidth bandwidth, 125 enum fe_bandwidth bandwidth,
123 u16 *nominal_rate) 126 u16 *nominal_rate)
124{ 127{
125 u32 adc_clock = 45056; /* 45.056 MHz */
126 u8 bw;
127 struct zl10353_state *state = fe->demodulator_priv; 128 struct zl10353_state *state = fe->demodulator_priv;
129 u32 adc_clock = 450560; /* 45.056 MHz */
130 u64 value;
131 u8 bw;
128 132
129 if (state->config.adc_clock) 133 if (state->config.adc_clock)
130 adc_clock = state->config.adc_clock; 134 adc_clock = state->config.adc_clock;
@@ -142,12 +146,44 @@ static void zl10353_calc_nominal_rate(struct dvb_frontend *fe,
142 break; 146 break;
143 } 147 }
144 148
145 *nominal_rate = (bw * (1 << 23) / 7 * 125 + adc_clock / 2) / adc_clock; 149 value = (u64)10 * (1 << 23) / 7 * 125;
150 value = (bw * value) + adc_clock / 2;
151 do_div(value, adc_clock);
152 *nominal_rate = value;
146 153
147 dprintk("%s: bw %d, adc_clock %d => 0x%x\n", 154 dprintk("%s: bw %d, adc_clock %d => 0x%x\n",
148 __FUNCTION__, bw, adc_clock, *nominal_rate); 155 __FUNCTION__, bw, adc_clock, *nominal_rate);
149} 156}
150 157
158static void zl10353_calc_input_freq(struct dvb_frontend *fe,
159 u16 *input_freq)
160{
161 struct zl10353_state *state = fe->demodulator_priv;
162 u32 adc_clock = 450560; /* 45.056 MHz */
163 int if2 = 361667; /* 36.1667 MHz */
164 int ife;
165 u64 value;
166
167 if (state->config.adc_clock)
168 adc_clock = state->config.adc_clock;
169 if (state->config.if2)
170 if2 = state->config.if2;
171
172 if (adc_clock >= if2 * 2)
173 ife = if2;
174 else {
175 ife = adc_clock - (if2 % adc_clock);
176 if (ife > adc_clock / 2)
177 ife = adc_clock - ife;
178 }
179 value = (u64)65536 * ife + adc_clock / 2;
180 do_div(value, adc_clock);
181 *input_freq = -value;
182
183 dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
184 __FUNCTION__, if2, ife, adc_clock, -(int)value, *input_freq);
185}
186
151static int zl10353_sleep(struct dvb_frontend *fe) 187static int zl10353_sleep(struct dvb_frontend *fe)
152{ 188{
153 static u8 zl10353_softdown[] = { 0x50, 0x0C, 0x44 }; 189 static u8 zl10353_softdown[] = { 0x50, 0x0C, 0x44 };
@@ -160,64 +196,276 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
160 struct dvb_frontend_parameters *param) 196 struct dvb_frontend_parameters *param)
161{ 197{
162 struct zl10353_state *state = fe->demodulator_priv; 198 struct zl10353_state *state = fe->demodulator_priv;
163 u16 nominal_rate; 199 u16 nominal_rate, input_freq;
164 u8 pllbuf[6] = { 0x67 }; 200 u8 pllbuf[6] = { 0x67 }, acq_ctl = 0;
201 u16 tps = 0;
202 struct dvb_ofdm_parameters *op = &param->u.ofdm;
165 203
166 /* These settings set "auto-everything" and start the FSM. */ 204 zl10353_single_write(fe, RESET, 0x80);
167 zl10353_single_write(fe, 0x55, 0x80);
168 udelay(200); 205 udelay(200);
169 zl10353_single_write(fe, 0xEA, 0x01); 206 zl10353_single_write(fe, 0xEA, 0x01);
170 udelay(200); 207 udelay(200);
171 zl10353_single_write(fe, 0xEA, 0x00); 208 zl10353_single_write(fe, 0xEA, 0x00);
172 209
173 zl10353_single_write(fe, 0x56, 0x28); 210 zl10353_single_write(fe, AGC_TARGET, 0x28);
174 zl10353_single_write(fe, 0x89, 0x20); 211
175 zl10353_single_write(fe, 0x5E, 0x00); 212 if (op->transmission_mode != TRANSMISSION_MODE_AUTO)
213 acq_ctl |= (1 << 0);
214 if (op->guard_interval != GUARD_INTERVAL_AUTO)
215 acq_ctl |= (1 << 1);
216 zl10353_single_write(fe, ACQ_CTL, acq_ctl);
176 217
177 zl10353_calc_nominal_rate(fe, param->u.ofdm.bandwidth, &nominal_rate); 218 switch (op->bandwidth) {
219 case BANDWIDTH_6_MHZ:
220 /* These are extrapolated from the 7 and 8MHz values */
221 zl10353_single_write(fe, MCLK_RATIO, 0x97);
222 zl10353_single_write(fe, 0x64, 0x34);
223 break;
224 case BANDWIDTH_7_MHZ:
225 zl10353_single_write(fe, MCLK_RATIO, 0x86);
226 zl10353_single_write(fe, 0x64, 0x35);
227 break;
228 case BANDWIDTH_8_MHZ:
229 default:
230 zl10353_single_write(fe, MCLK_RATIO, 0x75);
231 zl10353_single_write(fe, 0x64, 0x36);
232 }
233
234 zl10353_calc_nominal_rate(fe, op->bandwidth, &nominal_rate);
178 zl10353_single_write(fe, TRL_NOMINAL_RATE_1, msb(nominal_rate)); 235 zl10353_single_write(fe, TRL_NOMINAL_RATE_1, msb(nominal_rate));
179 zl10353_single_write(fe, TRL_NOMINAL_RATE_0, lsb(nominal_rate)); 236 zl10353_single_write(fe, TRL_NOMINAL_RATE_0, lsb(nominal_rate));
237 state->bandwidth = op->bandwidth;
238
239 zl10353_calc_input_freq(fe, &input_freq);
240 zl10353_single_write(fe, INPUT_FREQ_1, msb(input_freq));
241 zl10353_single_write(fe, INPUT_FREQ_0, lsb(input_freq));
242
243 /* Hint at TPS settings */
244 switch (op->code_rate_HP) {
245 case FEC_2_3:
246 tps |= (1 << 7);
247 break;
248 case FEC_3_4:
249 tps |= (2 << 7);
250 break;
251 case FEC_5_6:
252 tps |= (3 << 7);
253 break;
254 case FEC_7_8:
255 tps |= (4 << 7);
256 break;
257 case FEC_1_2:
258 case FEC_AUTO:
259 break;
260 default:
261 return -EINVAL;
262 }
263
264 switch (op->code_rate_LP) {
265 case FEC_2_3:
266 tps |= (1 << 4);
267 break;
268 case FEC_3_4:
269 tps |= (2 << 4);
270 break;
271 case FEC_5_6:
272 tps |= (3 << 4);
273 break;
274 case FEC_7_8:
275 tps |= (4 << 4);
276 break;
277 case FEC_1_2:
278 case FEC_AUTO:
279 break;
280 case FEC_NONE:
281 if (op->hierarchy_information == HIERARCHY_AUTO ||
282 op->hierarchy_information == HIERARCHY_NONE)
283 break;
284 default:
285 return -EINVAL;
286 }
287
288 switch (op->constellation) {
289 case QPSK:
290 break;
291 case QAM_AUTO:
292 case QAM_16:
293 tps |= (1 << 13);
294 break;
295 case QAM_64:
296 tps |= (2 << 13);
297 break;
298 default:
299 return -EINVAL;
300 }
301
302 switch (op->transmission_mode) {
303 case TRANSMISSION_MODE_2K:
304 case TRANSMISSION_MODE_AUTO:
305 break;
306 case TRANSMISSION_MODE_8K:
307 tps |= (1 << 0);
308 break;
309 default:
310 return -EINVAL;
311 }
312
313 switch (op->guard_interval) {
314 case GUARD_INTERVAL_1_32:
315 case GUARD_INTERVAL_AUTO:
316 break;
317 case GUARD_INTERVAL_1_16:
318 tps |= (1 << 2);
319 break;
320 case GUARD_INTERVAL_1_8:
321 tps |= (2 << 2);
322 break;
323 case GUARD_INTERVAL_1_4:
324 tps |= (3 << 2);
325 break;
326 default:
327 return -EINVAL;
328 }
329
330 switch (op->hierarchy_information) {
331 case HIERARCHY_AUTO:
332 case HIERARCHY_NONE:
333 break;
334 case HIERARCHY_1:
335 tps |= (1 << 10);
336 break;
337 case HIERARCHY_2:
338 tps |= (2 << 10);
339 break;
340 case HIERARCHY_4:
341 tps |= (3 << 10);
342 break;
343 default:
344 return -EINVAL;
345 }
346
347 zl10353_single_write(fe, TPS_GIVEN_1, msb(tps));
348 zl10353_single_write(fe, TPS_GIVEN_0, lsb(tps));
180 349
181 zl10353_single_write(fe, 0x6C, 0xCD);
182 zl10353_single_write(fe, 0x6D, 0x7E);
183 if (fe->ops.i2c_gate_ctrl) 350 if (fe->ops.i2c_gate_ctrl)
184 fe->ops.i2c_gate_ctrl(fe, 0); 351 fe->ops.i2c_gate_ctrl(fe, 0);
185 352
186 // if there is no attached secondary tuner, we call set_params to program 353 /*
187 // a potential tuner attached somewhere else 354 * If there is no tuner attached to the secondary I2C bus, we call
355 * set_params to program a potential tuner attached somewhere else.
356 * Otherwise, we update the PLL registers via calc_regs.
357 */
188 if (state->config.no_tuner) { 358 if (state->config.no_tuner) {
189 if (fe->ops.tuner_ops.set_params) { 359 if (fe->ops.tuner_ops.set_params) {
190 fe->ops.tuner_ops.set_params(fe, param); 360 fe->ops.tuner_ops.set_params(fe, param);
191 if (fe->ops.i2c_gate_ctrl) 361 if (fe->ops.i2c_gate_ctrl)
192 fe->ops.i2c_gate_ctrl(fe, 0); 362 fe->ops.i2c_gate_ctrl(fe, 0);
193 } 363 }
364 } else if (fe->ops.tuner_ops.calc_regs) {
365 fe->ops.tuner_ops.calc_regs(fe, param, pllbuf + 1, 5);
366 pllbuf[1] <<= 1;
367 zl10353_write(fe, pllbuf, sizeof(pllbuf));
194 } 368 }
195 369
196 // if pllbuf is defined, retrieve the settings 370 zl10353_single_write(fe, 0x5F, 0x13);
197 if (fe->ops.tuner_ops.calc_regs) { 371
198 fe->ops.tuner_ops.calc_regs(fe, param, pllbuf+1, 5); 372 /* If no attached tuner or invalid PLL registers, just start the FSM. */
199 pllbuf[1] <<= 1; 373 if (state->config.no_tuner || fe->ops.tuner_ops.calc_regs == NULL)
200 } else { 374 zl10353_single_write(fe, FSM_GO, 0x01);
201 // fake pllbuf settings 375 else
202 pllbuf[1] = 0x61 << 1; 376 zl10353_single_write(fe, TUNER_GO, 0x01);
203 pllbuf[2] = 0; 377
204 pllbuf[3] = 0; 378 return 0;
205 pllbuf[3] = 0; 379}
206 pllbuf[4] = 0; 380
381static int zl10353_get_parameters(struct dvb_frontend *fe,
382 struct dvb_frontend_parameters *param)
383{
384 struct zl10353_state *state = fe->demodulator_priv;
385 struct dvb_ofdm_parameters *op = &param->u.ofdm;
386 int s6, s9;
387 u16 tps;
388 static const u8 tps_fec_to_api[8] = {
389 FEC_1_2,
390 FEC_2_3,
391 FEC_3_4,
392 FEC_5_6,
393 FEC_7_8,
394 FEC_AUTO,
395 FEC_AUTO,
396 FEC_AUTO
397 };
398
399 s6 = zl10353_read_register(state, STATUS_6);
400 s9 = zl10353_read_register(state, STATUS_9);
401 if (s6 < 0 || s9 < 0)
402 return -EREMOTEIO;
403 if ((s6 & (1 << 5)) == 0 || (s9 & (1 << 4)) == 0)
404 return -EINVAL; /* no FE or TPS lock */
405
406 tps = zl10353_read_register(state, TPS_RECEIVED_1) << 8 |
407 zl10353_read_register(state, TPS_RECEIVED_0);
408
409 op->code_rate_HP = tps_fec_to_api[(tps >> 7) & 7];
410 op->code_rate_LP = tps_fec_to_api[(tps >> 4) & 7];
411
412 switch ((tps >> 13) & 3) {
413 case 0:
414 op->constellation = QPSK;
415 break;
416 case 1:
417 op->constellation = QAM_16;
418 break;
419 case 2:
420 op->constellation = QAM_64;
421 break;
422 default:
423 op->constellation = QAM_AUTO;
424 break;
207 } 425 }
208 426
209 // there is no call to _just_ start decoding, so we send the pllbuf anyway 427 op->transmission_mode = (tps & 0x01) ? TRANSMISSION_MODE_8K :
210 // even if there isn't a PLL attached to the secondary bus 428 TRANSMISSION_MODE_2K;
211 zl10353_write(fe, pllbuf, sizeof(pllbuf));
212 429
213 zl10353_single_write(fe, 0x5F, 0x13); 430 switch ((tps >> 2) & 3) {
214 zl10353_single_write(fe, 0x70, 0x01); 431 case 0:
215 udelay(250); 432 op->guard_interval = GUARD_INTERVAL_1_32;
216 zl10353_single_write(fe, 0xE4, 0x00); 433 break;
217 zl10353_single_write(fe, 0xE5, 0x2A); 434 case 1:
218 zl10353_single_write(fe, 0xE9, 0x02); 435 op->guard_interval = GUARD_INTERVAL_1_16;
219 zl10353_single_write(fe, 0xE7, 0x40); 436 break;
220 zl10353_single_write(fe, 0xE8, 0x10); 437 case 2:
438 op->guard_interval = GUARD_INTERVAL_1_8;
439 break;
440 case 3:
441 op->guard_interval = GUARD_INTERVAL_1_4;
442 break;
443 default:
444 op->guard_interval = GUARD_INTERVAL_AUTO;
445 break;
446 }
447
448 switch ((tps >> 10) & 7) {
449 case 0:
450 op->hierarchy_information = HIERARCHY_NONE;
451 break;
452 case 1:
453 op->hierarchy_information = HIERARCHY_1;
454 break;
455 case 2:
456 op->hierarchy_information = HIERARCHY_2;
457 break;
458 case 3:
459 op->hierarchy_information = HIERARCHY_4;
460 break;
461 default:
462 op->hierarchy_information = HIERARCHY_AUTO;
463 break;
464 }
465
466 param->frequency = 0;
467 op->bandwidth = state->bandwidth;
468 param->inversion = INVERSION_AUTO;
221 469
222 return 0; 470 return 0;
223} 471}
@@ -406,6 +654,7 @@ static struct dvb_frontend_ops zl10353_ops = {
406 .write = zl10353_write, 654 .write = zl10353_write,
407 655
408 .set_frontend = zl10353_set_parameters, 656 .set_frontend = zl10353_set_parameters,
657 .get_frontend = zl10353_get_parameters,
409 .get_tune_settings = zl10353_get_tune_settings, 658 .get_tune_settings = zl10353_get_tune_settings,
410 659
411 .read_status = zl10353_read_status, 660 .read_status = zl10353_read_status,
diff --git a/drivers/media/dvb/frontends/zl10353.h b/drivers/media/dvb/frontends/zl10353.h
index 1c3d494a6da9..fc734c22b5fa 100644
--- a/drivers/media/dvb/frontends/zl10353.h
+++ b/drivers/media/dvb/frontends/zl10353.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for Zarlink DVB-T ZL10353 demodulator 2 * Driver for Zarlink DVB-T ZL10353 demodulator
3 * 3 *
4 * Copyright (C) 2006 Christopher Pascoe <c.pascoe@itee.uq.edu.au> 4 * Copyright (C) 2006, 2007 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
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
@@ -29,8 +29,9 @@ struct zl10353_config
29 /* demodulator's I2C address */ 29 /* demodulator's I2C address */
30 u8 demod_address; 30 u8 demod_address;
31 31
32 /* frequencies in kHz */ 32 /* frequencies in units of 0.1kHz */
33 int adc_clock; /* default: 45056 */ 33 int adc_clock; /* default: 450560 (45.056 MHz) */
34 int if2; /* default: 361667 (36.1667 MHz) */
34 35
35 /* set if no pll is connected to the secondary i2c bus */ 36 /* set if no pll is connected to the secondary i2c bus */
36 int no_tuner; 37 int no_tuner;
@@ -49,6 +50,6 @@ static inline struct dvb_frontend* zl10353_attach(const struct zl10353_config *c
49 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
50 return NULL; 51 return NULL;
51} 52}
52#endif // CONFIG_DVB_ZL10353 53#endif /* CONFIG_DVB_ZL10353 */
53 54
54#endif /* ZL10353_H */ 55#endif /* ZL10353_H */
diff --git a/drivers/media/dvb/frontends/zl10353_priv.h b/drivers/media/dvb/frontends/zl10353_priv.h
index 4962434b35e7..055ff1f7e349 100644
--- a/drivers/media/dvb/frontends/zl10353_priv.h
+++ b/drivers/media/dvb/frontends/zl10353_priv.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for Zarlink DVB-T ZL10353 demodulator 2 * Driver for Zarlink DVB-T ZL10353 demodulator
3 * 3 *
4 * Copyright (C) 2006 Christopher Pascoe <c.pascoe@itee.uq.edu.au> 4 * Copyright (C) 2006, 2007 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
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
@@ -16,7 +16,7 @@
16 * 16 *
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.= 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#ifndef _ZL10353_PRIV_ 22#ifndef _ZL10353_PRIV_
@@ -46,9 +46,28 @@ enum zl10353_reg_addr {
46 RS_ERR_CNT_0 = 0x13, 46 RS_ERR_CNT_0 = 0x13,
47 RS_UBC_1 = 0x14, 47 RS_UBC_1 = 0x14,
48 RS_UBC_0 = 0x15, 48 RS_UBC_0 = 0x15,
49 TPS_RECEIVED_1 = 0x1D,
50 TPS_RECEIVED_0 = 0x1E,
51 TPS_CURRENT_1 = 0x1F,
52 TPS_CURRENT_0 = 0x20,
53 RESET = 0x55,
54 AGC_TARGET = 0x56,
55 MCLK_RATIO = 0x5C,
56 ACQ_CTL = 0x5E,
49 TRL_NOMINAL_RATE_1 = 0x65, 57 TRL_NOMINAL_RATE_1 = 0x65,
50 TRL_NOMINAL_RATE_0 = 0x66, 58 TRL_NOMINAL_RATE_0 = 0x66,
59 INPUT_FREQ_1 = 0x6C,
60 INPUT_FREQ_0 = 0x6D,
61 TPS_GIVEN_1 = 0x6E,
62 TPS_GIVEN_0 = 0x6F,
63 TUNER_GO = 0x70,
64 FSM_GO = 0x71,
51 CHIP_ID = 0x7F, 65 CHIP_ID = 0x7F,
66 CHAN_STEP_1 = 0xE4,
67 CHAN_STEP_0 = 0xE5,
68 OFDM_LOCK_TIME = 0xE7,
69 FEC_LOCK_TIME = 0xE8,
70 ACQ_DELAY = 0xE9,
52}; 71};
53 72
54#endif /* _ZL10353_PRIV_ */ 73#endif /* _ZL10353_PRIV_ */
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index 54b91f26ca63..ae882432dd3d 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -1,8 +1,14 @@
1config TTPCI_EEPROM
2 tristate
3 default n
4
1config DVB_AV7110 5config DVB_AV7110
2 tristate "AV7110 cards" 6 tristate "AV7110 cards"
3 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 7 depends on DVB_CORE && PCI && I2C
4 select FW_LOADER if !DVB_AV7110_FIRMWARE 8 select FW_LOADER if !DVB_AV7110_FIRMWARE
9 select TTPCI_EEPROM
5 select VIDEO_SAA7146_VV 10 select VIDEO_SAA7146_VV
11 depends on VIDEO_DEV # dependencies of VIDEO_SAA7146_VV
6 select DVB_VES1820 if !DVB_FE_CUSTOMISE 12 select DVB_VES1820 if !DVB_FE_CUSTOMISE
7 select DVB_VES1X93 if !DVB_FE_CUSTOMISE 13 select DVB_VES1X93 if !DVB_FE_CUSTOMISE
8 select DVB_STV0299 if !DVB_FE_CUSTOMISE 14 select DVB_STV0299 if !DVB_FE_CUSTOMISE
@@ -57,10 +63,19 @@ config DVB_AV7110_OSD
57 63
58 All other people say N. 64 All other people say N.
59 65
66config DVB_BUDGET_CORE
67 tristate "SAA7146 DVB cards (aka Budget, Nova-PCI)"
68 depends on DVB_CORE && PCI && I2C
69 select VIDEO_SAA7146
70 select TTPCI_EEPROM
71 help
72 Support for simple SAA7146 based DVB cards
73 (so called Budget- or Nova-PCI cards) without onboard
74 MPEG2 decoder.
75
60config DVB_BUDGET 76config DVB_BUDGET
61 tristate "Budget cards" 77 tristate "Budget cards"
62 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 78 depends on DVB_BUDGET_CORE && I2C
63 select VIDEO_SAA7146
64 select DVB_STV0299 if !DVB_FE_CUSTOMISE 79 select DVB_STV0299 if !DVB_FE_CUSTOMISE
65 select DVB_VES1X93 if !DVB_FE_CUSTOMISE 80 select DVB_VES1X93 if !DVB_FE_CUSTOMISE
66 select DVB_VES1820 if !DVB_FE_CUSTOMISE 81 select DVB_VES1820 if !DVB_FE_CUSTOMISE
@@ -73,9 +88,9 @@ config DVB_BUDGET
73 select DVB_TDA826X if !DVB_FE_CUSTOMISE 88 select DVB_TDA826X if !DVB_FE_CUSTOMISE
74 select DVB_LNBP21 if !DVB_FE_CUSTOMISE 89 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
75 help 90 help
76 Support for simple SAA7146 based DVB cards 91 Support for simple SAA7146 based DVB cards (so called Budget-
77 (so called Budget- or Nova-PCI cards) without onboard 92 or Nova-PCI cards) without onboard MPEG2 decoder, and without
78 MPEG2 decoder. 93 analog inputs or an onboard Common Interface connector.
79 94
80 Say Y if you own such a card and want to use it. 95 Say Y if you own such a card and want to use it.
81 96
@@ -84,8 +99,7 @@ config DVB_BUDGET
84 99
85config DVB_BUDGET_CI 100config DVB_BUDGET_CI
86 tristate "Budget cards with onboard CI connector" 101 tristate "Budget cards with onboard CI connector"
87 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 && INPUT 102 depends on DVB_BUDGET_CORE && I2C
88 select VIDEO_SAA7146
89 select DVB_STV0297 if !DVB_FE_CUSTOMISE 103 select DVB_STV0297 if !DVB_FE_CUSTOMISE
90 select DVB_STV0299 if !DVB_FE_CUSTOMISE 104 select DVB_STV0299 if !DVB_FE_CUSTOMISE
91 select DVB_TDA1004X if !DVB_FE_CUSTOMISE 105 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
@@ -106,8 +120,9 @@ config DVB_BUDGET_CI
106 120
107config DVB_BUDGET_AV 121config DVB_BUDGET_AV
108 tristate "Budget cards with analog video inputs" 122 tristate "Budget cards with analog video inputs"
109 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 123 depends on DVB_BUDGET_CORE && I2C
110 select VIDEO_SAA7146_VV 124 select VIDEO_SAA7146_VV
125 depends on VIDEO_DEV # dependencies of VIDEO_SAA7146_VV
111 select DVB_PLL if !DVB_FE_CUSTOMISE 126 select DVB_PLL if !DVB_FE_CUSTOMISE
112 select DVB_STV0299 if !DVB_FE_CUSTOMISE 127 select DVB_STV0299 if !DVB_FE_CUSTOMISE
113 select DVB_TDA1004X if !DVB_FE_CUSTOMISE 128 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
@@ -127,8 +142,8 @@ config DVB_BUDGET_AV
127 142
128config DVB_BUDGET_PATCH 143config DVB_BUDGET_PATCH
129 tristate "AV7110 cards with Budget Patch" 144 tristate "AV7110 cards with Budget Patch"
130 depends on DVB_CORE && DVB_BUDGET && VIDEO_V4L1 145 depends on DVB_BUDGET_CORE && I2C
131 select DVB_AV7110 146 depends on DVB_AV7110
132 select DVB_STV0299 if !DVB_FE_CUSTOMISE 147 select DVB_STV0299 if !DVB_FE_CUSTOMISE
133 select DVB_VES1X93 if !DVB_FE_CUSTOMISE 148 select DVB_VES1X93 if !DVB_FE_CUSTOMISE
134 select DVB_TDA8083 if !DVB_FE_CUSTOMISE 149 select DVB_TDA8083 if !DVB_FE_CUSTOMISE
diff --git a/drivers/media/dvb/ttpci/Makefile b/drivers/media/dvb/ttpci/Makefile
index 2c1145236ee6..d7483f1a9b3f 100644
--- a/drivers/media/dvb/ttpci/Makefile
+++ b/drivers/media/dvb/ttpci/Makefile
@@ -5,11 +5,13 @@
5 5
6dvb-ttpci-objs := av7110_hw.o av7110_v4l.o av7110_av.o av7110_ca.o av7110.o av7110_ipack.o av7110_ir.o 6dvb-ttpci-objs := av7110_hw.o av7110_v4l.o av7110_av.o av7110_ca.o av7110.o av7110_ipack.o av7110_ir.o
7 7
8obj-$(CONFIG_DVB_BUDGET) += budget-core.o budget.o ttpci-eeprom.o 8obj-$(CONFIG_TTPCI_EEPROM) += ttpci-eeprom.o
9obj-$(CONFIG_DVB_BUDGET_AV) += budget-core.o budget-av.o ttpci-eeprom.o 9obj-$(CONFIG_DVB_BUDGET_CORE) += budget-core.o
10obj-$(CONFIG_DVB_BUDGET_CI) += budget-core.o budget-ci.o ttpci-eeprom.o 10obj-$(CONFIG_DVB_BUDGET) += budget.o
11obj-$(CONFIG_DVB_BUDGET_PATCH) += budget-core.o budget-patch.o ttpci-eeprom.o 11obj-$(CONFIG_DVB_BUDGET_AV) += budget-av.o
12obj-$(CONFIG_DVB_AV7110) += dvb-ttpci.o ttpci-eeprom.o 12obj-$(CONFIG_DVB_BUDGET_CI) += budget-ci.o
13obj-$(CONFIG_DVB_BUDGET_PATCH) += budget-patch.o
14obj-$(CONFIG_DVB_AV7110) += dvb-ttpci.o
13 15
14EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 16EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
15 17
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 0d36c155695b..0e5701bdff19 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -2595,7 +2595,8 @@ static int __devinit av7110_attach(struct saa7146_dev* dev,
2595 mutex_init(&av7110->osd_mutex); 2595 mutex_init(&av7110->osd_mutex);
2596 2596
2597 /* TV standard */ 2597 /* TV standard */
2598 av7110->vidmode = tv_standard == 1 ? VIDEO_MODE_NTSC : VIDEO_MODE_PAL; 2598 av7110->vidmode = tv_standard == 1 ? AV7110_VIDEO_MODE_NTSC
2599 : AV7110_VIDEO_MODE_PAL;
2599 2600
2600 /* ARM "watchdog" */ 2601 /* ARM "watchdog" */
2601 init_waitqueue_head(&av7110->arm_wait); 2602 init_waitqueue_head(&av7110->arm_wait);
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h
index 0cb439527498..39fbf7d5cffb 100644
--- a/drivers/media/dvb/ttpci/av7110.h
+++ b/drivers/media/dvb/ttpci/av7110.h
@@ -46,6 +46,11 @@ extern int av7110_debug;
46 46
47enum {AV_PES_STREAM, PS_STREAM, TS_STREAM, PES_STREAM}; 47enum {AV_PES_STREAM, PS_STREAM, TS_STREAM, PES_STREAM};
48 48
49enum av7110_video_mode {
50 AV7110_VIDEO_MODE_PAL = 0,
51 AV7110_VIDEO_MODE_NTSC = 1
52};
53
49struct av7110_p2t { 54struct av7110_p2t {
50 u8 pes[TS_SIZE]; 55 u8 pes[TS_SIZE];
51 u8 counter; 56 u8 counter;
@@ -170,7 +175,7 @@ struct av7110 {
170 175
171 ca_slot_info_t ci_slot[2]; 176 ca_slot_info_t ci_slot[2];
172 177
173 int vidmode; 178 enum av7110_video_mode vidmode;
174 struct dmxdev dmxdev; 179 struct dmxdev dmxdev;
175 struct dvb_demux demux; 180 struct dvb_demux demux;
176 181
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index d75e7e48addc..aef6e36d7c5c 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -329,7 +329,7 @@ int av7110_set_volume(struct av7110 *av7110, int volleft, int volright)
329 return 0; 329 return 0;
330} 330}
331 331
332int av7110_set_vidmode(struct av7110 *av7110, int mode) 332int av7110_set_vidmode(struct av7110 *av7110, enum av7110_video_mode mode)
333{ 333{
334 int ret; 334 int ret;
335 dprintk(2, "av7110:%p, \n", av7110); 335 dprintk(2, "av7110:%p, \n", av7110);
@@ -348,11 +348,15 @@ int av7110_set_vidmode(struct av7110 *av7110, int mode)
348} 348}
349 349
350 350
351static int sw2mode[16] = { 351static enum av7110_video_mode sw2mode[16] = {
352 VIDEO_MODE_PAL, VIDEO_MODE_NTSC, VIDEO_MODE_NTSC, VIDEO_MODE_PAL, 352 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_NTSC,
353 VIDEO_MODE_NTSC, VIDEO_MODE_NTSC, VIDEO_MODE_PAL, VIDEO_MODE_NTSC, 353 AV7110_VIDEO_MODE_NTSC, AV7110_VIDEO_MODE_PAL,
354 VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, 354 AV7110_VIDEO_MODE_NTSC, AV7110_VIDEO_MODE_NTSC,
355 VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, 355 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_NTSC,
356 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
357 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
358 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
359 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
356}; 360};
357 361
358static int get_video_format(struct av7110 *av7110, u8 *buf, int count) 362static int get_video_format(struct av7110 *av7110, u8 *buf, int count)
diff --git a/drivers/media/dvb/ttpci/av7110_av.h b/drivers/media/dvb/ttpci/av7110_av.h
index 45dc144b8b43..5f02ef85e47d 100644
--- a/drivers/media/dvb/ttpci/av7110_av.h
+++ b/drivers/media/dvb/ttpci/av7110_av.h
@@ -3,7 +3,8 @@
3 3
4struct av7110; 4struct av7110;
5 5
6extern int av7110_set_vidmode(struct av7110 *av7110, int mode); 6extern int av7110_set_vidmode(struct av7110 *av7110,
7 enum av7110_video_mode mode);
7 8
8extern int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len); 9extern int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len);
9extern int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen); 10extern int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen);
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index 76cca003252f..e2f066fb7967 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -876,11 +876,11 @@ static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
876 struct av7110 *av7110 = (struct av7110*) dev->ext_priv; 876 struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
877 877
878 if (std->id & V4L2_STD_PAL) { 878 if (std->id & V4L2_STD_PAL) {
879 av7110->vidmode = VIDEO_MODE_PAL; 879 av7110->vidmode = AV7110_VIDEO_MODE_PAL;
880 av7110_set_vidmode(av7110, av7110->vidmode); 880 av7110_set_vidmode(av7110, av7110->vidmode);
881 } 881 }
882 else if (std->id & V4L2_STD_NTSC) { 882 else if (std->id & V4L2_STD_NTSC) {
883 av7110->vidmode = VIDEO_MODE_NTSC; 883 av7110->vidmode = AV7110_VIDEO_MODE_NTSC;
884 av7110_set_vidmode(av7110, av7110->vidmode); 884 av7110_set_vidmode(av7110, av7110->vidmode);
885 } 885 }
886 else 886 else
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 11e962f1a97f..8d5214f18cf0 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -351,4 +351,14 @@ config USB_DSBR
351 To compile this driver as a module, choose M here: the 351 To compile this driver as a module, choose M here: the
352 module will be called dsbr100. 352 module will be called dsbr100.
353 353
354config USB_SI470X
355 tristate "Silicon Labs Si470x FM Radio Receiver support"
356 depends on USB && VIDEO_V4L2
357 ---help---
358 Say Y here if you want to connect this type of radio to your
359 computer's USB port.
360
361 To compile this driver as a module, choose M here: the
362 module will be called radio-silabs.
363
354endif # RADIO_ADAPTERS 364endif # RADIO_ADAPTERS
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index cf55a18e3ddf..a30159f6fa42 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -21,5 +21,6 @@ obj-$(CONFIG_RADIO_GEMTEK_PCI) += radio-gemtek-pci.o
21obj-$(CONFIG_RADIO_TRUST) += radio-trust.o 21obj-$(CONFIG_RADIO_TRUST) += radio-trust.o
22obj-$(CONFIG_RADIO_MAESTRO) += radio-maestro.o 22obj-$(CONFIG_RADIO_MAESTRO) += radio-maestro.o
23obj-$(CONFIG_USB_DSBR) += dsbr100.o 23obj-$(CONFIG_USB_DSBR) += dsbr100.o
24obj-$(CONFIG_USB_SI470X) += radio-si470x.o
24 25
25EXTRA_CFLAGS += -Isound 26EXTRA_CFLAGS += -Isound
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c
index 3bd07f7e3774..36c0e3651502 100644
--- a/drivers/media/radio/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
@@ -33,6 +33,9 @@
33 33
34 History: 34 History:
35 35
36 Version 0.43:
37 Oliver Neukum: avoided DMA coherency issue
38
36 Version 0.42: 39 Version 0.42:
37 Converted dsbr100 to use video_ioctl2 40 Converted dsbr100 to use video_ioctl2
38 by Douglas Landgraf <dougsland@gmail.com> 41 by Douglas Landgraf <dougsland@gmail.com>
@@ -135,7 +138,7 @@ module_param(radio_nr, int, 0);
135struct dsbr100_device { 138struct dsbr100_device {
136 struct usb_device *usbdev; 139 struct usb_device *usbdev;
137 struct video_device *videodev; 140 struct video_device *videodev;
138 unsigned char transfer_buffer[TB_LEN]; 141 u8 *transfer_buffer;
139 int curfreq; 142 int curfreq;
140 int stereo; 143 int stereo;
141 int users; 144 int users;
@@ -237,10 +240,7 @@ static void dsbr100_getstat(struct dsbr100_device *radio)
237/* handle unplugging of the device, release data structures 240/* handle unplugging of the device, release data structures
238if nothing keeps us from doing it. If something is still 241if nothing keeps us from doing it. If something is still
239keeping us busy, the release callback of v4l will take care 242keeping us busy, the release callback of v4l will take care
240of releasing it. stv680.c does not relase its private 243of releasing it. */
241data, so I don't do this here either. Checking out the
242code I'd expect I better did that, but if there's a memory
243leak here it's tiny (~50 bytes per disconnect) */
244static void usb_dsbr100_disconnect(struct usb_interface *intf) 244static void usb_dsbr100_disconnect(struct usb_interface *intf)
245{ 245{
246 struct dsbr100_device *radio = usb_get_intfdata(intf); 246 struct dsbr100_device *radio = usb_get_intfdata(intf);
@@ -250,6 +250,7 @@ static void usb_dsbr100_disconnect(struct usb_interface *intf)
250 video_unregister_device(radio->videodev); 250 video_unregister_device(radio->videodev);
251 radio->videodev = NULL; 251 radio->videodev = NULL;
252 if (radio->users) { 252 if (radio->users) {
253 kfree(radio->transfer_buffer);
253 kfree(radio); 254 kfree(radio);
254 } else { 255 } else {
255 radio->removed = 1; 256 radio->removed = 1;
@@ -425,6 +426,7 @@ static int usb_dsbr100_close(struct inode *inode, struct file *file)
425 return -ENODEV; 426 return -ENODEV;
426 radio->users = 0; 427 radio->users = 0;
427 if (radio->removed) { 428 if (radio->removed) {
429 kfree(radio->transfer_buffer);
428 kfree(radio); 430 kfree(radio);
429 } 431 }
430 return 0; 432 return 0;
@@ -471,7 +473,12 @@ static int usb_dsbr100_probe(struct usb_interface *intf,
471 473
472 if (!(radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL))) 474 if (!(radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL)))
473 return -ENOMEM; 475 return -ENOMEM;
476 if (!(radio->transfer_buffer = kmalloc(TB_LEN, GFP_KERNEL))) {
477 kfree(radio);
478 return -ENOMEM;
479 }
474 if (!(radio->videodev = video_device_alloc())) { 480 if (!(radio->videodev = video_device_alloc())) {
481 kfree(radio->transfer_buffer);
475 kfree(radio); 482 kfree(radio);
476 return -ENOMEM; 483 return -ENOMEM;
477 } 484 }
@@ -485,6 +492,7 @@ static int usb_dsbr100_probe(struct usb_interface *intf,
485 if (video_register_device(radio->videodev, VFL_TYPE_RADIO,radio_nr)) { 492 if (video_register_device(radio->videodev, VFL_TYPE_RADIO,radio_nr)) {
486 warn("Could not register video device"); 493 warn("Could not register video device");
487 video_device_release(radio->videodev); 494 video_device_release(radio->videodev);
495 kfree(radio->transfer_buffer);
488 kfree(radio); 496 kfree(radio);
489 return -EIO; 497 return -EIO;
490 } 498 }
diff --git a/drivers/media/radio/radio-gemtek.c b/drivers/media/radio/radio-gemtek.c
index 5e4b9ddb23c0..246422b49267 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -58,10 +58,10 @@ static int initmute = 1;
58static int radio_nr = -1; 58static int radio_nr = -1;
59 59
60module_param(io, int, 0444); 60module_param(io, int, 0444);
61MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic" 61MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic "
62 "probing is disabled or fails. The most common I/O ports are: 0x20c " 62 "probing is disabled or fails. The most common I/O ports are: 0x20c "
63 "0x30c, 0x24c or 0x34c (0x20c, 0x248 and 0x28c have been reported to " 63 "0x30c, 0x24c or 0x34c (0x20c, 0x248 and 0x28c have been reported to "
64 " work for the combined sound/radiocard)."); 64 "work for the combined sound/radiocard).");
65 65
66module_param(probe, bool, 0444); 66module_param(probe, bool, 0444);
67MODULE_PARM_DESC(probe, "Enable automatic device probing. Note: only the most " 67MODULE_PARM_DESC(probe, "Enable automatic device probing. Note: only the most "
@@ -392,7 +392,7 @@ static struct v4l2_queryctrl radio_qctrl[] = {
392 } 392 }
393}; 393};
394 394
395static struct file_operations gemtek_fops = { 395static const struct file_operations gemtek_fops = {
396 .owner = THIS_MODULE, 396 .owner = THIS_MODULE,
397 .open = video_exclusive_open, 397 .open = video_exclusive_open,
398 .release = video_exclusive_release, 398 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index 8e33a19a22a3..bc51f4d23a5a 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -423,7 +423,7 @@ static int __devinit maestro_probe(struct pci_dev *pdev,
423errunr: 423errunr:
424 video_unregister_device(maestro_radio_inst); 424 video_unregister_device(maestro_radio_inst);
425errfr1: 425errfr1:
426 kfree(maestro_radio_inst); 426 video_device_release(maestro_radio_inst);
427errfr: 427errfr:
428 kfree(radio_unit); 428 kfree(radio_unit);
429err: 429err:
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index 395165367f37..3118bdab3183 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -321,7 +321,7 @@ static struct isapnp_device_id id_table[] __devinitdata = {
321 321
322MODULE_DEVICE_TABLE(isapnp, id_table); 322MODULE_DEVICE_TABLE(isapnp, id_table);
323 323
324static int isapnp_fmi_probe(void) 324static int __init isapnp_fmi_probe(void)
325{ 325{
326 int i = 0; 326 int i = 0;
327 327
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index c432c44bd634..f7c8b000404f 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -476,8 +476,7 @@ static int __init fmr2_init(void)
476 return -EBUSY; 476 return -EBUSY;
477 } 477 }
478 478
479 if(video_register_device(&fmr2_radio, VFL_TYPE_RADIO, radio_nr)==-1) 479 if (video_register_device(&fmr2_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
480 {
481 release_region(io, 2); 480 release_region(io, 2);
482 return -EINVAL; 481 return -EINVAL;
483 } 482 }
diff --git a/drivers/media/radio/radio-si470x.c b/drivers/media/radio/radio-si470x.c
new file mode 100644
index 000000000000..8e4bd4769048
--- /dev/null
+++ b/drivers/media/radio/radio-si470x.c
@@ -0,0 +1,1432 @@
1/*
2 * drivers/media/radio/radio-si470x.c
3 *
4 * Driver for USB radios for the Silicon Labs Si470x FM Radio Receivers:
5 * - Silicon Labs USB FM Radio Reference Design
6 * - ADS/Tech FM Radio Receiver (formerly Instant FM Music) (RDX-155-EF)
7 *
8 * Copyright (c) 2008 Tobias Lorenz <tobias.lorenz@gmx.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25
26/*
27 * History:
28 * 2008-01-12 Tobias Lorenz <tobias.lorenz@gmx.net>
29 * Version 1.0.0
30 * - First working version
31 * 2008-01-13 Tobias Lorenz <tobias.lorenz@gmx.net>
32 * Version 1.0.1
33 * - Improved error handling, every function now returns errno
34 * - Improved multi user access (start/mute/stop)
35 * - Channel doesn't get lost anymore after start/mute/stop
36 * - RDS support added (polling mode via interrupt EP 1)
37 * - marked default module parameters with *value*
38 * - switched from bit structs to bit masks
39 * - header file cleaned and integrated
40 * 2008-01-14 Tobias Lorenz <tobias.lorenz@gmx.net>
41 * Version 1.0.2
42 * - hex values are now lower case
43 * - commented USB ID for ADS/Tech moved on todo list
44 * - blacklisted si470x in hid-quirks.c
45 * - rds buffer handling functions integrated into *_work, *_read
46 * - rds_command in si470x_poll exchanged against simple retval
47 * - check for firmware version 15
48 * - code order and prototypes still remain the same
49 * - spacing and bottom of band codes remain the same
50 * 2008-01-16 Tobias Lorenz <tobias.lorenz@gmx.net>
51 * Version 1.0.3
52 * - code reordered to avoid function prototypes
53 * - switch/case defaults are now more user-friendly
54 * - unified comment style
55 * - applied all checkpatch.pl v1.12 suggestions
56 * except the warning about the too long lines with bit comments
57 * - renamed FMRADIO to RADIO to cut line length (checkpatch.pl)
58 * 2008-01-22 Tobias Lorenz <tobias.lorenz@gmx.net>
59 * Version 1.0.4
60 * - avoid poss. locking when doing copy_to_user which may sleep
61 * - RDS is automatically activated on read now
62 * - code cleaned of unnecessary rds_commands
63 * - USB Vendor/Product ID for ADS/Tech FM Radio Receiver verified
64 * (thanks to Guillaume RAMOUSSE)
65 *
66 * ToDo:
67 * - add seeking support
68 * - add firmware download/update support
69 * - RDS support: interrupt mode, instead of polling
70 * - add LED status output (check if that's not already done in firmware)
71 */
72
73
74/* driver definitions */
75#define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>"
76#define DRIVER_NAME "radio-si470x"
77#define DRIVER_VERSION KERNEL_VERSION(1, 0, 4)
78#define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
79#define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers"
80
81
82/* kernel includes */
83#include <linux/kernel.h>
84#include <linux/module.h>
85#include <linux/init.h>
86#include <linux/slab.h>
87#include <linux/input.h>
88#include <linux/usb.h>
89#include <linux/hid.h>
90#include <linux/version.h>
91#include <linux/videodev2.h>
92#include <media/v4l2-common.h>
93#include <media/rds.h>
94
95
96/* USB Device ID List */
97static struct usb_device_id si470x_usb_driver_id_table[] = {
98 /* Silicon Labs USB FM Radio Reference Design */
99 { USB_DEVICE_AND_INTERFACE_INFO(0x10c4, 0x818a, USB_CLASS_HID, 0, 0) },
100 /* ADS/Tech FM Radio Receiver (formerly Instant FM Music) */
101 { USB_DEVICE_AND_INTERFACE_INFO(0x06e1, 0xa155, USB_CLASS_HID, 0, 0) },
102 /* Terminating entry */
103 { }
104};
105MODULE_DEVICE_TABLE(usb, si470x_usb_driver_id_table);
106
107
108
109/**************************************************************************
110 * Module Parameters
111 **************************************************************************/
112
113/* Radio Nr */
114static int radio_nr = -1;
115module_param(radio_nr, int, 0);
116MODULE_PARM_DESC(radio_nr, "Radio Nr");
117
118/* Spacing (kHz) */
119/* 0: 200 kHz (USA, Australia) */
120/* 1: 100 kHz (Europe, Japan) */
121/* 2: 50 kHz */
122static int space = 2;
123module_param(space, int, 0);
124MODULE_PARM_DESC(radio_nr, "Spacing: 0=200kHz 1=100kHz *2=50kHz*");
125
126/* Bottom of Band (MHz) */
127/* 0: 87.5 - 108 MHz (USA, Europe)*/
128/* 1: 76 - 108 MHz (Japan wide band) */
129/* 2: 76 - 90 MHz (Japan) */
130static int band = 1;
131module_param(band, int, 0);
132MODULE_PARM_DESC(radio_nr, "Band: 0=87.5..108MHz *1=76..108MHz* 2=76..90MHz");
133
134/* De-emphasis */
135/* 0: 75 us (USA) */
136/* 1: 50 us (Europe, Australia, Japan) */
137static int de = 1;
138module_param(de, int, 0);
139MODULE_PARM_DESC(radio_nr, "De-emphasis: 0=75us *1=50us*");
140
141/* USB timeout */
142static int usb_timeout = 500;
143module_param(usb_timeout, int, 0);
144MODULE_PARM_DESC(usb_timeout, "USB timeout (ms): *500*");
145
146/* Seek retries */
147static int seek_retries = 100;
148module_param(seek_retries, int, 0);
149MODULE_PARM_DESC(seek_retries, "Seek retries: *100*");
150
151/* RDS buffer blocks */
152static int rds_buf = 100;
153module_param(rds_buf, int, 0);
154MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*");
155
156/* RDS maximum block errors */
157static int max_rds_errors = 1;
158/* 0 means 0 errors requiring correction */
159/* 1 means 1-2 errors requiring correction (used by original USBRadio.exe) */
160/* 2 means 3-5 errors requiring correction */
161/* 3 means 6+ errors or errors in checkword, correction not possible */
162module_param(max_rds_errors, int, 0);
163MODULE_PARM_DESC(max_rds_errors, "RDS maximum block errors: *1*");
164
165/* RDS poll frequency */
166static int rds_poll_time = 40;
167/* 40 is used by the original USBRadio.exe */
168/* 50 is used by radio-cadet */
169/* 75 should be okay */
170/* 80 is the usual RDS receive interval */
171module_param(rds_poll_time, int, 0);
172MODULE_PARM_DESC(rds_poll_time, "RDS poll time (ms): *40*");
173
174
175
176/**************************************************************************
177 * Register Definitions
178 **************************************************************************/
179#define RADIO_REGISTER_SIZE 2 /* 16 register bit width */
180#define RADIO_REGISTER_NUM 16 /* DEVICEID ... RDSD */
181#define RDS_REGISTER_NUM 6 /* STATUSRSSI ... RDSD */
182
183#define DEVICEID 0 /* Device ID */
184#define DEVICEID_PN 0xf000 /* bits 15..12: Part Number */
185#define DEVICEID_MFGID 0x0fff /* bits 11..00: Manufacturer ID */
186
187#define CHIPID 1 /* Chip ID */
188#define CHIPID_REV 0xfc00 /* bits 15..10: Chip Version */
189#define CHIPID_DEV 0x0200 /* bits 09..09: Device */
190#define CHIPID_FIRMWARE 0x01ff /* bits 08..00: Firmware Version */
191
192#define POWERCFG 2 /* Power Configuration */
193#define POWERCFG_DSMUTE 0x8000 /* bits 15..15: Softmute Disable */
194#define POWERCFG_DMUTE 0x4000 /* bits 14..14: Mute Disable */
195#define POWERCFG_MONO 0x2000 /* bits 13..13: Mono Select */
196#define POWERCFG_RDSM 0x0800 /* bits 11..11: RDS Mode (Si4701 only) */
197#define POWERCFG_SKMODE 0x0400 /* bits 10..10: Seek Mode */
198#define POWERCFG_SEEKUP 0x0200 /* bits 09..09: Seek Direction */
199#define POWERCFG_SEEK 0x0100 /* bits 08..08: Seek */
200#define POWERCFG_DISABLE 0x0040 /* bits 06..06: Powerup Disable */
201#define POWERCFG_ENABLE 0x0001 /* bits 00..00: Powerup Enable */
202
203#define CHANNEL 3 /* Channel */
204#define CHANNEL_TUNE 0x8000 /* bits 15..15: Tune */
205#define CHANNEL_CHAN 0x03ff /* bits 09..00: Channel Select */
206
207#define SYSCONFIG1 4 /* System Configuration 1 */
208#define SYSCONFIG1_RDSIEN 0x8000 /* bits 15..15: RDS Interrupt Enable (Si4701 only) */
209#define SYSCONFIG1_STCIEN 0x4000 /* bits 14..14: Seek/Tune Complete Interrupt Enable */
210#define SYSCONFIG1_RDS 0x1000 /* bits 12..12: RDS Enable (Si4701 only) */
211#define SYSCONFIG1_DE 0x0800 /* bits 11..11: De-emphasis (0=75us 1=50us) */
212#define SYSCONFIG1_AGCD 0x0400 /* bits 10..10: AGC Disable */
213#define SYSCONFIG1_BLNDADJ 0x00c0 /* bits 07..06: Stereo/Mono Blend Level Adjustment */
214#define SYSCONFIG1_GPIO3 0x0030 /* bits 05..04: General Purpose I/O 3 */
215#define SYSCONFIG1_GPIO2 0x000c /* bits 03..02: General Purpose I/O 2 */
216#define SYSCONFIG1_GPIO1 0x0003 /* bits 01..00: General Purpose I/O 1 */
217
218#define SYSCONFIG2 5 /* System Configuration 2 */
219#define SYSCONFIG2_SEEKTH 0xff00 /* bits 15..08: RSSI Seek Threshold */
220#define SYSCONFIG2_BAND 0x0080 /* bits 07..06: Band Select */
221#define SYSCONFIG2_SPACE 0x0030 /* bits 05..04: Channel Spacing */
222#define SYSCONFIG2_VOLUME 0x000f /* bits 03..00: Volume */
223
224#define SYSCONFIG3 6 /* System Configuration 3 */
225#define SYSCONFIG3_SMUTER 0xc000 /* bits 15..14: Softmute Attack/Recover Rate */
226#define SYSCONFIG3_SMUTEA 0x3000 /* bits 13..12: Softmute Attenuation */
227#define SYSCONFIG3_SKSNR 0x00f0 /* bits 07..04: Seek SNR Threshold */
228#define SYSCONFIG3_SKCNT 0x000f /* bits 03..00: Seek FM Impulse Detection Threshold */
229
230#define TEST1 7 /* Test 1 */
231#define TEST1_AHIZEN 0x4000 /* bits 14..14: Audio High-Z Enable */
232
233#define TEST2 8 /* Test 2 */
234/* TEST2 only contains reserved bits */
235
236#define BOOTCONFIG 9 /* Boot Configuration */
237/* BOOTCONFIG only contains reserved bits */
238
239#define STATUSRSSI 10 /* Status RSSI */
240#define STATUSRSSI_RDSR 0x8000 /* bits 15..15: RDS Ready (Si4701 only) */
241#define STATUSRSSI_STC 0x4000 /* bits 14..14: Seek/Tune Complete */
242#define STATUSRSSI_SF 0x2000 /* bits 13..13: Seek Fail/Band Limit */
243#define STATUSRSSI_AFCRL 0x1000 /* bits 12..12: AFC Rail */
244#define STATUSRSSI_RDSS 0x0800 /* bits 11..11: RDS Synchronized (Si4701 only) */
245#define STATUSRSSI_BLERA 0x0600 /* bits 10..09: RDS Block A Errors (Si4701 only) */
246#define STATUSRSSI_ST 0x0100 /* bits 08..08: Stereo Indicator */
247#define STATUSRSSI_RSSI 0x00ff /* bits 07..00: RSSI (Received Signal Strength Indicator) */
248
249#define READCHAN 11 /* Read Channel */
250#define READCHAN_BLERB 0xc000 /* bits 15..14: RDS Block D Errors (Si4701 only) */
251#define READCHAN_BLERC 0x3000 /* bits 13..12: RDS Block C Errors (Si4701 only) */
252#define READCHAN_BLERD 0x0c00 /* bits 11..10: RDS Block B Errors (Si4701 only) */
253#define READCHAN_READCHAN 0x03ff /* bits 09..00: Read Channel */
254
255#define RDSA 12 /* RDSA */
256#define RDSA_RDSA 0xffff /* bits 15..00: RDS Block A Data (Si4701 only) */
257
258#define RDSB 13 /* RDSB */
259#define RDSB_RDSB 0xffff /* bits 15..00: RDS Block B Data (Si4701 only) */
260
261#define RDSC 14 /* RDSC */
262#define RDSC_RDSC 0xffff /* bits 15..00: RDS Block C Data (Si4701 only) */
263
264#define RDSD 15 /* RDSD */
265#define RDSD_RDSD 0xffff /* bits 15..00: RDS Block D Data (Si4701 only) */
266
267
268
269/**************************************************************************
270 * USB HID Reports
271 **************************************************************************/
272
273/* Reports 1-16 give direct read/write access to the 16 Si470x registers */
274/* with the (REPORT_ID - 1) corresponding to the register address across USB */
275/* endpoint 0 using GET_REPORT and SET_REPORT */
276#define REGISTER_REPORT_SIZE (RADIO_REGISTER_SIZE + 1)
277#define REGISTER_REPORT(reg) ((reg) + 1)
278
279/* Report 17 gives direct read/write access to the entire Si470x register */
280/* map across endpoint 0 using GET_REPORT and SET_REPORT */
281#define ENTIRE_REPORT_SIZE (RADIO_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
282#define ENTIRE_REPORT 17
283
284/* Report 18 is used to send the lowest 6 Si470x registers up the HID */
285/* interrupt endpoint 1 to Windows every 20 milliseconds for status */
286#define RDS_REPORT_SIZE (RDS_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
287#define RDS_REPORT 18
288
289/* Report 19: LED state */
290#define LED_REPORT_SIZE 3
291#define LED_REPORT 19
292
293/* Report 19: stream */
294#define STREAM_REPORT_SIZE 3
295#define STREAM_REPORT 19
296
297/* Report 20: scratch */
298#define SCRATCH_PAGE_SIZE 63
299#define SCRATCH_REPORT_SIZE (SCRATCH_PAGE_SIZE + 1)
300#define SCRATCH_REPORT 20
301
302/* Reports 19-22: flash upgrade of the C8051F321 */
303#define WRITE_REPORT 19
304#define FLASH_REPORT 20
305#define CRC_REPORT 21
306#define RESPONSE_REPORT 22
307
308/* Report 23: currently unused, but can accept 60 byte reports on the HID */
309/* interrupt out endpoint 2 every 1 millisecond */
310#define UNUSED_REPORT 23
311
312
313
314/**************************************************************************
315 * Software/Hardware Versions
316 **************************************************************************/
317#define RADIO_SW_VERSION_NOT_BOOTLOADABLE 6
318#define RADIO_SW_VERSION 7
319#define RADIO_SW_VERSION_CURRENT 15
320#define RADIO_HW_VERSION 1
321
322#define SCRATCH_PAGE_SW_VERSION 1
323#define SCRATCH_PAGE_HW_VERSION 2
324
325
326
327/**************************************************************************
328 * LED State Definitions
329 **************************************************************************/
330#define LED_COMMAND 0x35
331
332#define NO_CHANGE_LED 0x00
333#define ALL_COLOR_LED 0x01 /* streaming state */
334#define BLINK_GREEN_LED 0x02 /* connect state */
335#define BLINK_RED_LED 0x04
336#define BLINK_ORANGE_LED 0x10 /* disconnect state */
337#define SOLID_GREEN_LED 0x20 /* tuning/seeking state */
338#define SOLID_RED_LED 0x40 /* bootload state */
339#define SOLID_ORANGE_LED 0x80
340
341
342
343/**************************************************************************
344 * Stream State Definitions
345 **************************************************************************/
346#define STREAM_COMMAND 0x36
347#define STREAM_VIDPID 0x00
348#define STREAM_AUDIO 0xff
349
350
351
352/**************************************************************************
353 * Bootloader / Flash Commands
354 **************************************************************************/
355
356/* unique id sent to bootloader and required to put into a bootload state */
357#define UNIQUE_BL_ID 0x34
358
359/* mask for the flash data */
360#define FLASH_DATA_MASK 0x55
361
362/* bootloader commands */
363#define GET_SW_VERSION_COMMAND 0x00
364#define SET_PAGE_COMMAND 0x01
365#define ERASE_PAGE_COMMAND 0x02
366#define WRITE_PAGE_COMMAND 0x03
367#define CRC_ON_PAGE_COMMAND 0x04
368#define READ_FLASH_BYTE_COMMAND 0x05
369#define RESET_DEVICE_COMMAND 0x06
370#define GET_HW_VERSION_COMMAND 0x07
371#define BLANK 0xff
372
373/* bootloader command responses */
374#define COMMAND_OK 0x01
375#define COMMAND_FAILED 0x02
376#define COMMAND_PENDING 0x03
377
378/* buffer sizes */
379#define COMMAND_BUFFER_SIZE 4
380#define RESPONSE_BUFFER_SIZE 2
381#define FLASH_BUFFER_SIZE 64
382#define CRC_BUFFER_SIZE 3
383
384
385
386/**************************************************************************
387 * General Driver Definitions
388 **************************************************************************/
389
390/*
391 * si470x_device - private data
392 */
393struct si470x_device {
394 /* reference to USB and video device */
395 struct usb_device *usbdev;
396 struct video_device *videodev;
397
398 /* are these really necessary ? */
399 int users;
400
401 /* report buffer (maximum 64 bytes) */
402 unsigned char buf[64];
403
404 /* Silabs internal registers (0..15) */
405 unsigned short registers[RADIO_REGISTER_NUM];
406
407 /* RDS receive buffer */
408 struct work_struct work;
409 wait_queue_head_t read_queue;
410 struct timer_list timer;
411 spinlock_t lock; /* buffer locking */
412 unsigned char *buffer; /* size is always multiple of three */
413 unsigned int buf_size;
414 unsigned int rd_index;
415 unsigned int wr_index;
416};
417
418
419/*
420 * The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW,
421 * 62.5 kHz otherwise.
422 * The tuner is able to have a channel spacing of 50, 100 or 200 kHz.
423 * tuner->capability is therefore set to V4L2_TUNER_CAP_LOW
424 * The FREQ_MUL is then: 1 MHz / 62.5 Hz = 16000
425 */
426#define FREQ_MUL (1000000 / 62.5)
427
428
429
430/**************************************************************************
431 * General Driver Functions
432 **************************************************************************/
433
434/*
435 * si470x_get_report - receive a HID report
436 */
437static int si470x_get_report(struct si470x_device *radio, int size)
438{
439 return usb_control_msg(radio->usbdev,
440 usb_rcvctrlpipe(radio->usbdev, 0),
441 HID_REQ_GET_REPORT,
442 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
443 radio->buf[0], 2,
444 radio->buf, size, usb_timeout);
445}
446
447
448/*
449 * si470x_set_report - send a HID report
450 */
451static int si470x_set_report(struct si470x_device *radio, int size)
452{
453 return usb_control_msg(radio->usbdev,
454 usb_sndctrlpipe(radio->usbdev, 0),
455 HID_REQ_SET_REPORT,
456 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
457 radio->buf[0], 2,
458 radio->buf, size, usb_timeout);
459}
460
461
462/*
463 * si470x_get_register - read register
464 */
465static int si470x_get_register(struct si470x_device *radio, int regnr)
466{
467 int retval;
468
469 radio->buf[0] = REGISTER_REPORT(regnr);
470
471 retval = si470x_get_report(radio, REGISTER_REPORT_SIZE);
472 if (retval >= 0)
473 radio->registers[regnr] = (radio->buf[1] << 8) | radio->buf[2];
474
475 return (retval < 0) ? -EINVAL : 0;
476}
477
478
479/*
480 * si470x_set_register - write register
481 */
482static int si470x_set_register(struct si470x_device *radio, int regnr)
483{
484 int retval;
485
486 radio->buf[0] = REGISTER_REPORT(regnr);
487 radio->buf[1] = (radio->registers[regnr] & 0xff00) >> 8;
488 radio->buf[2] = (radio->registers[regnr] & 0x00ff);
489
490 retval = si470x_set_report(radio, REGISTER_REPORT_SIZE);
491
492 return (retval < 0) ? -EINVAL : 0;
493}
494
495
496/*
497 * si470x_get_all_registers - read entire registers
498 */
499static int si470x_get_all_registers(struct si470x_device *radio)
500{
501 int retval;
502 int regnr;
503
504 radio->buf[0] = ENTIRE_REPORT;
505
506 retval = si470x_get_report(radio, ENTIRE_REPORT_SIZE);
507
508 if (retval >= 0)
509 for (regnr = 0; regnr < RADIO_REGISTER_NUM; regnr++)
510 radio->registers[regnr] =
511 (radio->buf[regnr * RADIO_REGISTER_SIZE + 1] << 8) |
512 radio->buf[regnr * RADIO_REGISTER_SIZE + 2];
513
514 return (retval < 0) ? -EINVAL : 0;
515}
516
517
518/*
519 * si470x_get_rds_registers - read rds registers
520 */
521static int si470x_get_rds_registers(struct si470x_device *radio)
522{
523 int retval;
524 int regnr;
525 int size;
526
527 radio->buf[0] = RDS_REPORT;
528
529 retval = usb_interrupt_msg(radio->usbdev,
530 usb_rcvctrlpipe(radio->usbdev, 1),
531 radio->buf, RDS_REPORT_SIZE, &size, usb_timeout);
532
533 if (retval >= 0)
534 for (regnr = 0; regnr < RDS_REGISTER_NUM; regnr++)
535 radio->registers[STATUSRSSI + regnr] =
536 (radio->buf[regnr * RADIO_REGISTER_SIZE + 1] << 8) |
537 radio->buf[regnr * RADIO_REGISTER_SIZE + 2];
538
539 return (retval < 0) ? -EINVAL : 0;
540}
541
542
543/*
544 * si470x_set_chan - set the channel
545 */
546static int si470x_set_chan(struct si470x_device *radio, int chan)
547{
548 int retval, i;
549
550 /* start tuning */
551 radio->registers[CHANNEL] &= ~CHANNEL_CHAN;
552 radio->registers[CHANNEL] |= CHANNEL_TUNE | chan;
553 retval = si470x_set_register(radio, CHANNEL);
554 if (retval < 0)
555 return retval;
556
557 /* wait till seek operation has completed */
558 i = 0;
559 do {
560 retval = si470x_get_register(radio, STATUSRSSI);
561 if (retval < 0)
562 return retval;
563 } while ((radio->registers[STATUSRSSI] & STATUSRSSI_STC) &&
564 (++i < seek_retries));
565 if (i >= seek_retries)
566 printk(KERN_WARNING DRIVER_NAME
567 ": seek does not finish after %d tries\n", i);
568
569 /* stop tuning */
570 radio->registers[CHANNEL] &= ~CHANNEL_TUNE;
571 return si470x_set_register(radio, CHANNEL);
572}
573
574
575/*
576 * si470x_get_freq - get the frequency
577 */
578static int si470x_get_freq(struct si470x_device *radio)
579{
580 int spacing, band_bottom, chan, freq;
581 int retval;
582
583 /* Spacing (kHz) */
584 switch (space) {
585 /* 0: 200 kHz (USA, Australia) */
586 case 0 : spacing = 0.200 * FREQ_MUL; break;
587 /* 1: 100 kHz (Europe, Japan) */
588 case 1 : spacing = 0.100 * FREQ_MUL; break;
589 /* 2: 50 kHz */
590 default: spacing = 0.050 * FREQ_MUL; break;
591 };
592
593 /* Bottom of Band (MHz) */
594 switch (band) {
595 /* 0: 87.5 - 108 MHz (USA, Europe) */
596 case 0 : band_bottom = 87.5 * FREQ_MUL; break;
597 /* 1: 76 - 108 MHz (Japan wide band) */
598 default: band_bottom = 76 * FREQ_MUL; break;
599 /* 2: 76 - 90 MHz (Japan) */
600 case 2 : band_bottom = 76 * FREQ_MUL; break;
601 };
602
603 /* read channel */
604 retval = si470x_get_register(radio, READCHAN);
605 if (retval < 0)
606 return retval;
607 chan = radio->registers[READCHAN] & READCHAN_READCHAN;
608
609 /* Frequency (MHz) = Spacing (kHz) x Channel + Bottom of Band (MHz) */
610 freq = chan * spacing + band_bottom;
611
612 return freq;
613}
614
615
616/*
617 * si470x_set_freq - set the frequency
618 */
619static int si470x_set_freq(struct si470x_device *radio, int freq)
620{
621 int spacing, band_bottom, chan;
622
623 /* Spacing (kHz) */
624 switch (space) {
625 /* 0: 200 kHz (USA, Australia) */
626 case 0 : spacing = 0.200 * FREQ_MUL; break;
627 /* 1: 100 kHz (Europe, Japan) */
628 case 1 : spacing = 0.100 * FREQ_MUL; break;
629 /* 2: 50 kHz */
630 default: spacing = 0.050 * FREQ_MUL; break;
631 };
632
633 /* Bottom of Band (MHz) */
634 switch (band) {
635 /* 0: 87.5 - 108 MHz (USA, Europe) */
636 case 0 : band_bottom = 87.5 * FREQ_MUL; break;
637 /* 1: 76 - 108 MHz (Japan wide band) */
638 default: band_bottom = 76 * FREQ_MUL; break;
639 /* 2: 76 - 90 MHz (Japan) */
640 case 2 : band_bottom = 76 * FREQ_MUL; break;
641 };
642
643 /* Chan = [ Freq (Mhz) - Bottom of Band (MHz) ] / Spacing (kHz) */
644 chan = (freq - band_bottom) / spacing;
645
646 return si470x_set_chan(radio, chan);
647}
648
649
650/*
651 * si470x_start - switch on radio
652 */
653static int si470x_start(struct si470x_device *radio)
654{
655 int retval;
656
657 /* powercfg */
658 radio->registers[POWERCFG] =
659 POWERCFG_DMUTE | POWERCFG_ENABLE | POWERCFG_RDSM;
660 retval = si470x_set_register(radio, POWERCFG);
661 if (retval < 0)
662 return retval;
663
664 /* sysconfig 1 */
665 radio->registers[SYSCONFIG1] = SYSCONFIG1_DE;
666 retval = si470x_set_register(radio, SYSCONFIG1);
667 if (retval < 0)
668 return retval;
669
670 /* sysconfig 2 */
671 radio->registers[SYSCONFIG2] =
672 (0x3f << 8) | /* SEEKTH */
673 (band << 6) | /* BAND */
674 (space << 4) | /* SPACE */
675 15; /* VOLUME (max) */
676 retval = si470x_set_register(radio, SYSCONFIG2);
677 if (retval < 0)
678 return retval;
679
680 /* reset last channel */
681 return si470x_set_chan(radio,
682 radio->registers[CHANNEL] & CHANNEL_CHAN);
683}
684
685
686/*
687 * si470x_stop - switch off radio
688 */
689static int si470x_stop(struct si470x_device *radio)
690{
691 int retval;
692
693 /* sysconfig 1 */
694 radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS;
695 retval = si470x_set_register(radio, SYSCONFIG1);
696 if (retval < 0)
697 return retval;
698
699 /* powercfg */
700 radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
701 /* POWERCFG_ENABLE has to automatically go low */
702 radio->registers[POWERCFG] |= POWERCFG_ENABLE | POWERCFG_DISABLE;
703 return si470x_set_register(radio, POWERCFG);
704}
705
706
707/*
708 * si470x_rds_on - switch on rds reception
709 */
710static int si470x_rds_on(struct si470x_device *radio)
711{
712 /* sysconfig 1 */
713 radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDS;
714 return si470x_set_register(radio, SYSCONFIG1);
715}
716
717
718
719/**************************************************************************
720 * RDS Driver Functions
721 **************************************************************************/
722
723/*
724 * si470x_rds - rds processing function
725 */
726static void si470x_rds(struct si470x_device *radio)
727{
728 unsigned char tmpbuf[3];
729 unsigned char blocknum;
730 unsigned char bler; /* rds block errors */
731 unsigned short rds;
732 unsigned int i;
733
734 /* get rds blocks */
735 if (si470x_get_rds_registers(radio) < 0)
736 return;
737 if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSR) == 0) {
738 /* No RDS group ready */
739 return;
740 }
741 if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSS) == 0) {
742 /* RDS decoder not synchronized */
743 return;
744 }
745
746 /* copy four RDS blocks to internal buffer */
747 if (spin_trylock(&radio->lock)) {
748 /* process each rds block */
749 for (blocknum = 0; blocknum < 4; blocknum++) {
750 switch (blocknum) {
751 default:
752 bler = (radio->registers[STATUSRSSI] &
753 STATUSRSSI_BLERA) >> 9;
754 rds = radio->registers[RDSA];
755 break;
756 case 1:
757 bler = (radio->registers[READCHAN] &
758 READCHAN_BLERB) >> 14;
759 rds = radio->registers[RDSB];
760 break;
761 case 2:
762 bler = (radio->registers[READCHAN] &
763 READCHAN_BLERC) >> 12;
764 rds = radio->registers[RDSC];
765 break;
766 case 3:
767 bler = (radio->registers[READCHAN] &
768 READCHAN_BLERD) >> 10;
769 rds = radio->registers[RDSD];
770 break;
771 };
772
773 /* Fill the V4L2 RDS buffer */
774 tmpbuf[0] = rds & 0x00ff; /* LSB */
775 tmpbuf[1] = (rds & 0xff00) >> 8;/* MSB */
776 tmpbuf[2] = blocknum; /* offset name */
777 tmpbuf[2] |= blocknum << 3; /* received offset */
778 if (bler > max_rds_errors)
779 tmpbuf[2] |= 0x80; /* uncorrectable errors */
780 else if (bler > 0)
781 tmpbuf[2] |= 0x40; /* corrected error(s) */
782
783 /* copy RDS block to internal buffer */
784 for (i = 0; i < 3; i++) {
785 radio->buffer[radio->wr_index] = tmpbuf[i];
786 radio->wr_index++;
787 }
788
789 /* wrap write pointer */
790 if (radio->wr_index >= radio->buf_size)
791 radio->wr_index = 0;
792
793 /* check for overflow */
794 if (radio->wr_index == radio->rd_index) {
795 /* increment and wrap read pointer */
796 radio->rd_index += 3;
797 if (radio->rd_index >= radio->buf_size)
798 radio->rd_index = 0;
799 }
800 }
801 spin_unlock(&radio->lock);
802 }
803
804 /* wake up read queue */
805 if (radio->wr_index != radio->rd_index)
806 wake_up_interruptible(&radio->read_queue);
807}
808
809
810/*
811 * si470x_timer - rds timer function
812 */
813static void si470x_timer(unsigned long data)
814{
815 struct si470x_device *radio = (struct si470x_device *) data;
816
817 schedule_work(&radio->work);
818}
819
820
821/*
822 * si470x_work - rds work function
823 */
824static void si470x_work(struct work_struct *work)
825{
826 struct si470x_device *radio = container_of(work, struct si470x_device,
827 work);
828
829 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
830 return;
831
832 si470x_rds(radio);
833 mod_timer(&radio->timer, jiffies + msecs_to_jiffies(rds_poll_time));
834}
835
836
837
838/**************************************************************************
839 * File Operations Interface
840 **************************************************************************/
841
842/*
843 * si470x_fops_read - read RDS data
844 */
845static ssize_t si470x_fops_read(struct file *file, char __user *buf,
846 size_t count, loff_t *ppos)
847{
848 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
849 int retval = 0;
850 unsigned int block_count = 0;
851
852 /* switch on rds reception */
853 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) {
854 si470x_rds_on(radio);
855 schedule_work(&radio->work);
856 }
857
858 /* block if no new data available */
859 while (radio->wr_index == radio->rd_index) {
860 if (file->f_flags & O_NONBLOCK)
861 return -EWOULDBLOCK;
862 interruptible_sleep_on(&radio->read_queue);
863 }
864
865 /* calculate block count from byte count */
866 count /= 3;
867
868 /* copy RDS block out of internal buffer and to user buffer */
869 if (spin_trylock(&radio->lock)) {
870 while (block_count < count) {
871 if (radio->rd_index == radio->wr_index)
872 break;
873
874 /* always transfer rds complete blocks */
875 if (copy_to_user(buf,
876 &radio->buffer[radio->rd_index], 3))
877 /* retval = -EFAULT; */
878 break;
879
880 /* increment and wrap read pointer */
881 radio->rd_index += 3;
882 if (radio->rd_index >= radio->buf_size)
883 radio->rd_index = 0;
884
885 /* increment counters */
886 block_count++;
887 buf += 3;
888 retval += 3;
889 }
890
891 spin_unlock(&radio->lock);
892 }
893
894 return retval;
895}
896
897
898/*
899 * si470x_fops_poll - poll RDS data
900 */
901static unsigned int si470x_fops_poll(struct file *file,
902 struct poll_table_struct *pts)
903{
904 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
905
906 /* switch on rds reception */
907 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) {
908 si470x_rds_on(radio);
909 schedule_work(&radio->work);
910 }
911
912 poll_wait(file, &radio->read_queue, pts);
913
914 if (radio->rd_index != radio->wr_index)
915 return POLLIN | POLLRDNORM;
916
917 return 0;
918}
919
920
921/*
922 * si470x_fops_open - file open
923 */
924static int si470x_fops_open(struct inode *inode, struct file *file)
925{
926 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
927
928 radio->users++;
929 if (radio->users == 1)
930 return si470x_start(radio);
931
932 return 0;
933}
934
935
936/*
937 * si470x_fops_release - file release
938 */
939static int si470x_fops_release(struct inode *inode, struct file *file)
940{
941 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
942
943 if (!radio)
944 return -ENODEV;
945
946 radio->users--;
947 if (radio->users == 0) {
948 /* stop rds reception */
949 del_timer_sync(&radio->timer);
950 flush_scheduled_work();
951
952 /* cancel read processes */
953 wake_up_interruptible(&radio->read_queue);
954
955 return si470x_stop(radio);
956 }
957
958 return 0;
959}
960
961
962/*
963 * si470x_fops - file operations interface
964 */
965static const struct file_operations si470x_fops = {
966 .owner = THIS_MODULE,
967 .llseek = no_llseek,
968 .read = si470x_fops_read,
969 .poll = si470x_fops_poll,
970 .ioctl = video_ioctl2,
971 .compat_ioctl = v4l_compat_ioctl32,
972 .open = si470x_fops_open,
973 .release = si470x_fops_release,
974};
975
976
977
978/**************************************************************************
979 * Video4Linux Interface
980 **************************************************************************/
981
982/*
983 * si470x_v4l2_queryctrl - query control
984 */
985static struct v4l2_queryctrl si470x_v4l2_queryctrl[] = {
986/* HINT: the disabled controls are only here to satify kradio and such apps */
987 {
988 .id = V4L2_CID_AUDIO_VOLUME,
989 .type = V4L2_CTRL_TYPE_INTEGER,
990 .name = "Volume",
991 .minimum = 0,
992 .maximum = 15,
993 .step = 1,
994 .default_value = 15,
995 },
996 {
997 .id = V4L2_CID_AUDIO_BALANCE,
998 .flags = V4L2_CTRL_FLAG_DISABLED,
999 },
1000 {
1001 .id = V4L2_CID_AUDIO_BASS,
1002 .flags = V4L2_CTRL_FLAG_DISABLED,
1003 },
1004 {
1005 .id = V4L2_CID_AUDIO_TREBLE,
1006 .flags = V4L2_CTRL_FLAG_DISABLED,
1007 },
1008 {
1009 .id = V4L2_CID_AUDIO_MUTE,
1010 .type = V4L2_CTRL_TYPE_BOOLEAN,
1011 .name = "Mute",
1012 .minimum = 0,
1013 .maximum = 1,
1014 .step = 1,
1015 .default_value = 1,
1016 },
1017 {
1018 .id = V4L2_CID_AUDIO_LOUDNESS,
1019 .flags = V4L2_CTRL_FLAG_DISABLED,
1020 },
1021};
1022
1023
1024/*
1025 * si470x_vidioc_querycap - query device capabilities
1026 */
1027static int si470x_vidioc_querycap(struct file *file, void *priv,
1028 struct v4l2_capability *capability)
1029{
1030 strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
1031 strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
1032 sprintf(capability->bus_info, "USB");
1033 capability->version = DRIVER_VERSION;
1034 capability->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
1035
1036 return 0;
1037}
1038
1039
1040/*
1041 * si470x_vidioc_g_input - get input
1042 */
1043static int si470x_vidioc_g_input(struct file *filp, void *priv,
1044 unsigned int *i)
1045{
1046 *i = 0;
1047
1048 return 0;
1049}
1050
1051
1052/*
1053 * si470x_vidioc_s_input - set input
1054 */
1055static int si470x_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
1056{
1057 if (i != 0)
1058 return -EINVAL;
1059
1060 return 0;
1061}
1062
1063
1064/*
1065 * si470x_vidioc_queryctrl - enumerate control items
1066 */
1067static int si470x_vidioc_queryctrl(struct file *file, void *priv,
1068 struct v4l2_queryctrl *qc)
1069{
1070 int i;
1071
1072 for (i = 0; i < ARRAY_SIZE(si470x_v4l2_queryctrl); i++) {
1073 if (qc->id && qc->id == si470x_v4l2_queryctrl[i].id) {
1074 memcpy(qc, &(si470x_v4l2_queryctrl[i]), sizeof(*qc));
1075 return 0;
1076 }
1077 }
1078
1079 return -EINVAL;
1080}
1081
1082
1083/*
1084 * si470x_vidioc_g_ctrl - get the value of a control
1085 */
1086static int si470x_vidioc_g_ctrl(struct file *file, void *priv,
1087 struct v4l2_control *ctrl)
1088{
1089 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1090
1091 switch (ctrl->id) {
1092 case V4L2_CID_AUDIO_VOLUME:
1093 ctrl->value = radio->registers[SYSCONFIG2] &
1094 SYSCONFIG2_VOLUME;
1095 break;
1096 case V4L2_CID_AUDIO_MUTE:
1097 ctrl->value = ((radio->registers[POWERCFG] &
1098 POWERCFG_DMUTE) == 0) ? 1 : 0;
1099 break;
1100 }
1101
1102 return 0;
1103}
1104
1105
1106/*
1107 * si470x_vidioc_s_ctrl - set the value of a control
1108 */
1109static int si470x_vidioc_s_ctrl(struct file *file, void *priv,
1110 struct v4l2_control *ctrl)
1111{
1112 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1113
1114 switch (ctrl->id) {
1115 case V4L2_CID_AUDIO_VOLUME:
1116 radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_VOLUME;
1117 radio->registers[SYSCONFIG2] |= ctrl->value;
1118 return si470x_set_register(radio, SYSCONFIG2);
1119 case V4L2_CID_AUDIO_MUTE:
1120 if (ctrl->value == 1)
1121 radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
1122 else
1123 radio->registers[POWERCFG] |= POWERCFG_DMUTE;
1124 return si470x_set_register(radio, POWERCFG);
1125 }
1126
1127 return -EINVAL;
1128}
1129
1130
1131/*
1132 * si470x_vidioc_g_audio - get audio attributes
1133 */
1134static int si470x_vidioc_g_audio(struct file *file, void *priv,
1135 struct v4l2_audio *audio)
1136{
1137 if (audio->index > 1)
1138 return -EINVAL;
1139
1140 strcpy(audio->name, "Radio");
1141 audio->capability = V4L2_AUDCAP_STEREO;
1142
1143 return 0;
1144}
1145
1146
1147/*
1148 * si470x_vidioc_s_audio - set audio attributes
1149 */
1150static int si470x_vidioc_s_audio(struct file *file, void *priv,
1151 struct v4l2_audio *audio)
1152{
1153 if (audio->index != 0)
1154 return -EINVAL;
1155
1156 return 0;
1157}
1158
1159
1160/*
1161 * si470x_vidioc_g_tuner - get tuner attributes
1162 */
1163static int si470x_vidioc_g_tuner(struct file *file, void *priv,
1164 struct v4l2_tuner *tuner)
1165{
1166 int retval;
1167 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1168
1169 if (tuner->index > 0)
1170 return -EINVAL;
1171
1172 /* read status rssi */
1173 retval = si470x_get_register(radio, STATUSRSSI);
1174 if (retval < 0)
1175 return retval;
1176
1177 strcpy(tuner->name, "FM");
1178 tuner->type = V4L2_TUNER_RADIO;
1179 switch (band) {
1180 /* 0: 87.5 - 108 MHz (USA, Europe, default) */
1181 default:
1182 tuner->rangelow = 87.5 * FREQ_MUL;
1183 tuner->rangehigh = 108 * FREQ_MUL;
1184 break;
1185 /* 1: 76 - 108 MHz (Japan wide band) */
1186 case 1 :
1187 tuner->rangelow = 76 * FREQ_MUL;
1188 tuner->rangehigh = 108 * FREQ_MUL;
1189 break;
1190 /* 2: 76 - 90 MHz (Japan) */
1191 case 2 :
1192 tuner->rangelow = 76 * FREQ_MUL;
1193 tuner->rangehigh = 90 * FREQ_MUL;
1194 break;
1195 };
1196 tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
1197 tuner->capability = V4L2_TUNER_CAP_LOW;
1198
1199 /* Stereo indicator == Stereo (instead of Mono) */
1200 if ((radio->registers[STATUSRSSI] & STATUSRSSI_ST) == 1)
1201 tuner->audmode = V4L2_TUNER_MODE_STEREO;
1202 else
1203 tuner->audmode = V4L2_TUNER_MODE_MONO;
1204
1205 /* min is worst, max is best; signal:0..0xffff; rssi: 0..0xff */
1206 tuner->signal = (radio->registers[STATUSRSSI] & STATUSRSSI_RSSI)
1207 * 0x0101;
1208
1209 /* automatic frequency control: -1: freq to low, 1 freq to high */
1210 tuner->afc = 0;
1211
1212 return 0;
1213}
1214
1215
1216/*
1217 * si470x_vidioc_s_tuner - set tuner attributes
1218 */
1219static int si470x_vidioc_s_tuner(struct file *file, void *priv,
1220 struct v4l2_tuner *tuner)
1221{
1222 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1223
1224 if (tuner->index > 0)
1225 return -EINVAL;
1226
1227 if (tuner->audmode == V4L2_TUNER_MODE_MONO)
1228 radio->registers[POWERCFG] |= POWERCFG_MONO; /* force mono */
1229 else
1230 radio->registers[POWERCFG] &= ~POWERCFG_MONO; /* try stereo */
1231
1232 return si470x_set_register(radio, POWERCFG);
1233}
1234
1235
1236/*
1237 * si470x_vidioc_g_frequency - get tuner or modulator radio frequency
1238 */
1239static int si470x_vidioc_g_frequency(struct file *file, void *priv,
1240 struct v4l2_frequency *freq)
1241{
1242 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1243
1244 freq->type = V4L2_TUNER_RADIO;
1245 freq->frequency = si470x_get_freq(radio);
1246
1247 return 0;
1248}
1249
1250
1251/*
1252 * si470x_vidioc_s_frequency - set tuner or modulator radio frequency
1253 */
1254static int si470x_vidioc_s_frequency(struct file *file, void *priv,
1255 struct v4l2_frequency *freq)
1256{
1257 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1258
1259 if (freq->type != V4L2_TUNER_RADIO)
1260 return -EINVAL;
1261
1262 return si470x_set_freq(radio, freq->frequency);
1263}
1264
1265
1266/*
1267 * si470x_viddev_tamples - video device interface
1268 */
1269static struct video_device si470x_viddev_template = {
1270 .fops = &si470x_fops,
1271 .name = DRIVER_NAME,
1272 .type = VID_TYPE_TUNER,
1273 .release = video_device_release,
1274 .vidioc_querycap = si470x_vidioc_querycap,
1275 .vidioc_g_input = si470x_vidioc_g_input,
1276 .vidioc_s_input = si470x_vidioc_s_input,
1277 .vidioc_queryctrl = si470x_vidioc_queryctrl,
1278 .vidioc_g_ctrl = si470x_vidioc_g_ctrl,
1279 .vidioc_s_ctrl = si470x_vidioc_s_ctrl,
1280 .vidioc_g_audio = si470x_vidioc_g_audio,
1281 .vidioc_s_audio = si470x_vidioc_s_audio,
1282 .vidioc_g_tuner = si470x_vidioc_g_tuner,
1283 .vidioc_s_tuner = si470x_vidioc_s_tuner,
1284 .vidioc_g_frequency = si470x_vidioc_g_frequency,
1285 .vidioc_s_frequency = si470x_vidioc_s_frequency,
1286 .owner = THIS_MODULE,
1287};
1288
1289
1290
1291/**************************************************************************
1292 * USB Interface
1293 **************************************************************************/
1294
1295/*
1296 * si470x_usb_driver_probe - probe for the device
1297 */
1298static int si470x_usb_driver_probe(struct usb_interface *intf,
1299 const struct usb_device_id *id)
1300{
1301 struct si470x_device *radio;
1302
1303 /* memory and interface allocations */
1304 radio = kmalloc(sizeof(struct si470x_device), GFP_KERNEL);
1305 if (!radio)
1306 return -ENOMEM;
1307 radio->videodev = video_device_alloc();
1308 if (!radio->videodev) {
1309 kfree(radio);
1310 return -ENOMEM;
1311 }
1312 memcpy(radio->videodev, &si470x_viddev_template,
1313 sizeof(si470x_viddev_template));
1314 radio->users = 0;
1315 radio->usbdev = interface_to_usbdev(intf);
1316 video_set_drvdata(radio->videodev, radio);
1317 if (video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr)) {
1318 printk(KERN_WARNING DRIVER_NAME
1319 ": Could not register video device\n");
1320 video_device_release(radio->videodev);
1321 kfree(radio);
1322 return -EIO;
1323 }
1324 usb_set_intfdata(intf, radio);
1325
1326 /* show some infos about the specific device */
1327 if (si470x_get_all_registers(radio) < 0) {
1328 video_device_release(radio->videodev);
1329 kfree(radio);
1330 return -EIO;
1331 }
1332 printk(KERN_INFO DRIVER_NAME ": DeviceID=0x%4.4x ChipID=0x%4.4x\n",
1333 radio->registers[DEVICEID], radio->registers[CHIPID]);
1334
1335 /* check if firmware is current */
1336 if ((radio->registers[CHIPID] & CHIPID_FIRMWARE)
1337 < RADIO_SW_VERSION_CURRENT)
1338 printk(KERN_WARNING DRIVER_NAME
1339 ": This driver is known to work with chip version %d, "
1340 "but the device has firmware %d.\n"
1341 DRIVER_NAME
1342 "If you have some trouble using this driver, please "
1343 "report to V4L ML at video4linux-list@redhat.com\n",
1344 radio->registers[CHIPID] & CHIPID_FIRMWARE,
1345 RADIO_SW_VERSION_CURRENT);
1346
1347 /* set initial frequency */
1348 si470x_set_freq(radio, 87.5 * FREQ_MUL); /* available in all regions */
1349
1350 /* rds initialization */
1351 radio->buf_size = rds_buf * 3;
1352 radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL);
1353 if (!radio->buffer) {
1354 video_device_release(radio->videodev);
1355 kfree(radio);
1356 return -ENOMEM;
1357 }
1358 radio->wr_index = 0;
1359 radio->rd_index = 0;
1360 init_waitqueue_head(&radio->read_queue);
1361
1362 /* prepare polling via eventd */
1363 INIT_WORK(&radio->work, si470x_work);
1364 init_timer(&radio->timer);
1365 radio->timer.function = si470x_timer;
1366 radio->timer.data = (unsigned long) radio;
1367
1368 return 0;
1369}
1370
1371
1372/*
1373 * si470x_usb_driver_disconnect - disconnect the device
1374 */
1375static void si470x_usb_driver_disconnect(struct usb_interface *intf)
1376{
1377 struct si470x_device *radio = usb_get_intfdata(intf);
1378
1379 del_timer_sync(&radio->timer);
1380 flush_scheduled_work();
1381
1382 usb_set_intfdata(intf, NULL);
1383 if (radio) {
1384 video_unregister_device(radio->videodev);
1385 kfree(radio->buffer);
1386 kfree(radio);
1387 }
1388}
1389
1390
1391/*
1392 * si470x_usb_driver - usb driver interface
1393 */
1394static struct usb_driver si470x_usb_driver = {
1395 .name = DRIVER_NAME,
1396 .probe = si470x_usb_driver_probe,
1397 .disconnect = si470x_usb_driver_disconnect,
1398 .id_table = si470x_usb_driver_id_table,
1399};
1400
1401
1402
1403/**************************************************************************
1404 * Module Interface
1405 **************************************************************************/
1406
1407/*
1408 * si470x_module_init - module init
1409 */
1410static int __init si470x_module_init(void)
1411{
1412 printk(KERN_INFO DRIVER_DESC "\n");
1413 return usb_register(&si470x_usb_driver);
1414}
1415
1416
1417/*
1418 * si470x_module_exit - module exit
1419 */
1420static void __exit si470x_module_exit(void)
1421{
1422 usb_deregister(&si470x_usb_driver);
1423}
1424
1425
1426module_init(si470x_module_init);
1427module_exit(si470x_module_exit);
1428
1429MODULE_LICENSE("GPL");
1430MODULE_AUTHOR(DRIVER_AUTHOR);
1431MODULE_DESCRIPTION(DRIVER_DESC);
1432MODULE_VERSION("1.0.4");
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index c9f14bfc8544..a2e8987a6195 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -45,7 +45,7 @@ comment "Audio decoders"
45 45
46config VIDEO_TVAUDIO 46config VIDEO_TVAUDIO
47 tristate "Simple audio decoder chips" 47 tristate "Simple audio decoder chips"
48 depends on VIDEO_V4L1 && I2C 48 depends on VIDEO_V4L2 && I2C
49 ---help--- 49 ---help---
50 Support for several audio decoder chips found on some bt8xx boards: 50 Support for several audio decoder chips found on some bt8xx boards:
51 Philips: tda9840, tda9873h, tda9874h/a, tda9850, tda985x, tea6300, 51 Philips: tda9840, tda9873h, tda9874h/a, tda9850, tda985x, tea6300,
@@ -57,7 +57,7 @@ config VIDEO_TVAUDIO
57 57
58config VIDEO_TDA7432 58config VIDEO_TDA7432
59 tristate "Philips TDA7432 audio processor" 59 tristate "Philips TDA7432 audio processor"
60 depends on VIDEO_V4L1 && I2C 60 depends on VIDEO_V4L2 && I2C
61 ---help--- 61 ---help---
62 Support for tda7432 audio decoder chip found on some bt8xx boards. 62 Support for tda7432 audio decoder chip found on some bt8xx boards.
63 63
@@ -75,7 +75,7 @@ config VIDEO_TDA9840
75 75
76config VIDEO_TDA9875 76config VIDEO_TDA9875
77 tristate "Philips TDA9875 audio processor" 77 tristate "Philips TDA9875 audio processor"
78 depends on VIDEO_V4L1 && I2C 78 depends on VIDEO_V4L2 && I2C
79 ---help--- 79 ---help---
80 Support for tda9875 audio decoder chip found on some bt8xx boards. 80 Support for tda9875 audio decoder chip found on some bt8xx boards.
81 81
@@ -109,9 +109,19 @@ config VIDEO_MSP3400
109 To compile this driver as a module, choose M here: the 109 To compile this driver as a module, choose M here: the
110 module will be called msp3400. 110 module will be called msp3400.
111 111
112config VIDEO_CS5345
113 tristate "Cirrus Logic CS5345 audio ADC"
114 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
115 ---help---
116 Support for the Cirrus Logic CS5345 24-bit, 192 kHz
117 stereo A/D converter.
118
119 To compile this driver as a module, choose M here: the
120 module will be called cs5345.
121
112config VIDEO_CS53L32A 122config VIDEO_CS53L32A
113 tristate "Cirrus Logic CS53L32A audio ADC" 123 tristate "Cirrus Logic CS53L32A audio ADC"
114 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL 124 depends on VIDEO_V4L2 && I2C
115 ---help--- 125 ---help---
116 Support for the Cirrus Logic CS53L32A low voltage 126 Support for the Cirrus Logic CS53L32A low voltage
117 stereo A/D converter. 127 stereo A/D converter.
@@ -119,6 +129,15 @@ config VIDEO_CS53L32A
119 To compile this driver as a module, choose M here: the 129 To compile this driver as a module, choose M here: the
120 module will be called cs53l32a. 130 module will be called cs53l32a.
121 131
132config VIDEO_M52790
133 tristate "Mitsubishi M52790 A/V switch"
134 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
135 ---help---
136 Support for the Mitsubishi M52790 A/V switch.
137
138 To compile this driver as a module, choose M here: the
139 module will be called m52790.
140
122config VIDEO_TLV320AIC23B 141config VIDEO_TLV320AIC23B
123 tristate "Texas Instruments TLV320AIC23B audio codec" 142 tristate "Texas Instruments TLV320AIC23B audio codec"
124 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL 143 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
@@ -130,7 +149,7 @@ config VIDEO_TLV320AIC23B
130 149
131config VIDEO_WM8775 150config VIDEO_WM8775
132 tristate "Wolfson Microelectronics WM8775 audio ADC with input mixer" 151 tristate "Wolfson Microelectronics WM8775 audio ADC with input mixer"
133 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL 152 depends on VIDEO_V4L2 && I2C
134 ---help--- 153 ---help---
135 Support for the Wolfson Microelectronics WM8775 high 154 Support for the Wolfson Microelectronics WM8775 high
136 performance stereo A/D Converter with a 4 channel input mixer. 155 performance stereo A/D Converter with a 4 channel input mixer.
@@ -140,7 +159,7 @@ config VIDEO_WM8775
140 159
141config VIDEO_WM8739 160config VIDEO_WM8739
142 tristate "Wolfson Microelectronics WM8739 stereo audio ADC" 161 tristate "Wolfson Microelectronics WM8739 stereo audio ADC"
143 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL 162 depends on VIDEO_V4L2 && I2C
144 ---help--- 163 ---help---
145 Support for the Wolfson Microelectronics WM8739 164 Support for the Wolfson Microelectronics WM8739
146 stereo A/D Converter. 165 stereo A/D Converter.
@@ -244,7 +263,7 @@ config VIDEO_SAA7114
244 263
245config VIDEO_SAA711X 264config VIDEO_SAA711X
246 tristate "Philips SAA7113/4/5 video decoders" 265 tristate "Philips SAA7113/4/5 video decoders"
247 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL 266 depends on VIDEO_V4L2 && I2C
248 ---help--- 267 ---help---
249 Support for the Philips SAA7113/4/5 video decoders. 268 Support for the Philips SAA7113/4/5 video decoders.
250 269
@@ -300,7 +319,7 @@ comment "Video encoders"
300 319
301config VIDEO_SAA7127 320config VIDEO_SAA7127
302 tristate "Philips SAA7127/9 digital video encoders" 321 tristate "Philips SAA7127/9 digital video encoders"
303 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL 322 depends on VIDEO_V4L2 && I2C
304 ---help--- 323 ---help---
305 Support for the Philips SAA7127/9 digital video encoders. 324 Support for the Philips SAA7127/9 digital video encoders.
306 325
@@ -338,7 +357,7 @@ comment "Video improvement chips"
338 357
339config VIDEO_UPD64031A 358config VIDEO_UPD64031A
340 tristate "NEC Electronics uPD64031A Ghost Reduction" 359 tristate "NEC Electronics uPD64031A Ghost Reduction"
341 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL 360 depends on VIDEO_V4L2 && I2C
342 ---help--- 361 ---help---
343 Support for the NEC Electronics uPD64031A Ghost Reduction 362 Support for the NEC Electronics uPD64031A Ghost Reduction
344 video chip. It is most often found in NTSC TV cards made for 363 video chip. It is most often found in NTSC TV cards made for
@@ -350,7 +369,7 @@ config VIDEO_UPD64031A
350 369
351config VIDEO_UPD64083 370config VIDEO_UPD64083
352 tristate "NEC Electronics uPD64083 3-Dimensional Y/C separation" 371 tristate "NEC Electronics uPD64083 3-Dimensional Y/C separation"
353 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL 372 depends on VIDEO_V4L2 && I2C
354 ---help--- 373 ---help---
355 Support for the NEC Electronics uPD64083 3-Dimensional Y/C 374 Support for the NEC Electronics uPD64083 3-Dimensional Y/C
356 separation video chip. It is used to improve the quality of 375 separation video chip. It is used to improve the quality of
@@ -802,6 +821,19 @@ config USB_ZR364XX
802 To compile this driver as a module, choose M here: the 821 To compile this driver as a module, choose M here: the
803 module will be called zr364xx. 822 module will be called zr364xx.
804 823
824config USB_STKWEBCAM
825 tristate "USB Syntek DC1125 Camera support"
826 depends on VIDEO_V4L2 && EXPERIMENTAL
827 ---help---
828 Say Y here if you want to use this type of camera.
829 Supported devices are typically found in some Asus laptops,
830 with USB id 174f:a311 and 05e1:0501. Other Syntek cameras
831 may be supported by the stk11xx driver, from which this is
832 derived, see http://stk11xx.sourceforge.net
833
834 To compile this driver as a module, choose M here: the
835 module will be called stkwebcam.
836
805endif # V4L_USB_DRIVERS 837endif # V4L_USB_DRIVERS
806 838
807endif # VIDEO_CAPTURE_DRIVERS 839endif # VIDEO_CAPTURE_DRIVERS
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index b5a064163e03..28ddd146c1c5 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -4,10 +4,12 @@
4 4
5zr36067-objs := zoran_procfs.o zoran_device.o \ 5zr36067-objs := zoran_procfs.o zoran_device.o \
6 zoran_driver.o zoran_card.o 6 zoran_driver.o zoran_card.o
7tuner-objs := tuner-core.o tuner-types.o tda9887.o 7tuner-objs := tuner-core.o tuner-types.o
8 8
9msp3400-objs := msp3400-driver.o msp3400-kthreads.o 9msp3400-objs := msp3400-driver.o msp3400-kthreads.o
10 10
11stkwebcam-objs := stk-webcam.o stk-sensor.o
12
11obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o compat_ioctl32.o \ 13obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o compat_ioctl32.o \
12 v4l2-int-device.o 14 v4l2-int-device.o
13 15
@@ -66,7 +68,9 @@ obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
66obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o 68obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o
67obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/ 69obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
68obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o 70obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o
71obj-$(CONFIG_VIDEO_CS5345) += cs5345.o
69obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o 72obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
73obj-$(CONFIG_VIDEO_M52790) += m52790.o
70obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o 74obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o
71obj-$(CONFIG_VIDEO_WM8775) += wm8775.o 75obj-$(CONFIG_VIDEO_WM8775) += wm8775.o
72obj-$(CONFIG_VIDEO_WM8739) += wm8739.o 76obj-$(CONFIG_VIDEO_WM8739) += wm8739.o
@@ -81,11 +85,13 @@ obj-$(CONFIG_TUNER_3036) += tuner-3036.o
81 85
82obj-$(CONFIG_VIDEO_TUNER) += tuner.o 86obj-$(CONFIG_VIDEO_TUNER) += tuner.o
83 87
88obj-$(CONFIG_TUNER_XC2028) += tuner-xc2028.o
84obj-$(CONFIG_TUNER_SIMPLE) += tuner-simple.o 89obj-$(CONFIG_TUNER_SIMPLE) += tuner-simple.o
85obj-$(CONFIG_TUNER_MT20XX) += mt20xx.o 90obj-$(CONFIG_TUNER_MT20XX) += mt20xx.o
86obj-$(CONFIG_TUNER_TDA8290) += tda8290.o 91obj-$(CONFIG_TUNER_TDA8290) += tda8290.o
87obj-$(CONFIG_TUNER_TEA5767) += tea5767.o 92obj-$(CONFIG_TUNER_TEA5767) += tea5767.o
88obj-$(CONFIG_TUNER_TEA5761) += tea5761.o 93obj-$(CONFIG_TUNER_TEA5761) += tea5761.o
94obj-$(CONFIG_TUNER_TDA9887) += tda9887.o
89 95
90obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o 96obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o
91obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o 97obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o
@@ -112,6 +118,7 @@ obj-$(CONFIG_USB_SE401) += se401.o
112obj-$(CONFIG_USB_STV680) += stv680.o 118obj-$(CONFIG_USB_STV680) += stv680.o
113obj-$(CONFIG_USB_W9968CF) += w9968cf.o 119obj-$(CONFIG_USB_W9968CF) += w9968cf.o
114obj-$(CONFIG_USB_ZR364XX) += zr364xx.o 120obj-$(CONFIG_USB_ZR364XX) += zr364xx.o
121obj-$(CONFIG_USB_STKWEBCAM) += stkwebcam.o
115 122
116obj-$(CONFIG_USB_SN9C102) += sn9c102/ 123obj-$(CONFIG_USB_SN9C102) += sn9c102/
117obj-$(CONFIG_USB_ET61X251) += et61x251/ 124obj-$(CONFIG_USB_ET61X251) += et61x251/
@@ -129,3 +136,4 @@ obj-$(CONFIG_VIDEO_VIVI) += vivi.o
129obj-$(CONFIG_VIDEO_CX23885) += cx23885/ 136obj-$(CONFIG_VIDEO_CX23885) += cx23885/
130 137
131EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 138EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
139EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index 2ca162b390a2..cfc822bb502a 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_BT848 1config VIDEO_BT848
2 tristate "BT848 Video For Linux" 2 tristate "BT848 Video For Linux"
3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L1 3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2 && INPUT
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select FW_LOADER 5 select FW_LOADER
6 select VIDEO_BTCX 6 select VIDEO_BTCX
diff --git a/drivers/media/video/bt8xx/Makefile b/drivers/media/video/bt8xx/Makefile
index a096a03418aa..924d216d9570 100644
--- a/drivers/media/video/bt8xx/Makefile
+++ b/drivers/media/video/bt8xx/Makefile
@@ -4,7 +4,7 @@
4 4
5bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \ 5bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
6 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o \ 6 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o \
7 bttv-input.o 7 bttv-input.o bttv-audio-hook.o
8 8
9obj-$(CONFIG_VIDEO_BT848) += bttv.o 9obj-$(CONFIG_VIDEO_BT848) += bttv.o
10 10
diff --git a/drivers/media/video/bt8xx/bttv-audio-hook.c b/drivers/media/video/bt8xx/bttv-audio-hook.c
new file mode 100644
index 000000000000..2364d16586b3
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-audio-hook.c
@@ -0,0 +1,382 @@
1/*
2 * Handlers for board audio hooks, splitted from bttv-cards
3 *
4 * Copyright (c) 2006 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * This code is placed under the terms of the GNU General Public License
6 */
7
8#include "bttv-audio-hook.h"
9
10#include <linux/delay.h>
11
12/* ----------------------------------------------------------------------- */
13/* winview */
14
15void winview_volume(struct bttv *btv, __u16 volume)
16{
17 /* PT2254A programming Jon Tombs, jon@gte.esi.us.es */
18 int bits_out, loops, vol, data;
19
20 /* 32 levels logarithmic */
21 vol = 32 - ((volume>>11));
22 /* units */
23 bits_out = (PT2254_DBS_IN_2>>(vol%5));
24 /* tens */
25 bits_out |= (PT2254_DBS_IN_10>>(vol/5));
26 bits_out |= PT2254_L_CHANNEL | PT2254_R_CHANNEL;
27 data = gpio_read();
28 data &= ~(WINVIEW_PT2254_CLK| WINVIEW_PT2254_DATA|
29 WINVIEW_PT2254_STROBE);
30 for (loops = 17; loops >= 0 ; loops--) {
31 if (bits_out & (1<<loops))
32 data |= WINVIEW_PT2254_DATA;
33 else
34 data &= ~WINVIEW_PT2254_DATA;
35 gpio_write(data);
36 udelay(5);
37 data |= WINVIEW_PT2254_CLK;
38 gpio_write(data);
39 udelay(5);
40 data &= ~WINVIEW_PT2254_CLK;
41 gpio_write(data);
42 }
43 data |= WINVIEW_PT2254_STROBE;
44 data &= ~WINVIEW_PT2254_DATA;
45 gpio_write(data);
46 udelay(10);
47 data &= ~WINVIEW_PT2254_STROBE;
48 gpio_write(data);
49}
50
51/* ----------------------------------------------------------------------- */
52/* mono/stereo control for various cards (which don't use i2c chips but */
53/* connect something to the GPIO pins */
54
55void gvbctv3pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
56{
57 unsigned int con = 0;
58
59 if (set) {
60 gpio_inout(0x300, 0x300);
61 if (t->audmode & V4L2_TUNER_MODE_LANG1)
62 con = 0x000;
63 if (t->audmode & V4L2_TUNER_MODE_LANG2)
64 con = 0x300;
65 if (t->audmode & V4L2_TUNER_MODE_STEREO)
66 con = 0x200;
67/* if (t->audmode & V4L2_TUNER_MODE_MONO)
68 * con = 0x100; */
69 gpio_bits(0x300, con);
70 } else {
71 t->audmode = V4L2_TUNER_MODE_STEREO |
72 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
73 }
74}
75
76void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
77{
78 unsigned int val, con;
79
80 if (btv->radio_user)
81 return;
82
83 val = gpio_read();
84 if (set) {
85 con = 0x000;
86 if (t->audmode & V4L2_TUNER_MODE_LANG2) {
87 if (t->audmode & V4L2_TUNER_MODE_LANG1) {
88 /* LANG1 + LANG2 */
89 con = 0x100;
90 }
91 else {
92 /* LANG2 */
93 con = 0x300;
94 }
95 }
96 if (con != (val & 0x300)) {
97 gpio_bits(0x300, con);
98 if (bttv_gpio)
99 bttv_gpio_tracking(btv,"gvbctv5pci");
100 }
101 } else {
102 switch (val & 0x70) {
103 case 0x10:
104 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
105 break;
106 case 0x30:
107 t->rxsubchans = V4L2_TUNER_SUB_LANG2;
108 break;
109 case 0x50:
110 t->rxsubchans = V4L2_TUNER_SUB_LANG1;
111 break;
112 case 0x60:
113 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
114 break;
115 case 0x70:
116 t->rxsubchans = V4L2_TUNER_SUB_MONO;
117 break;
118 default:
119 t->rxsubchans = V4L2_TUNER_SUB_MONO |
120 V4L2_TUNER_SUB_STEREO |
121 V4L2_TUNER_SUB_LANG1 |
122 V4L2_TUNER_SUB_LANG2;
123 }
124 t->audmode = V4L2_TUNER_MODE_STEREO |
125 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
126 }
127}
128
129/*
130 * Mario Medina Nussbaum <medisoft@alohabbs.org.mx>
131 * I discover that on BT848_GPIO_DATA address a byte 0xcce enable stereo,
132 * 0xdde enables mono and 0xccd enables sap
133 *
134 * Petr Vandrovec <VANDROVE@vc.cvut.cz>
135 * P.S.: At least mask in line above is wrong - GPIO pins 3,2 select
136 * input/output sound connection, so both must be set for output mode.
137 *
138 * Looks like it's needed only for the "tvphone", the "tvphone 98"
139 * handles this with a tda9840
140 *
141 */
142
143void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
144{
145 int val = 0;
146
147 if (set) {
148 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
149 val = 0x02;
150 if (t->audmode & V4L2_TUNER_MODE_STEREO)
151 val = 0x01;
152 if (val) {
153 gpio_bits(0x03,val);
154 if (bttv_gpio)
155 bttv_gpio_tracking(btv,"avermedia");
156 }
157 } else {
158 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
159 V4L2_TUNER_MODE_LANG1;
160 return;
161 }
162}
163
164
165void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
166{
167 int val = 0;
168
169 if (set) {
170 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
171 val = 0x01;
172 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* STEREO */
173 val = 0x02;
174 btaor(val, ~0x03, BT848_GPIO_DATA);
175 if (bttv_gpio)
176 bttv_gpio_tracking(btv,"avermedia");
177 } else {
178 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
179 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
180 return;
181 }
182}
183
184/* Lifetec 9415 handling */
185
186void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
187{
188 int val = 0;
189
190 if (gpio_read() & 0x4000) {
191 t->audmode = V4L2_TUNER_MODE_MONO;
192 return;
193 }
194
195 if (set) {
196 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* A2 SAP */
197 val = 0x0080;
198 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* A2 stereo */
199 val = 0x0880;
200 if ((t->audmode & V4L2_TUNER_MODE_LANG1) ||
201 (t->audmode & V4L2_TUNER_MODE_MONO))
202 val = 0;
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;
211 }
212}
213
214/* TDA9821 on TerraTV+ Bt848, Bt878 */
215void terratv_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
216{
217 unsigned int con = 0;
218
219 if (set) {
220 gpio_inout(0x180000,0x180000);
221 if (t->audmode & V4L2_TUNER_MODE_LANG2)
222 con = 0x080000;
223 if (t->audmode & V4L2_TUNER_MODE_STEREO)
224 con = 0x180000;
225 gpio_bits(0x180000, con);
226 if (bttv_gpio)
227 bttv_gpio_tracking(btv,"terratv");
228 } else {
229 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
230 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
231 }
232}
233
234
235void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
236{
237 unsigned long val = 0;
238
239 if (set) {
240 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
241 if (t->audmode & V4L2_TUNER_MODE_MONO) /* Mono */
242 val = 0x420000;
243 if (t->audmode & V4L2_TUNER_MODE_LANG1) /* Mono */
244 val = 0x420000;
245 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
246 val = 0x410000;
247 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* Stereo */
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 }
258}
259
260/*
261 * Dariusz Kowalewski <darekk@automex.pl>
262 * sound control for Prolink PV-BT878P+9B (PixelView PlayTV Pro FM+NICAM
263 * revision 9B has on-board TDA9874A sound decoder).
264 *
265 * Note: There are card variants without tda9874a. Forcing the "stereo sound route"
266 * will mute this cards.
267 */
268void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
269{
270 unsigned int val = 0;
271
272 if (btv->radio_user)
273 return;
274
275 if (set) {
276 if (t->audmode & V4L2_TUNER_MODE_MONO) {
277 val = 0x01;
278 }
279 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
280 || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
281 val = 0x02;
282 }
283 if (val) {
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 }
292}
293
294/*
295 * Dariusz Kowalewski <darekk@automex.pl>
296 * sound control for FlyVideo 2000S (with tda9874 decoder)
297 * based on pvbt878p9b_audio() - this is not tested, please fix!!!
298 */
299void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
300{
301 unsigned int val = 0xffff;
302
303 if (btv->radio_user)
304 return;
305
306 if (set) {
307 if (t->audmode & V4L2_TUNER_MODE_MONO) {
308 val = 0x0000;
309 }
310 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
311 || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
312 val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
313 }
314 if (val != 0xffff) {
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 }
323}
324
325/*
326 * sound control for Canopus WinDVR PCI
327 * Masaki Suzuki <masaki@btree.org>
328 */
329void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
330{
331 unsigned long val = 0;
332
333 if (set) {
334 if (t->audmode & V4L2_TUNER_MODE_MONO)
335 val = 0x040000;
336 if (t->audmode & V4L2_TUNER_MODE_LANG1)
337 val = 0;
338 if (t->audmode & V4L2_TUNER_MODE_LANG2)
339 val = 0x100000;
340 if (t->audmode & V4L2_TUNER_MODE_STEREO)
341 val = 0;
342 if (val) {
343 gpio_bits(0x140000, val);
344 if (bttv_gpio)
345 bttv_gpio_tracking(btv,"windvr");
346 }
347 } else {
348 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
349 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
350 }
351}
352
353/*
354 * sound control for AD-TVK503
355 * Hiroshi Takekawa <sian@big.or.jp>
356 */
357void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
358{
359 unsigned int con = 0xffffff;
360
361 /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
362
363 if (set) {
364 /* btor(***, BT848_GPIO_OUT_EN); */
365 if (t->audmode & V4L2_TUNER_MODE_LANG1)
366 con = 0x00000000;
367 if (t->audmode & V4L2_TUNER_MODE_LANG2)
368 con = 0x00180000;
369 if (t->audmode & V4L2_TUNER_MODE_STEREO)
370 con = 0x00000000;
371 if (t->audmode & V4L2_TUNER_MODE_MONO)
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 }
382}
diff --git a/drivers/media/video/bt8xx/bttv-audio-hook.h b/drivers/media/video/bt8xx/bttv-audio-hook.h
new file mode 100644
index 000000000000..159d07adeff8
--- /dev/null
+++ b/drivers/media/video/bt8xx/bttv-audio-hook.h
@@ -0,0 +1,23 @@
1/*
2 * Handlers for board audio hooks, splitted from bttv-cards
3 *
4 * Copyright (c) 2006 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * This code is placed under the terms of the GNU General Public License
6 */
7
8#include "bttvp.h"
9
10void winview_volume (struct bttv *btv, __u16 volume);
11
12void lt9415_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
13void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
14void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
15void terratv_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
16void gvbctv3pci_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
17void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
18void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
19void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
20void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
21void windvr_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
22void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *tuner, int set);
23
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index 585d1ef95afd..63a47cd4c161 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -39,6 +39,7 @@
39#include "bttvp.h" 39#include "bttvp.h"
40#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
41#include <media/tvaudio.h> 41#include <media/tvaudio.h>
42#include "bttv-audio-hook.h"
42 43
43/* fwd decl */ 44/* fwd decl */
44static void boot_msp34xx(struct bttv *btv, int pin); 45static void boot_msp34xx(struct bttv *btv, int pin);
@@ -50,20 +51,6 @@ static void modtec_eeprom(struct bttv *btv);
50static void init_PXC200(struct bttv *btv); 51static void init_PXC200(struct bttv *btv);
51static void init_RTV24(struct bttv *btv); 52static void init_RTV24(struct bttv *btv);
52 53
53static void winview_audio(struct bttv *btv, struct video_audio *v, int set);
54static void lt9415_audio(struct bttv *btv, struct video_audio *v, int set);
55static void avermedia_tvphone_audio(struct bttv *btv, struct video_audio *v,
56 int set);
57static void avermedia_tv_stereo_audio(struct bttv *btv, struct video_audio *v,
58 int set);
59static void terratv_audio(struct bttv *btv, struct video_audio *v, int set);
60static void gvbctv3pci_audio(struct bttv *btv, struct video_audio *v, int set);
61static void gvbctv5pci_audio(struct bttv *btv, struct video_audio *v, int set);
62static void winfast2000_audio(struct bttv *btv, struct video_audio *v, int set);
63static void pvbt878p9b_audio(struct bttv *btv, struct video_audio *v, int set);
64static void fv2000s_audio(struct bttv *btv, struct video_audio *v, int set);
65static void windvr_audio(struct bttv *btv, struct video_audio *v, int set);
66static void adtvk503_audio(struct bttv *btv, struct video_audio *v, int set);
67static void rv605_muxsel(struct bttv *btv, unsigned int input); 54static void rv605_muxsel(struct bttv *btv, unsigned int input);
68static void eagle_muxsel(struct bttv *btv, unsigned int input); 55static void eagle_muxsel(struct bttv *btv, unsigned int input);
69static void xguard_muxsel(struct bttv *btv, unsigned int input); 56static void xguard_muxsel(struct bttv *btv, unsigned int input);
@@ -427,7 +414,7 @@ struct tvcard bttv_tvcards[] = {
427 .tuner_type = UNSET, 414 .tuner_type = UNSET,
428 .tuner_addr = ADDR_UNSET, 415 .tuner_addr = ADDR_UNSET,
429 .radio_addr = ADDR_UNSET, 416 .radio_addr = ADDR_UNSET,
430 .audio_hook = avermedia_tvphone_audio, 417 .audio_mode_gpio= avermedia_tvphone_audio,
431 .has_remote = 1, 418 .has_remote = 1,
432 }, 419 },
433 [BTTV_BOARD_MATRIX_VISION] = { 420 [BTTV_BOARD_MATRIX_VISION] = {
@@ -539,7 +526,7 @@ struct tvcard bttv_tvcards[] = {
539 .tuner_type = TUNER_PHILIPS_PAL, 526 .tuner_type = TUNER_PHILIPS_PAL,
540 .tuner_addr = ADDR_UNSET, 527 .tuner_addr = ADDR_UNSET,
541 .radio_addr = ADDR_UNSET, 528 .radio_addr = ADDR_UNSET,
542 .audio_hook = avermedia_tv_stereo_audio, 529 .audio_mode_gpio= avermedia_tv_stereo_audio,
543 .no_gpioirq = 1, 530 .no_gpioirq = 1,
544 }, 531 },
545 [BTTV_BOARD_VHX] = { 532 [BTTV_BOARD_VHX] = {
@@ -604,7 +591,7 @@ struct tvcard bttv_tvcards[] = {
604 .tuner_type = UNSET, 591 .tuner_type = UNSET,
605 .tuner_addr = ADDR_UNSET, 592 .tuner_addr = ADDR_UNSET,
606 .radio_addr = ADDR_UNSET, 593 .radio_addr = ADDR_UNSET,
607 .audio_hook = winview_audio, 594 .volume_gpio = winview_volume,
608 .has_radio = 1, 595 .has_radio = 1,
609 }, 596 },
610 [BTTV_BOARD_AVEC_INTERCAP] = { 597 [BTTV_BOARD_AVEC_INTERCAP] = {
@@ -728,7 +715,7 @@ struct tvcard bttv_tvcards[] = {
728 .tuner_type = TUNER_PHILIPS_PAL, 715 .tuner_type = TUNER_PHILIPS_PAL,
729 .tuner_addr = ADDR_UNSET, 716 .tuner_addr = ADDR_UNSET,
730 .radio_addr = ADDR_UNSET, 717 .radio_addr = ADDR_UNSET,
731 .audio_hook = terratv_audio, 718 .audio_mode_gpio= terratv_audio,
732 }, 719 },
733 [BTTV_BOARD_HAUPPAUG_WCAM] = { 720 [BTTV_BOARD_HAUPPAUG_WCAM] = {
734 .name = "Hauppauge WinCam newer (bt878)", 721 .name = "Hauppauge WinCam newer (bt878)",
@@ -776,7 +763,7 @@ struct tvcard bttv_tvcards[] = {
776 .tuner_type = TUNER_PHILIPS_PAL, 763 .tuner_type = TUNER_PHILIPS_PAL,
777 .tuner_addr = ADDR_UNSET, 764 .tuner_addr = ADDR_UNSET,
778 .radio_addr = ADDR_UNSET, 765 .radio_addr = ADDR_UNSET,
779 .audio_hook = terratv_audio, 766 .audio_mode_gpio= terratv_audio,
780 /* GPIO wiring: 767 /* GPIO wiring:
781 External 20 pin connector (for Active Radio Upgrade board) 768 External 20 pin connector (for Active Radio Upgrade board)
782 gpio00: i2c-sda 769 gpio00: i2c-sda
@@ -915,7 +902,7 @@ struct tvcard bttv_tvcards[] = {
915 .tuner_type = TUNER_PHILIPS_PAL, /* default for now, gpio reads BFFF06 for Pal bg+dk */ 902 .tuner_type = TUNER_PHILIPS_PAL, /* default for now, gpio reads BFFF06 for Pal bg+dk */
916 .tuner_addr = ADDR_UNSET, 903 .tuner_addr = ADDR_UNSET,
917 .radio_addr = ADDR_UNSET, 904 .radio_addr = ADDR_UNSET,
918 .audio_hook = winfast2000_audio, 905 .audio_mode_gpio= winfast2000_audio,
919 .has_remote = 1, 906 .has_remote = 1,
920 }, 907 },
921 [BTTV_BOARD_CHRONOS_VS2] = { 908 [BTTV_BOARD_CHRONOS_VS2] = {
@@ -1035,7 +1022,7 @@ struct tvcard bttv_tvcards[] = {
1035 .tuner_addr = ADDR_UNSET, 1022 .tuner_addr = ADDR_UNSET,
1036 .radio_addr = ADDR_UNSET, 1023 .radio_addr = ADDR_UNSET,
1037 .has_radio = 1, 1024 .has_radio = 1,
1038 .audio_hook = avermedia_tvphone_audio, 1025 .audio_mode_gpio= avermedia_tvphone_audio,
1039 }, 1026 },
1040 [BTTV_BOARD_PV951] = { 1027 [BTTV_BOARD_PV951] = {
1041 .name = "ProVideo PV951", /* pic16c54 */ 1028 .name = "ProVideo PV951", /* pic16c54 */
@@ -1167,7 +1154,7 @@ struct tvcard bttv_tvcards[] = {
1167 .tuner_type = TUNER_ALPS_TSHC6_NTSC, 1154 .tuner_type = TUNER_ALPS_TSHC6_NTSC,
1168 .tuner_addr = ADDR_UNSET, 1155 .tuner_addr = ADDR_UNSET,
1169 .radio_addr = ADDR_UNSET, 1156 .radio_addr = ADDR_UNSET,
1170 .audio_hook = gvbctv3pci_audio, 1157 .audio_mode_gpio= gvbctv3pci_audio,
1171 }, 1158 },
1172 [BTTV_BOARD_PXELVWPLTVPAK] = { 1159 [BTTV_BOARD_PXELVWPLTVPAK] = {
1173 .name = "Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP", 1160 .name = "Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP",
@@ -1472,7 +1459,7 @@ struct tvcard bttv_tvcards[] = {
1472 /* -dk-???: set mute=0x1800 for tda9874h daughterboard */ 1459 /* -dk-???: set mute=0x1800 for tda9874h daughterboard */
1473 .gpiomux = { 0x0000,0x0800,0x1000,0x1000 }, 1460 .gpiomux = { 0x0000,0x0800,0x1000,0x1000 },
1474 .gpiomute = 0x1800, 1461 .gpiomute = 0x1800,
1475 .audio_hook = fv2000s_audio, 1462 .audio_mode_gpio= fv2000s_audio,
1476 .no_msp34xx = 1, 1463 .no_msp34xx = 1,
1477 .no_tda9875 = 1, 1464 .no_tda9875 = 1,
1478 .needs_tvaudio = 1, 1465 .needs_tvaudio = 1,
@@ -1513,7 +1500,7 @@ struct tvcard bttv_tvcards[] = {
1513 .tuner_type = TUNER_SHARP_2U5JF5540_NTSC, 1500 .tuner_type = TUNER_SHARP_2U5JF5540_NTSC,
1514 .tuner_addr = ADDR_UNSET, 1501 .tuner_addr = ADDR_UNSET,
1515 .radio_addr = ADDR_UNSET, 1502 .radio_addr = ADDR_UNSET,
1516 .audio_hook = gvbctv3pci_audio, 1503 .audio_mode_gpio= gvbctv3pci_audio,
1517 }, 1504 },
1518 1505
1519 /* ---- card 0x44 ---------------------------------- */ 1506 /* ---- card 0x44 ---------------------------------- */
@@ -1632,7 +1619,7 @@ struct tvcard bttv_tvcards[] = {
1632 .tuner_type = TUNER_PHILIPS_PAL, 1619 .tuner_type = TUNER_PHILIPS_PAL,
1633 .tuner_addr = ADDR_UNSET, 1620 .tuner_addr = ADDR_UNSET,
1634 .radio_addr = ADDR_UNSET, 1621 .radio_addr = ADDR_UNSET,
1635 .audio_hook = pvbt878p9b_audio, /* Note: not all cards have stereo */ 1622 .audio_mode_gpio= pvbt878p9b_audio, /* Note: not all cards have stereo */
1636 .has_radio = 1, /* Note: not all cards have radio */ 1623 .has_radio = 1, /* Note: not all cards have radio */
1637 .has_remote = 1, 1624 .has_remote = 1,
1638 /* GPIO wiring: 1625 /* GPIO wiring:
@@ -1710,7 +1697,7 @@ struct tvcard bttv_tvcards[] = {
1710 .tuner_type = TUNER_PHILIPS_NTSC, 1697 .tuner_type = TUNER_PHILIPS_NTSC,
1711 .tuner_addr = ADDR_UNSET, 1698 .tuner_addr = ADDR_UNSET,
1712 .radio_addr = ADDR_UNSET, 1699 .radio_addr = ADDR_UNSET,
1713 .audio_hook = windvr_audio, 1700 .audio_mode_gpio= windvr_audio,
1714 }, 1701 },
1715 [BTTV_BOARD_GRANDTEC_MULTI] = { 1702 [BTTV_BOARD_GRANDTEC_MULTI] = {
1716 .name = "GrandTec Multi Capture Card (Bt878)", 1703 .name = "GrandTec Multi Capture Card (Bt878)",
@@ -1807,7 +1794,7 @@ struct tvcard bttv_tvcards[] = {
1807 .tuner_type = TUNER_PHILIPS_NTSC_M, 1794 .tuner_type = TUNER_PHILIPS_NTSC_M,
1808 .tuner_addr = ADDR_UNSET, 1795 .tuner_addr = ADDR_UNSET,
1809 .radio_addr = ADDR_UNSET, 1796 .radio_addr = ADDR_UNSET,
1810 .audio_hook = gvbctv5pci_audio, 1797 .audio_mode_gpio= gvbctv5pci_audio,
1811 .has_radio = 1, 1798 .has_radio = 1,
1812 }, 1799 },
1813 [BTTV_BOARD_OSPREY1x0] = { 1800 [BTTV_BOARD_OSPREY1x0] = {
@@ -2106,7 +2093,7 @@ struct tvcard bttv_tvcards[] = {
2106 .tuner_type = TUNER_PHILIPS_NTSC, 2093 .tuner_type = TUNER_PHILIPS_NTSC,
2107 .tuner_addr = ADDR_UNSET, 2094 .tuner_addr = ADDR_UNSET,
2108 .radio_addr = ADDR_UNSET, 2095 .radio_addr = ADDR_UNSET,
2109 .audio_hook = adtvk503_audio, 2096 .audio_mode_gpio= adtvk503_audio,
2110 }, 2097 },
2111 2098
2112 /* ---- card 0x64 ---------------------------------- */ 2099 /* ---- card 0x64 ---------------------------------- */
@@ -3173,8 +3160,8 @@ static void flyvideo_gpio(struct bttv *btv)
3173 /* LR90 Audio Routing is done by 2 hef4052, so Audio_Mask has 4 bits: 0x001c80 3160 /* LR90 Audio Routing is done by 2 hef4052, so Audio_Mask has 4 bits: 0x001c80
3174 * LR26/LR50 only has 1 hef4052, Audio_Mask 0x000c00 3161 * LR26/LR50 only has 1 hef4052, Audio_Mask 0x000c00
3175 * Audio options: from tuner, from tda9821/tda9821(mono,stereo,sap), from tda9874, ext., mute */ 3162 * Audio options: from tuner, from tda9821/tda9821(mono,stereo,sap), from tda9874, ext., mute */
3176 if(has_tda9820_tda9821) btv->audio_hook = lt9415_audio; 3163 if(has_tda9820_tda9821) btv->audio_mode_gpio = lt9415_audio;
3177 /* todo: if(has_tda9874) btv->audio_hook = fv2000s_audio; */ 3164 /* todo: if(has_tda9874) btv->audio_mode_gpio = fv2000s_audio; */
3178} 3165}
3179 3166
3180static int miro_tunermap[] = { 0,6,2,3, 4,5,6,0, 3,0,4,5, 5,2,16,1, 3167static int miro_tunermap[] = { 0,6,2,3, 4,5,6,0, 3,0,4,5, 5,2,16,1,
@@ -3574,8 +3561,12 @@ void __devinit bttv_init_card2(struct bttv *btv)
3574 } 3561 }
3575 3562
3576 if (btv->tda9887_conf) { 3563 if (btv->tda9887_conf) {
3577 bttv_call_i2c_clients(btv, TDA9887_SET_CONFIG, 3564 struct v4l2_priv_tun_config tda9887_cfg;
3578 &btv->tda9887_conf); 3565
3566 tda9887_cfg.tuner = TUNER_TDA9887;
3567 tda9887_cfg.priv = &btv->tda9887_conf;
3568
3569 bttv_call_i2c_clients(btv, TUNER_SET_CONFIG, &tda9887_cfg);
3579 } 3570 }
3580 3571
3581 btv->svhs = bttv_tvcards[btv->c.type].svhs; 3572 btv->svhs = bttv_tvcards[btv->c.type].svhs;
@@ -3590,8 +3581,10 @@ void __devinit bttv_init_card2(struct bttv *btv)
3590 btv->has_remote=1; 3581 btv->has_remote=1;
3591 if (!bttv_tvcards[btv->c.type].no_gpioirq) 3582 if (!bttv_tvcards[btv->c.type].no_gpioirq)
3592 btv->gpioirq=1; 3583 btv->gpioirq=1;
3593 if (bttv_tvcards[btv->c.type].audio_hook) 3584 if (bttv_tvcards[btv->c.type].volume_gpio)
3594 btv->audio_hook=bttv_tvcards[btv->c.type].audio_hook; 3585 btv->volume_gpio=bttv_tvcards[btv->c.type].volume_gpio;
3586 if (bttv_tvcards[btv->c.type].audio_mode_gpio)
3587 btv->audio_mode_gpio=bttv_tvcards[btv->c.type].audio_mode_gpio;
3595 3588
3596 if (bttv_tvcards[btv->c.type].digital_mode == DIGITAL_MODE_CAMERA) { 3589 if (bttv_tvcards[btv->c.type].digital_mode == DIGITAL_MODE_CAMERA) {
3597 /* detect Bt832 chip for quartzsight digital camera */ 3590 /* detect Bt832 chip for quartzsight digital camera */
@@ -3950,7 +3943,7 @@ static void __devinit avermedia_eeprom(struct bttv *btv)
3950void bttv_tda9880_setnorm(struct bttv *btv, int norm) 3943void bttv_tda9880_setnorm(struct bttv *btv, int norm)
3951{ 3944{
3952 /* fix up our card entry */ 3945 /* fix up our card entry */
3953 if(norm==VIDEO_MODE_NTSC) { 3946 if(norm==V4L2_STD_NTSC) {
3954 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomux[TVAUDIO_INPUT_TUNER]=0x957fff; 3947 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomux[TVAUDIO_INPUT_TUNER]=0x957fff;
3955 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomute=0x957fff; 3948 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomute=0x957fff;
3956 bttv_tvcards[BTTV_BOARD_VOODOOTV_200].gpiomux[TVAUDIO_INPUT_TUNER]=0x957fff; 3949 bttv_tvcards[BTTV_BOARD_VOODOOTV_200].gpiomux[TVAUDIO_INPUT_TUNER]=0x957fff;
@@ -4319,387 +4312,6 @@ void tea5757_set_freq(struct bttv *btv, unsigned short freq)
4319 tea5757_write(btv, 5 * freq + 0x358); /* add 10.7MHz (see docs) */ 4312 tea5757_write(btv, 5 * freq + 0x358); /* add 10.7MHz (see docs) */
4320} 4313}
4321 4314
4322
4323/* ----------------------------------------------------------------------- */
4324/* winview */
4325
4326static void winview_audio(struct bttv *btv, struct video_audio *v, int set)
4327{
4328 /* PT2254A programming Jon Tombs, jon@gte.esi.us.es */
4329 int bits_out, loops, vol, data;
4330
4331 if (!set) {
4332 /* Fixed by Leandro Lucarella <luca@linuxmendoza.org.ar (07/31/01) */
4333 v->flags |= VIDEO_AUDIO_VOLUME;
4334 return;
4335 }
4336
4337 /* 32 levels logarithmic */
4338 vol = 32 - ((v->volume>>11));
4339 /* units */
4340 bits_out = (PT2254_DBS_IN_2>>(vol%5));
4341 /* tens */
4342 bits_out |= (PT2254_DBS_IN_10>>(vol/5));
4343 bits_out |= PT2254_L_CHANNEL | PT2254_R_CHANNEL;
4344 data = gpio_read();
4345 data &= ~(WINVIEW_PT2254_CLK| WINVIEW_PT2254_DATA|
4346 WINVIEW_PT2254_STROBE);
4347 for (loops = 17; loops >= 0 ; loops--) {
4348 if (bits_out & (1<<loops))
4349 data |= WINVIEW_PT2254_DATA;
4350 else
4351 data &= ~WINVIEW_PT2254_DATA;
4352 gpio_write(data);
4353 udelay(5);
4354 data |= WINVIEW_PT2254_CLK;
4355 gpio_write(data);
4356 udelay(5);
4357 data &= ~WINVIEW_PT2254_CLK;
4358 gpio_write(data);
4359 }
4360 data |= WINVIEW_PT2254_STROBE;
4361 data &= ~WINVIEW_PT2254_DATA;
4362 gpio_write(data);
4363 udelay(10);
4364 data &= ~WINVIEW_PT2254_STROBE;
4365 gpio_write(data);
4366}
4367
4368/* ----------------------------------------------------------------------- */
4369/* mono/stereo control for various cards (which don't use i2c chips but */
4370/* connect something to the GPIO pins */
4371
4372static void
4373gvbctv3pci_audio(struct bttv *btv, struct video_audio *v, int set)
4374{
4375 unsigned int con = 0;
4376
4377 if (set) {
4378 gpio_inout(0x300, 0x300);
4379 if (v->mode & VIDEO_SOUND_LANG1)
4380 con = 0x000;
4381 if (v->mode & VIDEO_SOUND_LANG2)
4382 con = 0x300;
4383 if (v->mode & VIDEO_SOUND_STEREO)
4384 con = 0x200;
4385/* if (v->mode & VIDEO_SOUND_MONO)
4386 * con = 0x100; */
4387 gpio_bits(0x300, con);
4388 } else {
4389 v->mode = VIDEO_SOUND_STEREO |
4390 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4391 }
4392}
4393
4394static void
4395gvbctv5pci_audio(struct bttv *btv, struct video_audio *v, int set)
4396{
4397 unsigned int val, con;
4398
4399 if (btv->radio_user)
4400 return;
4401
4402 val = gpio_read();
4403 if (set) {
4404 con = 0x000;
4405 if (v->mode & VIDEO_SOUND_LANG2) {
4406 if (v->mode & VIDEO_SOUND_LANG1) {
4407 /* LANG1 + LANG2 */
4408 con = 0x100;
4409 }
4410 else {
4411 /* LANG2 */
4412 con = 0x300;
4413 }
4414 }
4415 if (con != (val & 0x300)) {
4416 gpio_bits(0x300, con);
4417 if (bttv_gpio)
4418 bttv_gpio_tracking(btv,"gvbctv5pci");
4419 }
4420 } else {
4421 switch (val & 0x70) {
4422 case 0x10:
4423 v->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4424 break;
4425 case 0x30:
4426 v->mode = VIDEO_SOUND_LANG2;
4427 break;
4428 case 0x50:
4429 v->mode = VIDEO_SOUND_LANG1;
4430 break;
4431 case 0x60:
4432 v->mode = VIDEO_SOUND_STEREO;
4433 break;
4434 case 0x70:
4435 v->mode = VIDEO_SOUND_MONO;
4436 break;
4437 default:
4438 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4439 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4440 }
4441 }
4442}
4443
4444/*
4445 * Mario Medina Nussbaum <medisoft@alohabbs.org.mx>
4446 * I discover that on BT848_GPIO_DATA address a byte 0xcce enable stereo,
4447 * 0xdde enables mono and 0xccd enables sap
4448 *
4449 * Petr Vandrovec <VANDROVE@vc.cvut.cz>
4450 * P.S.: At least mask in line above is wrong - GPIO pins 3,2 select
4451 * input/output sound connection, so both must be set for output mode.
4452 *
4453 * Looks like it's needed only for the "tvphone", the "tvphone 98"
4454 * handles this with a tda9840
4455 *
4456 */
4457static void
4458avermedia_tvphone_audio(struct bttv *btv, struct video_audio *v, int set)
4459{
4460 int val = 0;
4461
4462 if (set) {
4463 if (v->mode & VIDEO_SOUND_LANG2) /* SAP */
4464 val = 0x02;
4465 if (v->mode & VIDEO_SOUND_STEREO)
4466 val = 0x01;
4467 if (val) {
4468 gpio_bits(0x03,val);
4469 if (bttv_gpio)
4470 bttv_gpio_tracking(btv,"avermedia");
4471 }
4472 } else {
4473 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4474 VIDEO_SOUND_LANG1;
4475 return;
4476 }
4477}
4478
4479static void
4480avermedia_tv_stereo_audio(struct bttv *btv, struct video_audio *v, int set)
4481{
4482 int val = 0;
4483
4484 if (set) {
4485 if (v->mode & VIDEO_SOUND_LANG2) /* SAP */
4486 val = 0x01;
4487 if (v->mode & VIDEO_SOUND_STEREO) /* STEREO */
4488 val = 0x02;
4489 btaor(val, ~0x03, BT848_GPIO_DATA);
4490 if (bttv_gpio)
4491 bttv_gpio_tracking(btv,"avermedia");
4492 } else {
4493 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4494 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4495 return;
4496 }
4497}
4498
4499/* Lifetec 9415 handling */
4500static void
4501lt9415_audio(struct bttv *btv, struct video_audio *v, int set)
4502{
4503 int val = 0;
4504
4505 if (gpio_read() & 0x4000) {
4506 v->mode = VIDEO_SOUND_MONO;
4507 return;
4508 }
4509
4510 if (set) {
4511 if (v->mode & VIDEO_SOUND_LANG2) /* A2 SAP */
4512 val = 0x0080;
4513 if (v->mode & VIDEO_SOUND_STEREO) /* A2 stereo */
4514 val = 0x0880;
4515 if ((v->mode & VIDEO_SOUND_LANG1) ||
4516 (v->mode & VIDEO_SOUND_MONO))
4517 val = 0;
4518 gpio_bits(0x0880, val);
4519 if (bttv_gpio)
4520 bttv_gpio_tracking(btv,"lt9415");
4521 } else {
4522 /* autodetect doesn't work with this card :-( */
4523 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4524 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4525 return;
4526 }
4527}
4528
4529/* TDA9821 on TerraTV+ Bt848, Bt878 */
4530static void
4531terratv_audio(struct bttv *btv, struct video_audio *v, int set)
4532{
4533 unsigned int con = 0;
4534
4535 if (set) {
4536 gpio_inout(0x180000,0x180000);
4537 if (v->mode & VIDEO_SOUND_LANG2)
4538 con = 0x080000;
4539 if (v->mode & VIDEO_SOUND_STEREO)
4540 con = 0x180000;
4541 gpio_bits(0x180000, con);
4542 if (bttv_gpio)
4543 bttv_gpio_tracking(btv,"terratv");
4544 } else {
4545 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4546 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4547 }
4548}
4549
4550static void
4551winfast2000_audio(struct bttv *btv, struct video_audio *v, int set)
4552{
4553 unsigned long val = 0;
4554
4555 if (set) {
4556 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
4557 if (v->mode & VIDEO_SOUND_MONO) /* Mono */
4558 val = 0x420000;
4559 if (v->mode & VIDEO_SOUND_LANG1) /* Mono */
4560 val = 0x420000;
4561 if (v->mode & VIDEO_SOUND_LANG2) /* SAP */
4562 val = 0x410000;
4563 if (v->mode & VIDEO_SOUND_STEREO) /* Stereo */
4564 val = 0x020000;
4565 if (val) {
4566 gpio_bits(0x430000, val);
4567 if (bttv_gpio)
4568 bttv_gpio_tracking(btv,"winfast2000");
4569 }
4570 } else {
4571 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4572 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4573 }
4574}
4575
4576/*
4577 * Dariusz Kowalewski <darekk@automex.pl>
4578 * sound control for Prolink PV-BT878P+9B (PixelView PlayTV Pro FM+NICAM
4579 * revision 9B has on-board TDA9874A sound decoder).
4580 *
4581 * Note: There are card variants without tda9874a. Forcing the "stereo sound route"
4582 * will mute this cards.
4583 */
4584static void
4585pvbt878p9b_audio(struct bttv *btv, struct video_audio *v, int set)
4586{
4587 unsigned int val = 0;
4588
4589 if (btv->radio_user)
4590 return;
4591
4592 if (set) {
4593 if (v->mode & VIDEO_SOUND_MONO) {
4594 val = 0x01;
4595 }
4596 if ((v->mode & (VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2))
4597 || (v->mode & VIDEO_SOUND_STEREO)) {
4598 val = 0x02;
4599 }
4600 if (val) {
4601 gpio_bits(0x03,val);
4602 if (bttv_gpio)
4603 bttv_gpio_tracking(btv,"pvbt878p9b");
4604 }
4605 } else {
4606 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4607 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4608 }
4609}
4610
4611/*
4612 * Dariusz Kowalewski <darekk@automex.pl>
4613 * sound control for FlyVideo 2000S (with tda9874 decoder)
4614 * based on pvbt878p9b_audio() - this is not tested, please fix!!!
4615 */
4616static void
4617fv2000s_audio(struct bttv *btv, struct video_audio *v, int set)
4618{
4619 unsigned int val = 0xffff;
4620
4621 if (btv->radio_user)
4622 return;
4623 if (set) {
4624 if (v->mode & VIDEO_SOUND_MONO) {
4625 val = 0x0000;
4626 }
4627 if ((v->mode & (VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2))
4628 || (v->mode & VIDEO_SOUND_STEREO)) {
4629 val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
4630 }
4631 if (val != 0xffff) {
4632 gpio_bits(0x1800, val);
4633 if (bttv_gpio)
4634 bttv_gpio_tracking(btv,"fv2000s");
4635 }
4636 } else {
4637 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4638 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4639 }
4640}
4641
4642/*
4643 * sound control for Canopus WinDVR PCI
4644 * Masaki Suzuki <masaki@btree.org>
4645 */
4646static void
4647windvr_audio(struct bttv *btv, struct video_audio *v, int set)
4648{
4649 unsigned long val = 0;
4650
4651 if (set) {
4652 if (v->mode & VIDEO_SOUND_MONO)
4653 val = 0x040000;
4654 if (v->mode & VIDEO_SOUND_LANG1)
4655 val = 0;
4656 if (v->mode & VIDEO_SOUND_LANG2)
4657 val = 0x100000;
4658 if (v->mode & VIDEO_SOUND_STEREO)
4659 val = 0;
4660 if (val) {
4661 gpio_bits(0x140000, val);
4662 if (bttv_gpio)
4663 bttv_gpio_tracking(btv,"windvr");
4664 }
4665 } else {
4666 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4667 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4668 }
4669}
4670
4671/*
4672 * sound control for AD-TVK503
4673 * Hiroshi Takekawa <sian@big.or.jp>
4674 */
4675static void
4676adtvk503_audio(struct bttv *btv, struct video_audio *v, int set)
4677{
4678 unsigned int con = 0xffffff;
4679
4680 /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
4681
4682 if (set) {
4683 /* btor(***, BT848_GPIO_OUT_EN); */
4684 if (v->mode & VIDEO_SOUND_LANG1)
4685 con = 0x00000000;
4686 if (v->mode & VIDEO_SOUND_LANG2)
4687 con = 0x00180000;
4688 if (v->mode & VIDEO_SOUND_STEREO)
4689 con = 0x00000000;
4690 if (v->mode & VIDEO_SOUND_MONO)
4691 con = 0x00060000;
4692 if (con != 0xffffff) {
4693 gpio_bits(0x1e0000,con);
4694 if (bttv_gpio)
4695 bttv_gpio_tracking(btv, "adtvk503");
4696 }
4697 } else {
4698 v->mode = VIDEO_SOUND_MONO | VIDEO_SOUND_STEREO |
4699 VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
4700 }
4701}
4702
4703/* RemoteVision MX (rv605) muxsel helper [Miguel Freitas] 4315/* RemoteVision MX (rv605) muxsel helper [Miguel Freitas]
4704 * 4316 *
4705 * This is needed because rv605 don't use a normal multiplex, but a crosspoint 4317 * This is needed because rv605 don't use a normal multiplex, but a crosspoint
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 581a3c955739..907dc62c1783 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -9,6 +9,12 @@
9 some v4l2 code lines are taken from Justin's bttv2 driver which is 9 some v4l2 code lines are taken from Justin's bttv2 driver which is
10 (c) 2000 Justin Schoeman <justin@suntiger.ee.up.ac.za> 10 (c) 2000 Justin Schoeman <justin@suntiger.ee.up.ac.za>
11 11
12 V4L1 removal from:
13 (c) 2005-2006 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
14
15 Fixes to be fully V4L2 compliant by
16 (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
17
12 Cropping and overscan support 18 Cropping and overscan support
13 Copyright (C) 2005, 2006 Michael H. Schimek <mschimek@gmx.at> 19 Copyright (C) 2005, 2006 Michael H. Schimek <mschimek@gmx.at>
14 Sponsored by OPQ Systems AB 20 Sponsored by OPQ Systems AB
@@ -157,7 +163,7 @@ MODULE_LICENSE("GPL");
157static ssize_t show_card(struct device *cd, 163static ssize_t show_card(struct device *cd,
158 struct device_attribute *attr, char *buf) 164 struct device_attribute *attr, char *buf)
159{ 165{
160 struct video_device *vfd = to_video_device(cd); 166 struct video_device *vfd = container_of(cd, struct video_device, class_dev);
161 struct bttv *btv = dev_get_drvdata(vfd->dev); 167 struct bttv *btv = dev_get_drvdata(vfd->dev);
162 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET); 168 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
163} 169}
@@ -470,31 +476,27 @@ static const unsigned int BTTV_TVNORMS = ARRAY_SIZE(bttv_tvnorms);
470/* ----------------------------------------------------------------------- */ 476/* ----------------------------------------------------------------------- */
471/* bttv format list 477/* bttv format list
472 packed pixel formats must come first */ 478 packed pixel formats must come first */
473static const struct bttv_format bttv_formats[] = { 479static const struct bttv_format formats[] = {
474 { 480 {
475 .name = "8 bpp, gray", 481 .name = "8 bpp, gray",
476 .palette = VIDEO_PALETTE_GREY,
477 .fourcc = V4L2_PIX_FMT_GREY, 482 .fourcc = V4L2_PIX_FMT_GREY,
478 .btformat = BT848_COLOR_FMT_Y8, 483 .btformat = BT848_COLOR_FMT_Y8,
479 .depth = 8, 484 .depth = 8,
480 .flags = FORMAT_FLAGS_PACKED, 485 .flags = FORMAT_FLAGS_PACKED,
481 },{ 486 },{
482 .name = "8 bpp, dithered color", 487 .name = "8 bpp, dithered color",
483 .palette = VIDEO_PALETTE_HI240,
484 .fourcc = V4L2_PIX_FMT_HI240, 488 .fourcc = V4L2_PIX_FMT_HI240,
485 .btformat = BT848_COLOR_FMT_RGB8, 489 .btformat = BT848_COLOR_FMT_RGB8,
486 .depth = 8, 490 .depth = 8,
487 .flags = FORMAT_FLAGS_PACKED | FORMAT_FLAGS_DITHER, 491 .flags = FORMAT_FLAGS_PACKED | FORMAT_FLAGS_DITHER,
488 },{ 492 },{
489 .name = "15 bpp RGB, le", 493 .name = "15 bpp RGB, le",
490 .palette = VIDEO_PALETTE_RGB555,
491 .fourcc = V4L2_PIX_FMT_RGB555, 494 .fourcc = V4L2_PIX_FMT_RGB555,
492 .btformat = BT848_COLOR_FMT_RGB15, 495 .btformat = BT848_COLOR_FMT_RGB15,
493 .depth = 16, 496 .depth = 16,
494 .flags = FORMAT_FLAGS_PACKED, 497 .flags = FORMAT_FLAGS_PACKED,
495 },{ 498 },{
496 .name = "15 bpp RGB, be", 499 .name = "15 bpp RGB, be",
497 .palette = -1,
498 .fourcc = V4L2_PIX_FMT_RGB555X, 500 .fourcc = V4L2_PIX_FMT_RGB555X,
499 .btformat = BT848_COLOR_FMT_RGB15, 501 .btformat = BT848_COLOR_FMT_RGB15,
500 .btswap = 0x03, /* byteswap */ 502 .btswap = 0x03, /* byteswap */
@@ -502,14 +504,12 @@ static const struct bttv_format bttv_formats[] = {
502 .flags = FORMAT_FLAGS_PACKED, 504 .flags = FORMAT_FLAGS_PACKED,
503 },{ 505 },{
504 .name = "16 bpp RGB, le", 506 .name = "16 bpp RGB, le",
505 .palette = VIDEO_PALETTE_RGB565,
506 .fourcc = V4L2_PIX_FMT_RGB565, 507 .fourcc = V4L2_PIX_FMT_RGB565,
507 .btformat = BT848_COLOR_FMT_RGB16, 508 .btformat = BT848_COLOR_FMT_RGB16,
508 .depth = 16, 509 .depth = 16,
509 .flags = FORMAT_FLAGS_PACKED, 510 .flags = FORMAT_FLAGS_PACKED,
510 },{ 511 },{
511 .name = "16 bpp RGB, be", 512 .name = "16 bpp RGB, be",
512 .palette = -1,
513 .fourcc = V4L2_PIX_FMT_RGB565X, 513 .fourcc = V4L2_PIX_FMT_RGB565X,
514 .btformat = BT848_COLOR_FMT_RGB16, 514 .btformat = BT848_COLOR_FMT_RGB16,
515 .btswap = 0x03, /* byteswap */ 515 .btswap = 0x03, /* byteswap */
@@ -517,21 +517,18 @@ static const struct bttv_format bttv_formats[] = {
517 .flags = FORMAT_FLAGS_PACKED, 517 .flags = FORMAT_FLAGS_PACKED,
518 },{ 518 },{
519 .name = "24 bpp RGB, le", 519 .name = "24 bpp RGB, le",
520 .palette = VIDEO_PALETTE_RGB24,
521 .fourcc = V4L2_PIX_FMT_BGR24, 520 .fourcc = V4L2_PIX_FMT_BGR24,
522 .btformat = BT848_COLOR_FMT_RGB24, 521 .btformat = BT848_COLOR_FMT_RGB24,
523 .depth = 24, 522 .depth = 24,
524 .flags = FORMAT_FLAGS_PACKED, 523 .flags = FORMAT_FLAGS_PACKED,
525 },{ 524 },{
526 .name = "32 bpp RGB, le", 525 .name = "32 bpp RGB, le",
527 .palette = VIDEO_PALETTE_RGB32,
528 .fourcc = V4L2_PIX_FMT_BGR32, 526 .fourcc = V4L2_PIX_FMT_BGR32,
529 .btformat = BT848_COLOR_FMT_RGB32, 527 .btformat = BT848_COLOR_FMT_RGB32,
530 .depth = 32, 528 .depth = 32,
531 .flags = FORMAT_FLAGS_PACKED, 529 .flags = FORMAT_FLAGS_PACKED,
532 },{ 530 },{
533 .name = "32 bpp RGB, be", 531 .name = "32 bpp RGB, be",
534 .palette = -1,
535 .fourcc = V4L2_PIX_FMT_RGB32, 532 .fourcc = V4L2_PIX_FMT_RGB32,
536 .btformat = BT848_COLOR_FMT_RGB32, 533 .btformat = BT848_COLOR_FMT_RGB32,
537 .btswap = 0x0f, /* byte+word swap */ 534 .btswap = 0x0f, /* byte+word swap */
@@ -539,21 +536,18 @@ static const struct bttv_format bttv_formats[] = {
539 .flags = FORMAT_FLAGS_PACKED, 536 .flags = FORMAT_FLAGS_PACKED,
540 },{ 537 },{
541 .name = "4:2:2, packed, YUYV", 538 .name = "4:2:2, packed, YUYV",
542 .palette = VIDEO_PALETTE_YUV422,
543 .fourcc = V4L2_PIX_FMT_YUYV, 539 .fourcc = V4L2_PIX_FMT_YUYV,
544 .btformat = BT848_COLOR_FMT_YUY2, 540 .btformat = BT848_COLOR_FMT_YUY2,
545 .depth = 16, 541 .depth = 16,
546 .flags = FORMAT_FLAGS_PACKED, 542 .flags = FORMAT_FLAGS_PACKED,
547 },{ 543 },{
548 .name = "4:2:2, packed, YUYV", 544 .name = "4:2:2, packed, YUYV",
549 .palette = VIDEO_PALETTE_YUYV,
550 .fourcc = V4L2_PIX_FMT_YUYV, 545 .fourcc = V4L2_PIX_FMT_YUYV,
551 .btformat = BT848_COLOR_FMT_YUY2, 546 .btformat = BT848_COLOR_FMT_YUY2,
552 .depth = 16, 547 .depth = 16,
553 .flags = FORMAT_FLAGS_PACKED, 548 .flags = FORMAT_FLAGS_PACKED,
554 },{ 549 },{
555 .name = "4:2:2, packed, UYVY", 550 .name = "4:2:2, packed, UYVY",
556 .palette = VIDEO_PALETTE_UYVY,
557 .fourcc = V4L2_PIX_FMT_UYVY, 551 .fourcc = V4L2_PIX_FMT_UYVY,
558 .btformat = BT848_COLOR_FMT_YUY2, 552 .btformat = BT848_COLOR_FMT_YUY2,
559 .btswap = 0x03, /* byteswap */ 553 .btswap = 0x03, /* byteswap */
@@ -561,7 +555,6 @@ static const struct bttv_format bttv_formats[] = {
561 .flags = FORMAT_FLAGS_PACKED, 555 .flags = FORMAT_FLAGS_PACKED,
562 },{ 556 },{
563 .name = "4:2:2, planar, Y-Cb-Cr", 557 .name = "4:2:2, planar, Y-Cb-Cr",
564 .palette = VIDEO_PALETTE_YUV422P,
565 .fourcc = V4L2_PIX_FMT_YUV422P, 558 .fourcc = V4L2_PIX_FMT_YUV422P,
566 .btformat = BT848_COLOR_FMT_YCrCb422, 559 .btformat = BT848_COLOR_FMT_YCrCb422,
567 .depth = 16, 560 .depth = 16,
@@ -570,7 +563,6 @@ static const struct bttv_format bttv_formats[] = {
570 .vshift = 0, 563 .vshift = 0,
571 },{ 564 },{
572 .name = "4:2:0, planar, Y-Cb-Cr", 565 .name = "4:2:0, planar, Y-Cb-Cr",
573 .palette = VIDEO_PALETTE_YUV420P,
574 .fourcc = V4L2_PIX_FMT_YUV420, 566 .fourcc = V4L2_PIX_FMT_YUV420,
575 .btformat = BT848_COLOR_FMT_YCrCb422, 567 .btformat = BT848_COLOR_FMT_YCrCb422,
576 .depth = 12, 568 .depth = 12,
@@ -579,7 +571,6 @@ static const struct bttv_format bttv_formats[] = {
579 .vshift = 1, 571 .vshift = 1,
580 },{ 572 },{
581 .name = "4:2:0, planar, Y-Cr-Cb", 573 .name = "4:2:0, planar, Y-Cr-Cb",
582 .palette = -1,
583 .fourcc = V4L2_PIX_FMT_YVU420, 574 .fourcc = V4L2_PIX_FMT_YVU420,
584 .btformat = BT848_COLOR_FMT_YCrCb422, 575 .btformat = BT848_COLOR_FMT_YCrCb422,
585 .depth = 12, 576 .depth = 12,
@@ -588,7 +579,6 @@ static const struct bttv_format bttv_formats[] = {
588 .vshift = 1, 579 .vshift = 1,
589 },{ 580 },{
590 .name = "4:1:1, planar, Y-Cb-Cr", 581 .name = "4:1:1, planar, Y-Cb-Cr",
591 .palette = VIDEO_PALETTE_YUV411P,
592 .fourcc = V4L2_PIX_FMT_YUV411P, 582 .fourcc = V4L2_PIX_FMT_YUV411P,
593 .btformat = BT848_COLOR_FMT_YCrCb411, 583 .btformat = BT848_COLOR_FMT_YCrCb411,
594 .depth = 12, 584 .depth = 12,
@@ -597,7 +587,6 @@ static const struct bttv_format bttv_formats[] = {
597 .vshift = 0, 587 .vshift = 0,
598 },{ 588 },{
599 .name = "4:1:0, planar, Y-Cb-Cr", 589 .name = "4:1:0, planar, Y-Cb-Cr",
600 .palette = VIDEO_PALETTE_YUV410P,
601 .fourcc = V4L2_PIX_FMT_YUV410, 590 .fourcc = V4L2_PIX_FMT_YUV410,
602 .btformat = BT848_COLOR_FMT_YCrCb411, 591 .btformat = BT848_COLOR_FMT_YCrCb411,
603 .depth = 9, 592 .depth = 9,
@@ -606,7 +595,6 @@ static const struct bttv_format bttv_formats[] = {
606 .vshift = 2, 595 .vshift = 2,
607 },{ 596 },{
608 .name = "4:1:0, planar, Y-Cr-Cb", 597 .name = "4:1:0, planar, Y-Cr-Cb",
609 .palette = -1,
610 .fourcc = V4L2_PIX_FMT_YVU410, 598 .fourcc = V4L2_PIX_FMT_YVU410,
611 .btformat = BT848_COLOR_FMT_YCrCb411, 599 .btformat = BT848_COLOR_FMT_YCrCb411,
612 .depth = 9, 600 .depth = 9,
@@ -615,14 +603,13 @@ static const struct bttv_format bttv_formats[] = {
615 .vshift = 2, 603 .vshift = 2,
616 },{ 604 },{
617 .name = "raw scanlines", 605 .name = "raw scanlines",
618 .palette = VIDEO_PALETTE_RAW,
619 .fourcc = -1, 606 .fourcc = -1,
620 .btformat = BT848_COLOR_FMT_RAW, 607 .btformat = BT848_COLOR_FMT_RAW,
621 .depth = 8, 608 .depth = 8,
622 .flags = FORMAT_FLAGS_RAW, 609 .flags = FORMAT_FLAGS_RAW,
623 } 610 }
624}; 611};
625static const unsigned int BTTV_FORMATS = ARRAY_SIZE(bttv_formats); 612static const unsigned int FORMATS = ARRAY_SIZE(formats);
626 613
627/* ----------------------------------------------------------------------- */ 614/* ----------------------------------------------------------------------- */
628 615
@@ -798,7 +785,17 @@ static const struct v4l2_queryctrl bttv_ctls[] = {
798 785
799 786
800}; 787};
801static const int BTTV_CTLS = ARRAY_SIZE(bttv_ctls); 788
789static const struct v4l2_queryctrl *ctrl_by_id(int id)
790{
791 int i;
792
793 for (i = 0; i < ARRAY_SIZE(bttv_ctls); i++)
794 if (bttv_ctls[i].id == id)
795 return bttv_ctls+i;
796
797 return NULL;
798}
802 799
803/* ----------------------------------------------------------------------- */ 800/* ----------------------------------------------------------------------- */
804/* resource management */ 801/* resource management */
@@ -1255,16 +1252,6 @@ audio_input(struct bttv *btv, int input)
1255} 1252}
1256 1253
1257static void 1254static void
1258i2c_vidiocschan(struct bttv *btv)
1259{
1260 v4l2_std_id std = bttv_tvnorms[btv->tvnorm].v4l2_id;
1261
1262 bttv_call_i2c_clients(btv, VIDIOC_S_STD, &std);
1263 if (btv->c.type == BTTV_BOARD_VOODOOTV_FM || btv->c.type == BTTV_BOARD_VOODOOTV_200)
1264 bttv_tda9880_setnorm(btv,btv->tvnorm);
1265}
1266
1267static void
1268bttv_crop_calc_limits(struct bttv_crop *c) 1255bttv_crop_calc_limits(struct bttv_crop *c)
1269{ 1256{
1270 /* Scale factor min. 1:1, max. 16:1. Min. image size 1257 /* Scale factor min. 1:1, max. 16:1. Min. image size
@@ -1298,6 +1285,7 @@ static int
1298set_tvnorm(struct bttv *btv, unsigned int norm) 1285set_tvnorm(struct bttv *btv, unsigned int norm)
1299{ 1286{
1300 const struct bttv_tvnorm *tvnorm; 1287 const struct bttv_tvnorm *tvnorm;
1288 v4l2_std_id id;
1301 1289
1302 if (norm < 0 || norm >= BTTV_TVNORMS) 1290 if (norm < 0 || norm >= BTTV_TVNORMS)
1303 return -EINVAL; 1291 return -EINVAL;
@@ -1334,6 +1322,9 @@ set_tvnorm(struct bttv *btv, unsigned int norm)
1334 bttv_tda9880_setnorm(btv,norm); 1322 bttv_tda9880_setnorm(btv,norm);
1335 break; 1323 break;
1336 } 1324 }
1325 id = tvnorm->v4l2_id;
1326 bttv_call_i2c_clients(btv, VIDIOC_S_STD, &id);
1327
1337 return 0; 1328 return 0;
1338} 1329}
1339 1330
@@ -1359,7 +1350,6 @@ set_input(struct bttv *btv, unsigned int input, unsigned int norm)
1359 audio_input(btv,(input == bttv_tvcards[btv->c.type].tuner ? 1350 audio_input(btv,(input == bttv_tvcards[btv->c.type].tuner ?
1360 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN)); 1351 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN));
1361 set_tvnorm(btv, norm); 1352 set_tvnorm(btv, norm);
1362 i2c_vidiocschan(btv);
1363} 1353}
1364 1354
1365static void init_irqreg(struct bttv *btv) 1355static void init_irqreg(struct bttv *btv)
@@ -1452,38 +1442,12 @@ static void bttv_reinit_bt848(struct bttv *btv)
1452 set_input(btv, btv->input, btv->tvnorm); 1442 set_input(btv, btv->input, btv->tvnorm);
1453} 1443}
1454 1444
1455static int get_control(struct bttv *btv, struct v4l2_control *c) 1445static int bttv_g_ctrl(struct file *file, void *priv,
1446 struct v4l2_control *c)
1456{ 1447{
1457 struct video_audio va; 1448 struct bttv_fh *fh = priv;
1458 int i; 1449 struct bttv *btv = fh->btv;
1459 1450
1460 for (i = 0; i < BTTV_CTLS; i++)
1461 if (bttv_ctls[i].id == c->id)
1462 break;
1463 if (i == BTTV_CTLS)
1464 return -EINVAL;
1465 if (btv->audio_hook && i >= 4 && i <= 8) {
1466 memset(&va,0,sizeof(va));
1467 btv->audio_hook(btv,&va,0);
1468 switch (c->id) {
1469 case V4L2_CID_AUDIO_MUTE:
1470 c->value = (VIDEO_AUDIO_MUTE & va.flags) ? 1 : 0;
1471 break;
1472 case V4L2_CID_AUDIO_VOLUME:
1473 c->value = va.volume;
1474 break;
1475 case V4L2_CID_AUDIO_BALANCE:
1476 c->value = va.balance;
1477 break;
1478 case V4L2_CID_AUDIO_BASS:
1479 c->value = va.bass;
1480 break;
1481 case V4L2_CID_AUDIO_TREBLE:
1482 c->value = va.treble;
1483 break;
1484 }
1485 return 0;
1486 }
1487 switch (c->id) { 1451 switch (c->id) {
1488 case V4L2_CID_BRIGHTNESS: 1452 case V4L2_CID_BRIGHTNESS:
1489 c->value = btv->bright; 1453 c->value = btv->bright;
@@ -1503,7 +1467,7 @@ static int get_control(struct bttv *btv, struct v4l2_control *c)
1503 case V4L2_CID_AUDIO_BALANCE: 1467 case V4L2_CID_AUDIO_BALANCE:
1504 case V4L2_CID_AUDIO_BASS: 1468 case V4L2_CID_AUDIO_BASS:
1505 case V4L2_CID_AUDIO_TREBLE: 1469 case V4L2_CID_AUDIO_TREBLE:
1506 bttv_call_i2c_clients(btv,VIDIOC_G_CTRL,c); 1470 bttv_call_i2c_clients(btv, VIDIOC_G_CTRL, c);
1507 break; 1471 break;
1508 1472
1509 case V4L2_CID_PRIVATE_CHROMA_AGC: 1473 case V4L2_CID_PRIVATE_CHROMA_AGC:
@@ -1545,67 +1509,44 @@ static int get_control(struct bttv *btv, struct v4l2_control *c)
1545 return 0; 1509 return 0;
1546} 1510}
1547 1511
1548static int set_control(struct bttv *btv, struct v4l2_control *c) 1512static int bttv_s_ctrl(struct file *file, void *f,
1513 struct v4l2_control *c)
1549{ 1514{
1550 struct video_audio va; 1515 int err;
1551 int i,val; 1516 int val;
1517 struct bttv_fh *fh = f;
1518 struct bttv *btv = fh->btv;
1552 1519
1553 for (i = 0; i < BTTV_CTLS; i++) 1520 err = v4l2_prio_check(&btv->prio, &fh->prio);
1554 if (bttv_ctls[i].id == c->id) 1521 if (0 != err)
1555 break; 1522 return err;
1556 if (i == BTTV_CTLS)
1557 return -EINVAL;
1558 if (btv->audio_hook && i >= 4 && i <= 8) {
1559 memset(&va,0,sizeof(va));
1560 btv->audio_hook(btv,&va,0);
1561 switch (c->id) {
1562 case V4L2_CID_AUDIO_MUTE:
1563 if (c->value) {
1564 va.flags |= VIDEO_AUDIO_MUTE;
1565 audio_mute(btv, 1);
1566 } else {
1567 va.flags &= ~VIDEO_AUDIO_MUTE;
1568 audio_mute(btv, 0);
1569 }
1570 break;
1571 1523
1572 case V4L2_CID_AUDIO_VOLUME:
1573 va.volume = c->value;
1574 break;
1575 case V4L2_CID_AUDIO_BALANCE:
1576 va.balance = c->value;
1577 break;
1578 case V4L2_CID_AUDIO_BASS:
1579 va.bass = c->value;
1580 break;
1581 case V4L2_CID_AUDIO_TREBLE:
1582 va.treble = c->value;
1583 break;
1584 }
1585 btv->audio_hook(btv,&va,1);
1586 return 0;
1587 }
1588 switch (c->id) { 1524 switch (c->id) {
1589 case V4L2_CID_BRIGHTNESS: 1525 case V4L2_CID_BRIGHTNESS:
1590 bt848_bright(btv,c->value); 1526 bt848_bright(btv, c->value);
1591 break; 1527 break;
1592 case V4L2_CID_HUE: 1528 case V4L2_CID_HUE:
1593 bt848_hue(btv,c->value); 1529 bt848_hue(btv, c->value);
1594 break; 1530 break;
1595 case V4L2_CID_CONTRAST: 1531 case V4L2_CID_CONTRAST:
1596 bt848_contrast(btv,c->value); 1532 bt848_contrast(btv, c->value);
1597 break; 1533 break;
1598 case V4L2_CID_SATURATION: 1534 case V4L2_CID_SATURATION:
1599 bt848_sat(btv,c->value); 1535 bt848_sat(btv, c->value);
1600 break; 1536 break;
1601 case V4L2_CID_AUDIO_MUTE: 1537 case V4L2_CID_AUDIO_MUTE:
1602 audio_mute(btv, c->value); 1538 audio_mute(btv, c->value);
1603 /* fall through */ 1539 /* fall through */
1604 case V4L2_CID_AUDIO_VOLUME: 1540 case V4L2_CID_AUDIO_VOLUME:
1541 if (btv->volume_gpio)
1542 btv->volume_gpio(btv, c->value);
1543
1544 bttv_call_i2c_clients(btv, VIDIOC_S_CTRL, c);
1545 break;
1605 case V4L2_CID_AUDIO_BALANCE: 1546 case V4L2_CID_AUDIO_BALANCE:
1606 case V4L2_CID_AUDIO_BASS: 1547 case V4L2_CID_AUDIO_BASS:
1607 case V4L2_CID_AUDIO_TREBLE: 1548 case V4L2_CID_AUDIO_TREBLE:
1608 bttv_call_i2c_clients(btv,VIDIOC_S_CTRL,c); 1549 bttv_call_i2c_clients(btv, VIDIOC_S_CTRL, c);
1609 break; 1550 break;
1610 1551
1611 case V4L2_CID_PRIVATE_CHROMA_AGC: 1552 case V4L2_CID_PRIVATE_CHROMA_AGC:
@@ -1632,8 +1573,9 @@ static int set_control(struct bttv *btv, struct v4l2_control *c)
1632 break; 1573 break;
1633 case V4L2_CID_PRIVATE_AGC_CRUSH: 1574 case V4L2_CID_PRIVATE_AGC_CRUSH:
1634 btv->opt_adc_crush = c->value; 1575 btv->opt_adc_crush = c->value;
1635 btwrite(BT848_ADC_RESERVED | (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0), 1576 btwrite(BT848_ADC_RESERVED |
1636 BT848_ADC); 1577 (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0),
1578 BT848_ADC);
1637 break; 1579 break;
1638 case V4L2_CID_PRIVATE_VCR_HACK: 1580 case V4L2_CID_PRIVATE_VCR_HACK:
1639 btv->opt_vcr_hack = c->value; 1581 btv->opt_vcr_hack = c->value;
@@ -1693,29 +1635,15 @@ static void bttv_field_count(struct bttv *btv)
1693} 1635}
1694 1636
1695static const struct bttv_format* 1637static const struct bttv_format*
1696format_by_palette(int palette)
1697{
1698 unsigned int i;
1699
1700 for (i = 0; i < BTTV_FORMATS; i++) {
1701 if (-1 == bttv_formats[i].palette)
1702 continue;
1703 if (bttv_formats[i].palette == palette)
1704 return bttv_formats+i;
1705 }
1706 return NULL;
1707}
1708
1709static const struct bttv_format*
1710format_by_fourcc(int fourcc) 1638format_by_fourcc(int fourcc)
1711{ 1639{
1712 unsigned int i; 1640 unsigned int i;
1713 1641
1714 for (i = 0; i < BTTV_FORMATS; i++) { 1642 for (i = 0; i < FORMATS; i++) {
1715 if (-1 == bttv_formats[i].fourcc) 1643 if (-1 == formats[i].fourcc)
1716 continue; 1644 continue;
1717 if (bttv_formats[i].fourcc == fourcc) 1645 if (formats[i].fourcc == fourcc)
1718 return bttv_formats+i; 1646 return formats+i;
1719 } 1647 }
1720 return NULL; 1648 return NULL;
1721} 1649}
@@ -1733,7 +1661,7 @@ bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
1733 1661
1734 dprintk("switch_overlay: enter [new=%p]\n",new); 1662 dprintk("switch_overlay: enter [new=%p]\n",new);
1735 if (new) 1663 if (new)
1736 new->vb.state = STATE_DONE; 1664 new->vb.state = VIDEOBUF_DONE;
1737 spin_lock_irqsave(&btv->s_lock,flags); 1665 spin_lock_irqsave(&btv->s_lock,flags);
1738 old = btv->screen; 1666 old = btv->screen;
1739 btv->screen = new; 1667 btv->screen = new;
@@ -1844,7 +1772,7 @@ static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1844 } 1772 }
1845 1773
1846 /* alloc risc memory */ 1774 /* alloc risc memory */
1847 if (STATE_NEEDS_INIT == buf->vb.state) { 1775 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
1848 redo_dma_risc = 1; 1776 redo_dma_risc = 1;
1849 if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf))) 1777 if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf)))
1850 goto fail; 1778 goto fail;
@@ -1854,7 +1782,7 @@ static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1854 if (0 != (rc = bttv_buffer_risc(btv,buf))) 1782 if (0 != (rc = bttv_buffer_risc(btv,buf)))
1855 goto fail; 1783 goto fail;
1856 1784
1857 buf->vb.state = STATE_PREPARED; 1785 buf->vb.state = VIDEOBUF_PREPARED;
1858 return 0; 1786 return 0;
1859 1787
1860 fail: 1788 fail:
@@ -1893,7 +1821,7 @@ buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
1893 struct bttv_fh *fh = q->priv_data; 1821 struct bttv_fh *fh = q->priv_data;
1894 struct bttv *btv = fh->btv; 1822 struct bttv *btv = fh->btv;
1895 1823
1896 buf->vb.state = STATE_QUEUED; 1824 buf->vb.state = VIDEOBUF_QUEUED;
1897 list_add_tail(&buf->vb.queue,&btv->capture); 1825 list_add_tail(&buf->vb.queue,&btv->capture);
1898 if (!btv->curr.frame_irq) { 1826 if (!btv->curr.frame_irq) {
1899 btv->loop_irq |= 1; 1827 btv->loop_irq |= 1;
@@ -1916,374 +1844,234 @@ static struct videobuf_queue_ops bttv_video_qops = {
1916 .buf_release = buffer_release, 1844 .buf_release = buffer_release,
1917}; 1845};
1918 1846
1919static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg) 1847static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id)
1920{ 1848{
1921 switch (cmd) { 1849 struct bttv_fh *fh = priv;
1922 case BTTV_VERSION: 1850 struct bttv *btv = fh->btv;
1923 return BTTV_VERSION_CODE; 1851 unsigned int i;
1852 int err;
1924 1853
1925 /* *** v4l1 *** ************************************************ */ 1854 err = v4l2_prio_check(&btv->prio, &fh->prio);
1926 case VIDIOCGFREQ: 1855 if (0 != err)
1927 { 1856 return err;
1928 unsigned long *freq = arg;
1929 *freq = btv->freq;
1930 return 0;
1931 }
1932 case VIDIOCSFREQ:
1933 {
1934 struct v4l2_frequency freq;
1935 1857
1936 memset(&freq, 0, sizeof(freq)); 1858 for (i = 0; i < BTTV_TVNORMS; i++)
1937 freq.frequency = *(unsigned long *)arg; 1859 if (*id & bttv_tvnorms[i].v4l2_id)
1938 mutex_lock(&btv->lock); 1860 break;
1939 freq.type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1861 if (i == BTTV_TVNORMS)
1940 btv->freq = *(unsigned long *)arg; 1862 return -EINVAL;
1941 bttv_call_i2c_clients(btv,VIDIOC_S_FREQUENCY,&freq);
1942 if (btv->has_matchbox && btv->radio_user)
1943 tea5757_set_freq(btv,*(unsigned long *)arg);
1944 mutex_unlock(&btv->lock);
1945 return 0;
1946 }
1947 1863
1948 case VIDIOCGTUNER: 1864 mutex_lock(&btv->lock);
1949 { 1865 set_tvnorm(btv, i);
1950 struct video_tuner *v = arg; 1866 mutex_unlock(&btv->lock);
1951 1867
1952 if (UNSET == bttv_tvcards[btv->c.type].tuner) 1868 return 0;
1953 return -EINVAL; 1869}
1954 if (v->tuner) /* Only tuner 0 */
1955 return -EINVAL;
1956 strcpy(v->name, "Television");
1957 v->rangelow = 0;
1958 v->rangehigh = 0x7FFFFFFF;
1959 v->flags = VIDEO_TUNER_PAL|VIDEO_TUNER_NTSC|VIDEO_TUNER_SECAM;
1960 v->mode = btv->tvnorm;
1961 v->signal = (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC) ? 0xFFFF : 0;
1962 bttv_call_i2c_clients(btv,cmd,v);
1963 return 0;
1964 }
1965 case VIDIOCSTUNER:
1966 {
1967 struct video_tuner *v = arg;
1968 1870
1969 if (v->tuner) /* Only tuner 0 */ 1871static int bttv_querystd(struct file *file, void *f, v4l2_std_id *id)
1970 return -EINVAL; 1872{
1971 if (v->mode >= BTTV_TVNORMS) 1873 struct bttv_fh *fh = f;
1972 return -EINVAL; 1874 struct bttv *btv = fh->btv;
1973 1875
1974 mutex_lock(&btv->lock); 1876 if (btread(BT848_DSTATUS) & BT848_DSTATUS_NUML)
1975 set_tvnorm(btv,v->mode); 1877 *id = V4L2_STD_625_50;
1976 bttv_call_i2c_clients(btv,cmd,v); 1878 else
1977 mutex_unlock(&btv->lock); 1879 *id = V4L2_STD_525_60;
1978 return 0; 1880 return 0;
1979 } 1881}
1980 1882
1981 case VIDIOCGCHAN: 1883static int bttv_enum_input(struct file *file, void *priv,
1982 { 1884 struct v4l2_input *i)
1983 struct video_channel *v = arg; 1885{
1984 unsigned int channel = v->channel; 1886 struct bttv_fh *fh = priv;
1887 struct bttv *btv = fh->btv;
1888 unsigned int n;
1985 1889
1986 if (channel >= bttv_tvcards[btv->c.type].video_inputs) 1890 n = i->index;
1987 return -EINVAL;
1988 v->tuners=0;
1989 v->flags = VIDEO_VC_AUDIO;
1990 v->type = VIDEO_TYPE_CAMERA;
1991 v->norm = btv->tvnorm;
1992 if (channel == bttv_tvcards[btv->c.type].tuner) {
1993 strcpy(v->name,"Television");
1994 v->flags|=VIDEO_VC_TUNER;
1995 v->type=VIDEO_TYPE_TV;
1996 v->tuners=1;
1997 } else if (channel == btv->svhs) {
1998 strcpy(v->name,"S-Video");
1999 } else {
2000 sprintf(v->name,"Composite%d",channel);
2001 }
2002 return 0;
2003 }
2004 case VIDIOCSCHAN:
2005 {
2006 struct video_channel *v = arg;
2007 unsigned int channel = v->channel;
2008 1891
2009 if (channel >= bttv_tvcards[btv->c.type].video_inputs) 1892 if (n >= bttv_tvcards[btv->c.type].video_inputs)
2010 return -EINVAL; 1893 return -EINVAL;
2011 if (v->norm >= BTTV_TVNORMS)
2012 return -EINVAL;
2013 1894
2014 mutex_lock(&btv->lock); 1895 memset(i, 0, sizeof(*i));
2015 if (channel == btv->input &&
2016 v->norm == btv->tvnorm) {
2017 /* nothing to do */
2018 mutex_unlock(&btv->lock);
2019 return 0;
2020 }
2021 1896
2022 set_input(btv, v->channel, v->norm); 1897 i->index = n;
2023 mutex_unlock(&btv->lock); 1898 i->type = V4L2_INPUT_TYPE_CAMERA;
2024 return 0; 1899 i->audioset = 1;
1900
1901 if (i->index == bttv_tvcards[btv->c.type].tuner) {
1902 sprintf(i->name, "Television");
1903 i->type = V4L2_INPUT_TYPE_TUNER;
1904 i->tuner = 0;
1905 } else if (i->index == btv->svhs) {
1906 sprintf(i->name, "S-Video");
1907 } else {
1908 sprintf(i->name, "Composite%d", i->index);
2025 } 1909 }
2026 1910
2027 case VIDIOCGAUDIO: 1911 if (i->index == btv->input) {
2028 { 1912 __u32 dstatus = btread(BT848_DSTATUS);
2029 struct video_audio *v = arg; 1913 if (0 == (dstatus & BT848_DSTATUS_PRES))
1914 i->status |= V4L2_IN_ST_NO_SIGNAL;
1915 if (0 == (dstatus & BT848_DSTATUS_HLOC))
1916 i->status |= V4L2_IN_ST_NO_H_LOCK;
1917 }
2030 1918
2031 memset(v,0,sizeof(*v)); 1919 for (n = 0; n < BTTV_TVNORMS; n++)
2032 strcpy(v->name,"Television"); 1920 i->std |= bttv_tvnorms[n].v4l2_id;
2033 v->flags |= VIDEO_AUDIO_MUTABLE;
2034 v->mode = VIDEO_SOUND_MONO;
2035 1921
2036 mutex_lock(&btv->lock); 1922 return 0;
2037 bttv_call_i2c_clients(btv,cmd,v); 1923}
2038 1924
2039 /* card specific hooks */ 1925static int bttv_g_input(struct file *file, void *priv, unsigned int *i)
2040 if (btv->audio_hook) 1926{
2041 btv->audio_hook(btv,v,0); 1927 struct bttv_fh *fh = priv;
1928 struct bttv *btv = fh->btv;
2042 1929
2043 mutex_unlock(&btv->lock); 1930 *i = btv->input;
2044 return 0; 1931 return 0;
2045 } 1932}
2046 case VIDIOCSAUDIO:
2047 {
2048 struct video_audio *v = arg;
2049 unsigned int audio = v->audio;
2050 1933
2051 if (audio >= bttv_tvcards[btv->c.type].audio_inputs) 1934static int bttv_s_input(struct file *file, void *priv, unsigned int i)
2052 return -EINVAL; 1935{
1936 struct bttv_fh *fh = priv;
1937 struct bttv *btv = fh->btv;
2053 1938
2054 mutex_lock(&btv->lock); 1939 int err;
2055 audio_mute(btv, (v->flags&VIDEO_AUDIO_MUTE) ? 1 : 0);
2056 bttv_call_i2c_clients(btv,cmd,v);
2057 1940
2058 /* card specific hooks */ 1941 err = v4l2_prio_check(&btv->prio, &fh->prio);
2059 if (btv->audio_hook) 1942 if (0 != err)
2060 btv->audio_hook(btv,v,1); 1943 return err;
2061 1944
2062 mutex_unlock(&btv->lock); 1945 if (i > bttv_tvcards[btv->c.type].video_inputs)
2063 return 0; 1946 return -EINVAL;
2064 }
2065 1947
2066 /* *** v4l2 *** ************************************************ */ 1948 mutex_lock(&btv->lock);
2067 case VIDIOC_ENUMSTD: 1949 set_input(btv, i, btv->tvnorm);
2068 { 1950 mutex_unlock(&btv->lock);
2069 struct v4l2_standard *e = arg; 1951 return 0;
2070 unsigned int index = e->index; 1952}
2071 1953
2072 if (index >= BTTV_TVNORMS) 1954static int bttv_s_tuner(struct file *file, void *priv,
2073 return -EINVAL; 1955 struct v4l2_tuner *t)
2074 v4l2_video_std_construct(e, bttv_tvnorms[e->index].v4l2_id, 1956{
2075 bttv_tvnorms[e->index].name); 1957 struct bttv_fh *fh = priv;
2076 e->index = index; 1958 struct bttv *btv = fh->btv;
2077 return 0; 1959 int err;
2078 }
2079 case VIDIOC_G_STD:
2080 {
2081 v4l2_std_id *id = arg;
2082 *id = bttv_tvnorms[btv->tvnorm].v4l2_id;
2083 return 0;
2084 }
2085 case VIDIOC_S_STD:
2086 {
2087 v4l2_std_id *id = arg;
2088 unsigned int i;
2089 1960
2090 for (i = 0; i < BTTV_TVNORMS; i++) 1961 err = v4l2_prio_check(&btv->prio, &fh->prio);
2091 if (*id & bttv_tvnorms[i].v4l2_id) 1962 if (0 != err)
2092 break; 1963 return err;
2093 if (i == BTTV_TVNORMS)
2094 return -EINVAL;
2095 1964
2096 mutex_lock(&btv->lock); 1965 if (UNSET == bttv_tvcards[btv->c.type].tuner)
2097 set_tvnorm(btv,i); 1966 return -EINVAL;
2098 i2c_vidiocschan(btv);
2099 mutex_unlock(&btv->lock);
2100 return 0;
2101 }
2102 case VIDIOC_QUERYSTD:
2103 {
2104 v4l2_std_id *id = arg;
2105 1967
2106 if (btread(BT848_DSTATUS) & BT848_DSTATUS_NUML) 1968 if (0 != t->index)
2107 *id = V4L2_STD_625_50; 1969 return -EINVAL;
2108 else
2109 *id = V4L2_STD_525_60;
2110 return 0;
2111 }
2112 1970
2113 case VIDIOC_ENUMINPUT: 1971 mutex_lock(&btv->lock);
2114 { 1972 bttv_call_i2c_clients(btv, VIDIOC_S_TUNER, t);
2115 struct v4l2_input *i = arg;
2116 unsigned int n;
2117 1973
2118 n = i->index; 1974 if (btv->audio_mode_gpio)
2119 if (n >= bttv_tvcards[btv->c.type].video_inputs) 1975 btv->audio_mode_gpio(btv, t, 1);
2120 return -EINVAL;
2121 memset(i,0,sizeof(*i));
2122 i->index = n;
2123 i->type = V4L2_INPUT_TYPE_CAMERA;
2124 i->audioset = 1;
2125 if (i->index == bttv_tvcards[btv->c.type].tuner) {
2126 sprintf(i->name, "Television");
2127 i->type = V4L2_INPUT_TYPE_TUNER;
2128 i->tuner = 0;
2129 } else if (i->index == btv->svhs) {
2130 sprintf(i->name, "S-Video");
2131 } else {
2132 sprintf(i->name,"Composite%d",i->index);
2133 }
2134 if (i->index == btv->input) {
2135 __u32 dstatus = btread(BT848_DSTATUS);
2136 if (0 == (dstatus & BT848_DSTATUS_PRES))
2137 i->status |= V4L2_IN_ST_NO_SIGNAL;
2138 if (0 == (dstatus & BT848_DSTATUS_HLOC))
2139 i->status |= V4L2_IN_ST_NO_H_LOCK;
2140 }
2141 for (n = 0; n < BTTV_TVNORMS; n++)
2142 i->std |= bttv_tvnorms[n].v4l2_id;
2143 return 0;
2144 }
2145 case VIDIOC_G_INPUT:
2146 {
2147 int *i = arg;
2148 *i = btv->input;
2149 return 0;
2150 }
2151 case VIDIOC_S_INPUT:
2152 {
2153 unsigned int *i = arg;
2154 1976
2155 if (*i > bttv_tvcards[btv->c.type].video_inputs) 1977 mutex_unlock(&btv->lock);
2156 return -EINVAL;
2157 mutex_lock(&btv->lock);
2158 set_input(btv, *i, btv->tvnorm);
2159 mutex_unlock(&btv->lock);
2160 return 0;
2161 }
2162 1978
2163 case VIDIOC_G_TUNER: 1979 return 0;
2164 { 1980}
2165 struct v4l2_tuner *t = arg;
2166 1981
2167 if (UNSET == bttv_tvcards[btv->c.type].tuner) 1982static int bttv_g_frequency(struct file *file, void *priv,
2168 return -EINVAL; 1983 struct v4l2_frequency *f)
2169 if (0 != t->index) 1984{
2170 return -EINVAL; 1985 struct bttv_fh *fh = priv;
2171 mutex_lock(&btv->lock); 1986 struct bttv *btv = fh->btv;
2172 memset(t,0,sizeof(*t)); 1987 int err;
2173 t->rxsubchans = V4L2_TUNER_SUB_MONO;
2174 bttv_call_i2c_clients(btv, VIDIOC_G_TUNER, t);
2175 strcpy(t->name, "Television");
2176 t->capability = V4L2_TUNER_CAP_NORM;
2177 t->type = V4L2_TUNER_ANALOG_TV;
2178 if (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC)
2179 t->signal = 0xffff;
2180
2181 if (btv->audio_hook) {
2182 /* Hmmm ... */
2183 struct video_audio va;
2184 memset(&va, 0, sizeof(struct video_audio));
2185 btv->audio_hook(btv,&va,0);
2186 t->audmode = V4L2_TUNER_MODE_MONO;
2187 t->rxsubchans = V4L2_TUNER_SUB_MONO;
2188 if(va.mode & VIDEO_SOUND_STEREO) {
2189 t->audmode = V4L2_TUNER_MODE_STEREO;
2190 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
2191 }
2192 if(va.mode & VIDEO_SOUND_LANG2) {
2193 t->audmode = V4L2_TUNER_MODE_LANG1;
2194 t->rxsubchans = V4L2_TUNER_SUB_LANG1
2195 | V4L2_TUNER_SUB_LANG2;
2196 }
2197 }
2198 /* FIXME: fill capability+audmode */
2199 mutex_unlock(&btv->lock);
2200 return 0;
2201 }
2202 case VIDIOC_S_TUNER:
2203 {
2204 struct v4l2_tuner *t = arg;
2205 1988
2206 if (UNSET == bttv_tvcards[btv->c.type].tuner) 1989 err = v4l2_prio_check(&btv->prio, &fh->prio);
2207 return -EINVAL; 1990 if (0 != err)
2208 if (0 != t->index) 1991 return err;
2209 return -EINVAL;
2210 mutex_lock(&btv->lock);
2211 bttv_call_i2c_clients(btv, VIDIOC_S_TUNER, t);
2212 if (btv->audio_hook) {
2213 struct video_audio va;
2214 memset(&va, 0, sizeof(struct video_audio));
2215 if (t->audmode == V4L2_TUNER_MODE_MONO)
2216 va.mode = VIDEO_SOUND_MONO;
2217 else if (t->audmode == V4L2_TUNER_MODE_STEREO ||
2218 t->audmode == V4L2_TUNER_MODE_LANG1_LANG2)
2219 va.mode = VIDEO_SOUND_STEREO;
2220 else if (t->audmode == V4L2_TUNER_MODE_LANG1)
2221 va.mode = VIDEO_SOUND_LANG1;
2222 else if (t->audmode == V4L2_TUNER_MODE_LANG2)
2223 va.mode = VIDEO_SOUND_LANG2;
2224 btv->audio_hook(btv,&va,1);
2225 }
2226 mutex_unlock(&btv->lock);
2227 return 0;
2228 }
2229 1992
2230 case VIDIOC_G_FREQUENCY: 1993 f->type = V4L2_TUNER_ANALOG_TV;
2231 { 1994 f->frequency = btv->freq;
2232 struct v4l2_frequency *f = arg;
2233 1995
2234 memset(f,0,sizeof(*f)); 1996 return 0;
2235 f->type = V4L2_TUNER_ANALOG_TV; 1997}
2236 f->frequency = btv->freq; 1998
2237 return 0; 1999static int bttv_s_frequency(struct file *file, void *priv,
2238 } 2000 struct v4l2_frequency *f)
2239 case VIDIOC_S_FREQUENCY: 2001{
2240 { 2002 struct bttv_fh *fh = priv;
2241 struct v4l2_frequency *f = arg; 2003 struct bttv *btv = fh->btv;
2004 int err;
2005
2006 err = v4l2_prio_check(&btv->prio, &fh->prio);
2007 if (0 != err)
2008 return err;
2009
2010 if (unlikely(f->tuner != 0))
2011 return -EINVAL;
2012 if (unlikely(f->type != V4L2_TUNER_ANALOG_TV))
2013 return -EINVAL;
2014 mutex_lock(&btv->lock);
2015 btv->freq = f->frequency;
2016 bttv_call_i2c_clients(btv, VIDIOC_S_FREQUENCY, f);
2017 if (btv->has_matchbox && btv->radio_user)
2018 tea5757_set_freq(btv, btv->freq);
2019 mutex_unlock(&btv->lock);
2020 return 0;
2021}
2022
2023static int bttv_log_status(struct file *file, void *f)
2024{
2025 struct bttv_fh *fh = f;
2026 struct bttv *btv = fh->btv;
2027
2028 printk(KERN_INFO "bttv%d: ======== START STATUS CARD #%d ========\n",
2029 btv->c.nr, btv->c.nr);
2030 bttv_call_i2c_clients(btv, VIDIOC_LOG_STATUS, NULL);
2031 printk(KERN_INFO "bttv%d: ======== END STATUS CARD #%d ========\n",
2032 btv->c.nr, btv->c.nr);
2033 return 0;
2034}
2242 2035
2243 if (unlikely(f->tuner != 0))
2244 return -EINVAL;
2245 if (unlikely (f->type != V4L2_TUNER_ANALOG_TV))
2246 return -EINVAL;
2247 mutex_lock(&btv->lock);
2248 btv->freq = f->frequency;
2249 bttv_call_i2c_clients(btv,VIDIOC_S_FREQUENCY,f);
2250 if (btv->has_matchbox && btv->radio_user)
2251 tea5757_set_freq(btv,btv->freq);
2252 mutex_unlock(&btv->lock);
2253 return 0;
2254 }
2255 case VIDIOC_LOG_STATUS:
2256 {
2257 printk(KERN_INFO "bttv%d: ================= START STATUS CARD #%d =================\n", btv->c.nr, btv->c.nr);
2258 bttv_call_i2c_clients(btv, VIDIOC_LOG_STATUS, NULL);
2259 printk(KERN_INFO "bttv%d: ================== END STATUS CARD #%d ==================\n", btv->c.nr, btv->c.nr);
2260 return 0;
2261 }
2262#ifdef CONFIG_VIDEO_ADV_DEBUG 2036#ifdef CONFIG_VIDEO_ADV_DEBUG
2263 case VIDIOC_DBG_G_REGISTER: 2037static int bttv_g_register(struct file *file, void *f,
2264 case VIDIOC_DBG_S_REGISTER: 2038 struct v4l2_register *reg)
2265 { 2039{
2266 struct v4l2_register *reg = arg; 2040 struct bttv_fh *fh = f;
2267 if (!capable(CAP_SYS_ADMIN)) 2041 struct bttv *btv = fh->btv;
2268 return -EPERM;
2269 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
2270 return -EINVAL;
2271 /* bt848 has a 12-bit register space */
2272 reg->reg &= 0xfff;
2273 if (cmd == VIDIOC_DBG_G_REGISTER)
2274 reg->val = btread(reg->reg);
2275 else
2276 btwrite(reg->val, reg->reg);
2277 return 0;
2278 }
2279#endif
2280 2042
2281 default: 2043 if (!capable(CAP_SYS_ADMIN))
2282 return -ENOIOCTLCMD; 2044 return -EPERM;
2045
2046 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
2047 return -EINVAL;
2048
2049 /* bt848 has a 12-bit register space */
2050 reg->reg &= 0xfff;
2051 reg->val = btread(reg->reg);
2052
2053 return 0;
2054}
2055
2056static int bttv_s_register(struct file *file, void *f,
2057 struct v4l2_register *reg)
2058{
2059 struct bttv_fh *fh = f;
2060 struct bttv *btv = fh->btv;
2061
2062 if (!capable(CAP_SYS_ADMIN))
2063 return -EPERM;
2064
2065 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
2066 return -EINVAL;
2067
2068 /* bt848 has a 12-bit register space */
2069 reg->reg &= 0xfff;
2070 btwrite(reg->val, reg->reg);
2283 2071
2284 }
2285 return 0; 2072 return 0;
2286} 2073}
2074#endif
2287 2075
2288/* Given cropping boundaries b and the scaled width and height of a 2076/* Given cropping boundaries b and the scaled width and height of a
2289 single field or frame, which must not exceed hardware limits, this 2077 single field or frame, which must not exceed hardware limits, this
@@ -2659,983 +2447,681 @@ pix_format_set_size (struct v4l2_pix_format * f,
2659 } 2447 }
2660} 2448}
2661 2449
2662static int bttv_g_fmt(struct bttv_fh *fh, struct v4l2_format *f) 2450static int bttv_g_fmt_cap(struct file *file, void *priv,
2451 struct v4l2_format *f)
2663{ 2452{
2664 switch (f->type) { 2453 struct bttv_fh *fh = priv;
2665 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 2454
2666 memset(&f->fmt.pix,0,sizeof(struct v4l2_pix_format)); 2455 pix_format_set_size(&f->fmt.pix, fh->fmt,
2667 pix_format_set_size (&f->fmt.pix, fh->fmt, 2456 fh->width, fh->height);
2668 fh->width, fh->height); 2457 f->fmt.pix.field = fh->cap.field;
2669 f->fmt.pix.field = fh->cap.field; 2458 f->fmt.pix.pixelformat = fh->fmt->fourcc;
2670 f->fmt.pix.pixelformat = fh->fmt->fourcc; 2459
2671 return 0; 2460 return 0;
2672 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2673 memset(&f->fmt.win,0,sizeof(struct v4l2_window));
2674 f->fmt.win.w = fh->ov.w;
2675 f->fmt.win.field = fh->ov.field;
2676 return 0;
2677 case V4L2_BUF_TYPE_VBI_CAPTURE:
2678 bttv_vbi_get_fmt(fh, &f->fmt.vbi);
2679 return 0;
2680 default:
2681 return -EINVAL;
2682 }
2683} 2461}
2684 2462
2685static int bttv_try_fmt(struct bttv_fh *fh, struct bttv *btv, 2463static int bttv_g_fmt_overlay(struct file *file, void *priv,
2686 struct v4l2_format *f, int adjust_crop) 2464 struct v4l2_format *f)
2687{ 2465{
2688 switch (f->type) { 2466 struct bttv_fh *fh = priv;
2689 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2690 {
2691 const struct bttv_format *fmt;
2692 enum v4l2_field field;
2693 __s32 width, height;
2694 int rc;
2695 2467
2696 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 2468 f->fmt.win.w = fh->ov.w;
2697 if (NULL == fmt) 2469 f->fmt.win.field = fh->ov.field;
2698 return -EINVAL;
2699 2470
2700 field = f->fmt.pix.field; 2471 return 0;
2701 if (V4L2_FIELD_ANY == field) { 2472}
2702 __s32 height2;
2703 2473
2704 height2 = btv->crop[!!fh->do_crop].rect.height >> 1; 2474static int bttv_try_fmt_cap(struct file *file, void *priv,
2705 field = (f->fmt.pix.height > height2) 2475 struct v4l2_format *f)
2706 ? V4L2_FIELD_INTERLACED 2476{
2707 : V4L2_FIELD_BOTTOM; 2477 const struct bttv_format *fmt;
2708 } 2478 struct bttv_fh *fh = priv;
2709 if (V4L2_FIELD_SEQ_BT == field) 2479 struct bttv *btv = fh->btv;
2710 field = V4L2_FIELD_SEQ_TB; 2480 enum v4l2_field field;
2711 switch (field) { 2481 __s32 width, height;
2712 case V4L2_FIELD_TOP: 2482 int rc;
2713 case V4L2_FIELD_BOTTOM:
2714 case V4L2_FIELD_ALTERNATE:
2715 case V4L2_FIELD_INTERLACED:
2716 break;
2717 case V4L2_FIELD_SEQ_TB:
2718 if (fmt->flags & FORMAT_FLAGS_PLANAR)
2719 return -EINVAL;
2720 break;
2721 default:
2722 return -EINVAL;
2723 }
2724 2483
2725 width = f->fmt.pix.width; 2484 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
2726 height = f->fmt.pix.height; 2485 if (NULL == fmt)
2486 return -EINVAL;
2727 2487
2728 rc = limit_scaled_size(fh, &width, &height, field, 2488 field = f->fmt.pix.field;
2729 /* width_mask: 4 pixels */ ~3,
2730 /* width_bias: nearest */ 2,
2731 /* adjust_size */ 1,
2732 adjust_crop);
2733 if (0 != rc)
2734 return rc;
2735 2489
2736 /* update data for the application */ 2490 if (V4L2_FIELD_ANY == field) {
2737 f->fmt.pix.field = field; 2491 __s32 height2;
2738 pix_format_set_size(&f->fmt.pix, fmt, width, height);
2739 2492
2740 return 0; 2493 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2494 field = (f->fmt.pix.height > height2)
2495 ? V4L2_FIELD_INTERLACED
2496 : V4L2_FIELD_BOTTOM;
2741 } 2497 }
2742 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 2498
2743 return verify_window(fh, &f->fmt.win, 2499 if (V4L2_FIELD_SEQ_BT == field)
2744 /* adjust_size */ 1, 2500 field = V4L2_FIELD_SEQ_TB;
2745 /* adjust_crop */ 0); 2501
2746 case V4L2_BUF_TYPE_VBI_CAPTURE: 2502 switch (field) {
2747 return bttv_vbi_try_fmt(fh, &f->fmt.vbi); 2503 case V4L2_FIELD_TOP:
2504 case V4L2_FIELD_BOTTOM:
2505 case V4L2_FIELD_ALTERNATE:
2506 case V4L2_FIELD_INTERLACED:
2507 break;
2508 case V4L2_FIELD_SEQ_TB:
2509 if (fmt->flags & FORMAT_FLAGS_PLANAR)
2510 return -EINVAL;
2511 break;
2748 default: 2512 default:
2749 return -EINVAL; 2513 return -EINVAL;
2750 } 2514 }
2515
2516 width = f->fmt.pix.width;
2517 height = f->fmt.pix.height;
2518
2519 rc = limit_scaled_size(fh, &width, &height, field,
2520 /* width_mask: 4 pixels */ ~3,
2521 /* width_bias: nearest */ 2,
2522 /* adjust_size */ 1,
2523 /* adjust_crop */ 0);
2524 if (0 != rc)
2525 return rc;
2526
2527 /* update data for the application */
2528 f->fmt.pix.field = field;
2529 pix_format_set_size(&f->fmt.pix, fmt, width, height);
2530
2531 return 0;
2751} 2532}
2752 2533
2753static int bttv_s_fmt(struct bttv_fh *fh, struct bttv *btv, 2534static int bttv_try_fmt_overlay(struct file *file, void *priv,
2754 struct v4l2_format *f) 2535 struct v4l2_format *f)
2536{
2537 struct bttv_fh *fh = priv;
2538
2539 return verify_window(fh, &f->fmt.win,
2540 /* adjust_size */ 1,
2541 /* adjust_crop */ 0);
2542}
2543
2544static int bttv_s_fmt_cap(struct file *file, void *priv,
2545 struct v4l2_format *f)
2755{ 2546{
2756 int retval; 2547 int retval;
2548 const struct bttv_format *fmt;
2549 struct bttv_fh *fh = priv;
2550 struct bttv *btv = fh->btv;
2551 __s32 width, height;
2552 enum v4l2_field field;
2757 2553
2758 switch (f->type) { 2554 retval = bttv_switch_type(fh, f->type);
2759 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 2555 if (0 != retval)
2760 { 2556 return retval;
2761 const struct bttv_format *fmt;
2762 2557
2763 retval = bttv_switch_type(fh,f->type); 2558 retval = bttv_try_fmt_cap(file, priv, f);
2764 if (0 != retval) 2559 if (0 != retval)
2765 return retval; 2560 return retval;
2766 retval = bttv_try_fmt(fh,btv,f, /* adjust_crop */ 1);
2767 if (0 != retval)
2768 return retval;
2769 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
2770 2561
2771 /* update our state informations */ 2562 width = f->fmt.pix.width;
2772 mutex_lock(&fh->cap.lock); 2563 height = f->fmt.pix.height;
2773 fh->fmt = fmt; 2564 field = f->fmt.pix.field;
2774 fh->cap.field = f->fmt.pix.field;
2775 fh->cap.last = V4L2_FIELD_NONE;
2776 fh->width = f->fmt.pix.width;
2777 fh->height = f->fmt.pix.height;
2778 btv->init.fmt = fmt;
2779 btv->init.width = f->fmt.pix.width;
2780 btv->init.height = f->fmt.pix.height;
2781 mutex_unlock(&fh->cap.lock);
2782 2565
2783 return 0; 2566 retval = limit_scaled_size(fh, &width, &height, f->fmt.pix.field,
2784 } 2567 /* width_mask: 4 pixels */ ~3,
2785 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 2568 /* width_bias: nearest */ 2,
2786 if (no_overlay > 0) { 2569 /* adjust_size */ 1,
2787 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); 2570 /* adjust_crop */ 1);
2788 return -EINVAL; 2571 if (0 != retval)
2789 } 2572 return retval;
2790 return setup_window(fh, btv, &f->fmt.win, 1);
2791 case V4L2_BUF_TYPE_VBI_CAPTURE:
2792 retval = bttv_switch_type(fh,f->type);
2793 if (0 != retval)
2794 return retval;
2795 return bttv_vbi_set_fmt(fh, &f->fmt.vbi);
2796 default:
2797 return -EINVAL;
2798 }
2799}
2800 2573
2801static int bttv_do_ioctl(struct inode *inode, struct file *file, 2574 f->fmt.pix.field = field;
2802 unsigned int cmd, void *arg)
2803{
2804 struct bttv_fh *fh = file->private_data;
2805 struct bttv *btv = fh->btv;
2806 unsigned long flags;
2807 int retval = 0;
2808 2575
2809 if (bttv_debug > 1) 2576 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
2810 v4l_print_ioctl(btv->c.name, cmd);
2811
2812 if (btv->errors)
2813 bttv_reinit_bt848(btv);
2814
2815 switch (cmd) {
2816 case VIDIOCSFREQ:
2817 case VIDIOCSTUNER:
2818 case VIDIOCSCHAN:
2819 case VIDIOC_S_CTRL:
2820 case VIDIOC_S_STD:
2821 case VIDIOC_S_INPUT:
2822 case VIDIOC_S_TUNER:
2823 case VIDIOC_S_FREQUENCY:
2824 retval = v4l2_prio_check(&btv->prio,&fh->prio);
2825 if (0 != retval)
2826 return retval;
2827 };
2828 2577
2829 switch (cmd) { 2578 /* update our state informations */
2579 mutex_lock(&fh->cap.lock);
2580 fh->fmt = fmt;
2581 fh->cap.field = f->fmt.pix.field;
2582 fh->cap.last = V4L2_FIELD_NONE;
2583 fh->width = f->fmt.pix.width;
2584 fh->height = f->fmt.pix.height;
2585 btv->init.fmt = fmt;
2586 btv->init.width = f->fmt.pix.width;
2587 btv->init.height = f->fmt.pix.height;
2588 mutex_unlock(&fh->cap.lock);
2830 2589
2831 /* *** v4l1 *** ************************************************ */ 2590 return 0;
2832 case VIDIOCGCAP: 2591}
2833 {
2834 struct video_capability *cap = arg;
2835 2592
2836 memset(cap,0,sizeof(*cap)); 2593static int bttv_s_fmt_overlay(struct file *file, void *priv,
2837 strcpy(cap->name,btv->video_dev->name); 2594 struct v4l2_format *f)
2838 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { 2595{
2839 /* vbi */ 2596 struct bttv_fh *fh = priv;
2840 cap->type = VID_TYPE_TUNER|VID_TYPE_TELETEXT; 2597 struct bttv *btv = fh->btv;
2841 } else {
2842 /* others */
2843 cap->type = VID_TYPE_CAPTURE|
2844 VID_TYPE_TUNER|
2845 VID_TYPE_CLIPPING|
2846 VID_TYPE_SCALES;
2847 if (no_overlay <= 0)
2848 cap->type |= VID_TYPE_OVERLAY;
2849
2850 cap->maxwidth = bttv_tvnorms[btv->tvnorm].swidth;
2851 cap->maxheight = bttv_tvnorms[btv->tvnorm].sheight;
2852 cap->minwidth = 48;
2853 cap->minheight = 32;
2854 }
2855 cap->channels = bttv_tvcards[btv->c.type].video_inputs;
2856 cap->audios = bttv_tvcards[btv->c.type].audio_inputs;
2857 return 0;
2858 }
2859 2598
2860 case VIDIOCGPICT: 2599 if (no_overlay > 0) {
2861 { 2600 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
2862 struct video_picture *pic = arg; 2601 return -EINVAL;
2863
2864 memset(pic,0,sizeof(*pic));
2865 pic->brightness = btv->bright;
2866 pic->contrast = btv->contrast;
2867 pic->hue = btv->hue;
2868 pic->colour = btv->saturation;
2869 if (fh->fmt) {
2870 pic->depth = fh->fmt->depth;
2871 pic->palette = fh->fmt->palette;
2872 }
2873 return 0;
2874 } 2602 }
2875 case VIDIOCSPICT:
2876 {
2877 struct video_picture *pic = arg;
2878 const struct bttv_format *fmt;
2879 2603
2880 fmt = format_by_palette(pic->palette); 2604 return setup_window(fh, btv, &f->fmt.win, 1);
2881 if (NULL == fmt) 2605}
2882 return -EINVAL; 2606
2883 mutex_lock(&fh->cap.lock); 2607#ifdef CONFIG_VIDEO_V4L1_COMPAT
2884 if (fmt->flags & FORMAT_FLAGS_RAW) { 2608static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
2885 /* VIDIOCMCAPTURE uses gbufsize, not RAW_BPL * 2609{
2886 RAW_LINES * 2. F1 is stored at offset 0, F2 2610 int retval;
2887 at buffer size / 2. */ 2611 unsigned int i;
2888 fh->width = RAW_BPL; 2612 struct bttv_fh *fh = priv;
2889 fh->height = gbufsize / RAW_BPL; 2613
2890 btv->init.width = RAW_BPL; 2614 mutex_lock(&fh->cap.lock);
2891 btv->init.height = gbufsize / RAW_BPL; 2615 retval = videobuf_mmap_setup(&fh->cap, gbuffers, gbufsize,
2892 } 2616 V4L2_MEMORY_MMAP);
2893 fh->ovfmt = fmt; 2617 if (retval < 0) {
2894 fh->fmt = fmt;
2895 btv->init.ovfmt = fmt;
2896 btv->init.fmt = fmt;
2897 if (bigendian) {
2898 /* dirty hack time: swap bytes for overlay if the
2899 display adaptor is big endian (insmod option) */
2900 if (fmt->palette == VIDEO_PALETTE_RGB555 ||
2901 fmt->palette == VIDEO_PALETTE_RGB565 ||
2902 fmt->palette == VIDEO_PALETTE_RGB32) {
2903 fh->ovfmt = fmt+1;
2904 }
2905 }
2906 bt848_bright(btv,pic->brightness);
2907 bt848_contrast(btv,pic->contrast);
2908 bt848_hue(btv,pic->hue);
2909 bt848_sat(btv,pic->colour);
2910 mutex_unlock(&fh->cap.lock); 2618 mutex_unlock(&fh->cap.lock);
2911 return 0; 2619 return retval;
2912 } 2620 }
2913 2621
2914 case VIDIOCGWIN: 2622 gbuffers = retval;
2915 { 2623 memset(mbuf, 0, sizeof(*mbuf));
2916 struct video_window *win = arg; 2624 mbuf->frames = gbuffers;
2625 mbuf->size = gbuffers * gbufsize;
2917 2626
2918 memset(win,0,sizeof(*win)); 2627 for (i = 0; i < gbuffers; i++)
2919 win->x = fh->ov.w.left; 2628 mbuf->offsets[i] = i * gbufsize;
2920 win->y = fh->ov.w.top;
2921 win->width = fh->ov.w.width;
2922 win->height = fh->ov.w.height;
2923 return 0;
2924 }
2925 case VIDIOCSWIN:
2926 {
2927 struct video_window *win = arg;
2928 struct v4l2_window w2;
2929 2629
2930 if (no_overlay > 0) { 2630 mutex_unlock(&fh->cap.lock);
2931 printk ("VIDIOCSWIN: no_overlay\n"); 2631 return 0;
2932 return -EINVAL; 2632}
2933 } 2633#endif
2934 2634
2935 w2.field = V4L2_FIELD_ANY; 2635static int bttv_querycap(struct file *file, void *priv,
2936 w2.w.left = win->x; 2636 struct v4l2_capability *cap)
2937 w2.w.top = win->y; 2637{
2938 w2.w.width = win->width; 2638 struct bttv_fh *fh = priv;
2939 w2.w.height = win->height; 2639 struct bttv *btv = fh->btv;
2940 w2.clipcount = win->clipcount;
2941 w2.clips = (struct v4l2_clip __user *)win->clips;
2942 retval = setup_window(fh, btv, &w2, 0);
2943 if (0 == retval) {
2944 /* on v4l1 this ioctl affects the read() size too */
2945 fh->width = fh->ov.w.width;
2946 fh->height = fh->ov.w.height;
2947 btv->init.width = fh->ov.w.width;
2948 btv->init.height = fh->ov.w.height;
2949 }
2950 return retval;
2951 }
2952 2640
2953 case VIDIOCGFBUF: 2641 if (0 == v4l2)
2954 { 2642 return -EINVAL;
2955 struct video_buffer *fbuf = arg;
2956
2957 fbuf->base = btv->fbuf.base;
2958 fbuf->width = btv->fbuf.fmt.width;
2959 fbuf->height = btv->fbuf.fmt.height;
2960 fbuf->bytesperline = btv->fbuf.fmt.bytesperline;
2961 if (fh->ovfmt)
2962 fbuf->depth = fh->ovfmt->depth;
2963 else {
2964 if (fbuf->width)
2965 fbuf->depth = ((fbuf->bytesperline<<3)
2966 + (fbuf->width-1) )
2967 /fbuf->width;
2968 else
2969 fbuf->depth = 0;
2970 }
2971 return 0;
2972 }
2973 case VIDIOCSFBUF:
2974 {
2975 struct video_buffer *fbuf = arg;
2976 const struct bttv_format *fmt;
2977 unsigned long end;
2978
2979 if(!capable(CAP_SYS_ADMIN) &&
2980 !capable(CAP_SYS_RAWIO))
2981 return -EPERM;
2982 end = (unsigned long)fbuf->base +
2983 fbuf->height * fbuf->bytesperline;
2984 mutex_lock(&fh->cap.lock);
2985 retval = -EINVAL;
2986 2643
2987 switch (fbuf->depth) { 2644 strlcpy(cap->driver, "bttv", sizeof(cap->driver));
2988 case 8: 2645 strlcpy(cap->card, btv->video_dev->name, sizeof(cap->card));
2989 fmt = format_by_palette(VIDEO_PALETTE_HI240); 2646 snprintf(cap->bus_info, sizeof(cap->bus_info),
2990 break; 2647 "PCI:%s", pci_name(btv->c.pci));
2991 case 16: 2648 cap->version = BTTV_VERSION_CODE;
2992 fmt = format_by_palette(VIDEO_PALETTE_RGB565); 2649 cap->capabilities =
2993 break; 2650 V4L2_CAP_VIDEO_CAPTURE |
2994 case 24: 2651 V4L2_CAP_VBI_CAPTURE |
2995 fmt = format_by_palette(VIDEO_PALETTE_RGB24); 2652 V4L2_CAP_READWRITE |
2996 break; 2653 V4L2_CAP_STREAMING;
2997 case 32: 2654 if (no_overlay <= 0)
2998 fmt = format_by_palette(VIDEO_PALETTE_RGB32); 2655 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
2999 break; 2656
3000 case 15: 2657 if (bttv_tvcards[btv->c.type].tuner != UNSET &&
3001 fbuf->depth = 16; 2658 bttv_tvcards[btv->c.type].tuner != TUNER_ABSENT)
3002 fmt = format_by_palette(VIDEO_PALETTE_RGB555); 2659 cap->capabilities |= V4L2_CAP_TUNER;
3003 break; 2660 return 0;
3004 default: 2661}
3005 fmt = NULL;
3006 break;
3007 }
3008 if (NULL == fmt)
3009 goto fh_unlock_and_return;
3010
3011 fh->ovfmt = fmt;
3012 fh->fmt = fmt;
3013 btv->init.ovfmt = fmt;
3014 btv->init.fmt = fmt;
3015 btv->fbuf.base = fbuf->base;
3016 btv->fbuf.fmt.width = fbuf->width;
3017 btv->fbuf.fmt.height = fbuf->height;
3018 if (fbuf->bytesperline)
3019 btv->fbuf.fmt.bytesperline = fbuf->bytesperline;
3020 else
3021 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fbuf->depth/8;
3022 mutex_unlock(&fh->cap.lock);
3023 return 0;
3024 }
3025 2662
3026 case VIDIOCCAPTURE: 2663static int bttv_enum_fmt_vbi(struct file *file, void *priv,
3027 case VIDIOC_OVERLAY: 2664 struct v4l2_fmtdesc *f)
3028 { 2665{
3029 struct bttv_buffer *new; 2666 if (0 != f->index)
3030 int *on = arg; 2667 return -EINVAL;
3031 2668
3032 if (*on) { 2669 f->pixelformat = V4L2_PIX_FMT_GREY;
3033 /* verify args */ 2670 strcpy(f->description, "vbi data");
3034 if (NULL == btv->fbuf.base)
3035 return -EINVAL;
3036 if (!fh->ov.setup_ok) {
3037 dprintk("bttv%d: overlay: !setup_ok\n",btv->c.nr);
3038 return -EINVAL;
3039 }
3040 }
3041 2671
3042 if (!check_alloc_btres(btv,fh,RESOURCE_OVERLAY)) 2672 return 0;
3043 return -EBUSY; 2673}
3044 2674
3045 mutex_lock(&fh->cap.lock); 2675static int bttv_enum_fmt_cap_ovr(struct v4l2_fmtdesc *f)
3046 if (*on) { 2676{
3047 fh->ov.tvnorm = btv->tvnorm; 2677 int index = -1, i;
3048 new = videobuf_pci_alloc(sizeof(*new));
3049 new->crop = btv->crop[!!fh->do_crop].rect;
3050 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
3051 } else {
3052 new = NULL;
3053 }
3054 2678
3055 /* switch over */ 2679 for (i = 0; i < FORMATS; i++) {
3056 retval = bttv_switch_overlay(btv,fh,new); 2680 if (formats[i].fourcc != -1)
3057 mutex_unlock(&fh->cap.lock); 2681 index++;
3058 return retval; 2682 if ((unsigned int)index == f->index)
2683 break;
3059 } 2684 }
2685 if (FORMATS == i)
2686 return -EINVAL;
3060 2687
3061 case VIDIOCGMBUF: 2688 f->pixelformat = formats[i].fourcc;
3062 { 2689 strlcpy(f->description, formats[i].name, sizeof(f->description));
3063 struct video_mbuf *mbuf = arg;
3064 unsigned int i;
3065 2690
3066 retval = videobuf_mmap_setup(&fh->cap,gbuffers,gbufsize, 2691 return i;
3067 V4L2_MEMORY_MMAP); 2692}
3068 if (retval < 0)
3069 return retval;
3070 2693
3071 gbuffers = retval; 2694static int bttv_enum_fmt_cap(struct file *file, void *priv,
3072 memset(mbuf,0,sizeof(*mbuf)); 2695 struct v4l2_fmtdesc *f)
3073 mbuf->frames = gbuffers; 2696{
3074 mbuf->size = gbuffers * gbufsize; 2697 int rc = bttv_enum_fmt_cap_ovr(f);
3075 for (i = 0; i < gbuffers; i++)
3076 mbuf->offsets[i] = i * gbufsize;
3077 return 0;
3078 }
3079 case VIDIOCMCAPTURE:
3080 {
3081 struct video_mmap *vm = arg;
3082 struct bttv_buffer *buf;
3083 enum v4l2_field field;
3084 __s32 height2;
3085 int res;
3086 2698
3087 if (vm->frame >= VIDEO_MAX_FRAME) 2699 if (rc < 0)
3088 return -EINVAL; 2700 return rc;
3089 2701
3090 res = bttv_resource(fh); 2702 return 0;
3091 if (!check_alloc_btres(btv, fh, res)) 2703}
3092 return -EBUSY;
3093 2704
3094 mutex_lock(&fh->cap.lock); 2705static int bttv_enum_fmt_overlay(struct file *file, void *priv,
3095 retval = -EINVAL; 2706 struct v4l2_fmtdesc *f)
3096 buf = (struct bttv_buffer *)fh->cap.bufs[vm->frame]; 2707{
3097 if (NULL == buf) 2708 int rc;
3098 goto fh_unlock_and_return;
3099 if (0 == buf->vb.baddr)
3100 goto fh_unlock_and_return;
3101 if (buf->vb.state == STATE_QUEUED ||
3102 buf->vb.state == STATE_ACTIVE)
3103 goto fh_unlock_and_return;
3104 2709
3105 height2 = btv->crop[!!fh->do_crop].rect.height >> 1; 2710 if (no_overlay > 0) {
3106 field = (vm->height > height2) 2711 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
3107 ? V4L2_FIELD_INTERLACED 2712 return -EINVAL;
3108 : V4L2_FIELD_BOTTOM;
3109 retval = bttv_prepare_buffer(&fh->cap,btv,buf,
3110 format_by_palette(vm->format),
3111 vm->width,vm->height,field);
3112 if (0 != retval)
3113 goto fh_unlock_and_return;
3114 btv->init.width = vm->width;
3115 btv->init.height = vm->height;
3116 spin_lock_irqsave(&btv->s_lock,flags);
3117 buffer_queue(&fh->cap,&buf->vb);
3118 spin_unlock_irqrestore(&btv->s_lock,flags);
3119 mutex_unlock(&fh->cap.lock);
3120 return 0;
3121 } 2713 }
3122 case VIDIOCSYNC:
3123 {
3124 int *frame = arg;
3125 struct bttv_buffer *buf;
3126 2714
3127 if (*frame >= VIDEO_MAX_FRAME) 2715 rc = bttv_enum_fmt_cap_ovr(f);
3128 return -EINVAL;
3129 2716
3130 mutex_lock(&fh->cap.lock); 2717 if (rc < 0)
3131 retval = -EINVAL; 2718 return rc;
3132 buf = (struct bttv_buffer *)fh->cap.bufs[*frame];
3133 if (NULL == buf)
3134 goto fh_unlock_and_return;
3135 retval = videobuf_waiton(&buf->vb,0,1);
3136 if (0 != retval)
3137 goto fh_unlock_and_return;
3138 switch (buf->vb.state) {
3139 case STATE_ERROR:
3140 retval = -EIO;
3141 /* fall through */
3142 case STATE_DONE:
3143 {
3144 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
3145 videobuf_dma_sync(&fh->cap,dma);
3146 bttv_dma_free(&fh->cap,btv,buf);
3147 break;
3148 }
3149 default:
3150 retval = -EINVAL;
3151 break;
3152 }
3153 mutex_unlock(&fh->cap.lock);
3154 return retval;
3155 }
3156 2719
3157 case VIDIOCGVBIFMT: 2720 if (!(formats[rc].flags & FORMAT_FLAGS_PACKED))
3158 if (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE) { 2721 return -EINVAL;
3159 retval = bttv_switch_type(fh,V4L2_BUF_TYPE_VBI_CAPTURE);
3160 if (0 != retval)
3161 return retval;
3162 }
3163 2722
3164 /* fall through */ 2723 return 0;
2724}
3165 2725
3166 case VIDIOCSVBIFMT: 2726static int bttv_g_fbuf(struct file *file, void *f,
3167 return v4l_compat_translate_ioctl(inode, file, cmd, 2727 struct v4l2_framebuffer *fb)
3168 arg, bttv_do_ioctl); 2728{
3169 2729 struct bttv_fh *fh = f;
3170 case BTTV_VERSION: 2730 struct bttv *btv = fh->btv;
3171 case VIDIOCGFREQ:
3172 case VIDIOCSFREQ:
3173 case VIDIOCGTUNER:
3174 case VIDIOCSTUNER:
3175 case VIDIOCGCHAN:
3176 case VIDIOCSCHAN:
3177 case VIDIOCGAUDIO:
3178 case VIDIOCSAUDIO:
3179 return bttv_common_ioctls(btv,cmd,arg);
3180
3181 /* *** v4l2 *** ************************************************ */
3182 case VIDIOC_QUERYCAP:
3183 {
3184 struct v4l2_capability *cap = arg;
3185 2731
3186 if (0 == v4l2) 2732 *fb = btv->fbuf;
3187 return -EINVAL; 2733 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
3188 memset(cap, 0, sizeof (*cap)); 2734 if (fh->ovfmt)
3189 strlcpy(cap->driver, "bttv", sizeof (cap->driver)); 2735 fb->fmt.pixelformat = fh->ovfmt->fourcc;
3190 strlcpy(cap->card, btv->video_dev->name, sizeof (cap->card)); 2736 return 0;
3191 snprintf(cap->bus_info, sizeof (cap->bus_info), 2737}
3192 "PCI:%s", pci_name(btv->c.pci));
3193 cap->version = BTTV_VERSION_CODE;
3194 cap->capabilities =
3195 V4L2_CAP_VIDEO_CAPTURE |
3196 V4L2_CAP_VBI_CAPTURE |
3197 V4L2_CAP_READWRITE |
3198 V4L2_CAP_STREAMING;
3199 if (no_overlay <= 0)
3200 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
3201
3202 if (bttv_tvcards[btv->c.type].tuner != UNSET &&
3203 bttv_tvcards[btv->c.type].tuner != TUNER_ABSENT)
3204 cap->capabilities |= V4L2_CAP_TUNER;
3205 return 0;
3206 }
3207 2738
3208 case VIDIOC_ENUM_FMT: 2739static int bttv_overlay(struct file *file, void *f, unsigned int on)
3209 { 2740{
3210 struct v4l2_fmtdesc *f = arg; 2741 struct bttv_fh *fh = f;
3211 enum v4l2_buf_type type; 2742 struct bttv *btv = fh->btv;
3212 unsigned int i; 2743 struct bttv_buffer *new;
3213 int index; 2744 int retval;
3214
3215 type = f->type;
3216 if (V4L2_BUF_TYPE_VBI_CAPTURE == type) {
3217 /* vbi */
3218 index = f->index;
3219 if (0 != index)
3220 return -EINVAL;
3221 memset(f,0,sizeof(*f));
3222 f->index = index;
3223 f->type = type;
3224 f->pixelformat = V4L2_PIX_FMT_GREY;
3225 strcpy(f->description,"vbi data");
3226 return 0;
3227 }
3228 2745
3229 /* video capture + overlay */ 2746 if (on) {
3230 index = -1; 2747 /* verify args */
3231 for (i = 0; i < BTTV_FORMATS; i++) { 2748 if (NULL == btv->fbuf.base)
3232 if (bttv_formats[i].fourcc != -1)
3233 index++;
3234 if ((unsigned int)index == f->index)
3235 break;
3236 }
3237 if (BTTV_FORMATS == i)
3238 return -EINVAL; 2749 return -EINVAL;
3239 2750 if (!fh->ov.setup_ok) {
3240 switch (f->type) { 2751 dprintk("bttv%d: overlay: !setup_ok\n", btv->c.nr);
3241 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3242 break;
3243 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3244 if (!(bttv_formats[i].flags & FORMAT_FLAGS_PACKED))
3245 return -EINVAL;
3246 break;
3247 default:
3248 return -EINVAL; 2752 return -EINVAL;
3249 } 2753 }
3250 memset(f,0,sizeof(*f));
3251 f->index = index;
3252 f->type = type;
3253 f->pixelformat = bttv_formats[i].fourcc;
3254 strlcpy(f->description,bttv_formats[i].name,sizeof(f->description));
3255 return 0;
3256 } 2754 }
3257 2755
3258 case VIDIOC_TRY_FMT: 2756 if (!check_alloc_btres(btv, fh, RESOURCE_OVERLAY))
3259 { 2757 return -EBUSY;
3260 struct v4l2_format *f = arg; 2758
3261 return bttv_try_fmt(fh,btv,f, /* adjust_crop */ 0); 2759 mutex_lock(&fh->cap.lock);
3262 } 2760 if (on) {
3263 case VIDIOC_G_FMT: 2761 fh->ov.tvnorm = btv->tvnorm;
3264 { 2762 new = videobuf_pci_alloc(sizeof(*new));
3265 struct v4l2_format *f = arg; 2763 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
3266 return bttv_g_fmt(fh,f); 2764 } else {
3267 } 2765 new = NULL;
3268 case VIDIOC_S_FMT:
3269 {
3270 struct v4l2_format *f = arg;
3271 return bttv_s_fmt(fh,btv,f);
3272 } 2766 }
3273 2767
3274 case VIDIOC_G_FBUF: 2768 /* switch over */
3275 { 2769 retval = bttv_switch_overlay(btv, fh, new);
3276 struct v4l2_framebuffer *fb = arg; 2770 mutex_unlock(&fh->cap.lock);
2771 return retval;
2772}
3277 2773
3278 *fb = btv->fbuf; 2774static int bttv_s_fbuf(struct file *file, void *f,
3279 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; 2775 struct v4l2_framebuffer *fb)
3280 if (fh->ovfmt) 2776{
3281 fb->fmt.pixelformat = fh->ovfmt->fourcc; 2777 struct bttv_fh *fh = f;
3282 return 0; 2778 struct bttv *btv = fh->btv;
3283 } 2779 const struct bttv_format *fmt;
3284 case VIDIOC_S_FBUF: 2780 int retval;
3285 {
3286 struct v4l2_framebuffer *fb = arg;
3287 const struct bttv_format *fmt;
3288 2781
3289 if(!capable(CAP_SYS_ADMIN) && 2782 if (!capable(CAP_SYS_ADMIN) &&
3290 !capable(CAP_SYS_RAWIO)) 2783 !capable(CAP_SYS_RAWIO))
3291 return -EPERM; 2784 return -EPERM;
3292 2785
3293 /* check args */ 2786 /* check args */
3294 fmt = format_by_fourcc(fb->fmt.pixelformat); 2787 fmt = format_by_fourcc(fb->fmt.pixelformat);
3295 if (NULL == fmt) 2788 if (NULL == fmt)
3296 return -EINVAL; 2789 return -EINVAL;
3297 if (0 == (fmt->flags & FORMAT_FLAGS_PACKED)) 2790 if (0 == (fmt->flags & FORMAT_FLAGS_PACKED))
3298 return -EINVAL; 2791 return -EINVAL;
3299 2792
3300 retval = -EINVAL; 2793 retval = -EINVAL;
3301 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { 2794 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) {
3302 __s32 width = fb->fmt.width; 2795 __s32 width = fb->fmt.width;
3303 __s32 height = fb->fmt.height; 2796 __s32 height = fb->fmt.height;
3304 2797
3305 retval = limit_scaled_size(fh, &width, &height, 2798 retval = limit_scaled_size(fh, &width, &height,
3306 V4L2_FIELD_INTERLACED, 2799 V4L2_FIELD_INTERLACED,
3307 /* width_mask */ ~3, 2800 /* width_mask */ ~3,
3308 /* width_bias */ 2, 2801 /* width_bias */ 2,
3309 /* adjust_size */ 0, 2802 /* adjust_size */ 0,
3310 /* adjust_crop */ 0); 2803 /* adjust_crop */ 0);
3311 if (0 != retval) 2804 if (0 != retval)
3312 return retval; 2805 return retval;
3313 } 2806 }
3314 2807
3315 /* ok, accept it */ 2808 /* ok, accept it */
3316 mutex_lock(&fh->cap.lock); 2809 mutex_lock(&fh->cap.lock);
3317 btv->fbuf.base = fb->base; 2810 btv->fbuf.base = fb->base;
3318 btv->fbuf.fmt.width = fb->fmt.width; 2811 btv->fbuf.fmt.width = fb->fmt.width;
3319 btv->fbuf.fmt.height = fb->fmt.height; 2812 btv->fbuf.fmt.height = fb->fmt.height;
3320 if (0 != fb->fmt.bytesperline) 2813 if (0 != fb->fmt.bytesperline)
3321 btv->fbuf.fmt.bytesperline = fb->fmt.bytesperline; 2814 btv->fbuf.fmt.bytesperline = fb->fmt.bytesperline;
3322 else 2815 else
3323 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8; 2816 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8;
3324 2817
3325 retval = 0; 2818 retval = 0;
3326 fh->ovfmt = fmt; 2819 fh->ovfmt = fmt;
3327 btv->init.ovfmt = fmt; 2820 btv->init.ovfmt = fmt;
3328 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { 2821 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) {
3329 fh->ov.w.left = 0; 2822 fh->ov.w.left = 0;
3330 fh->ov.w.top = 0; 2823 fh->ov.w.top = 0;
3331 fh->ov.w.width = fb->fmt.width; 2824 fh->ov.w.width = fb->fmt.width;
3332 fh->ov.w.height = fb->fmt.height; 2825 fh->ov.w.height = fb->fmt.height;
3333 btv->init.ov.w.width = fb->fmt.width; 2826 btv->init.ov.w.width = fb->fmt.width;
3334 btv->init.ov.w.height = fb->fmt.height; 2827 btv->init.ov.w.height = fb->fmt.height;
3335 kfree(fh->ov.clips); 2828 kfree(fh->ov.clips);
3336 fh->ov.clips = NULL; 2829 fh->ov.clips = NULL;
3337 fh->ov.nclips = 0; 2830 fh->ov.nclips = 0;
3338 2831
3339 if (check_btres(fh, RESOURCE_OVERLAY)) { 2832 if (check_btres(fh, RESOURCE_OVERLAY)) {
3340 struct bttv_buffer *new; 2833 struct bttv_buffer *new;
3341 2834
3342 new = videobuf_pci_alloc(sizeof(*new)); 2835 new = videobuf_pci_alloc(sizeof(*new));
3343 new->crop = btv->crop[!!fh->do_crop].rect; 2836 new->crop = btv->crop[!!fh->do_crop].rect;
3344 bttv_overlay_risc(btv,&fh->ov,fh->ovfmt,new); 2837 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
3345 retval = bttv_switch_overlay(btv,fh,new); 2838 retval = bttv_switch_overlay(btv, fh, new);
3346 }
3347 } 2839 }
3348 mutex_unlock(&fh->cap.lock);
3349 return retval;
3350 } 2840 }
2841 mutex_unlock(&fh->cap.lock);
2842 return retval;
2843}
3351 2844
3352 case VIDIOC_REQBUFS: 2845static int bttv_reqbufs(struct file *file, void *priv,
3353 return videobuf_reqbufs(bttv_queue(fh),arg); 2846 struct v4l2_requestbuffers *p)
2847{
2848 struct bttv_fh *fh = priv;
2849 return videobuf_reqbufs(bttv_queue(fh), p);
2850}
3354 2851
3355 case VIDIOC_QUERYBUF: 2852static int bttv_querybuf(struct file *file, void *priv,
3356 return videobuf_querybuf(bttv_queue(fh),arg); 2853 struct v4l2_buffer *b)
2854{
2855 struct bttv_fh *fh = priv;
2856 return videobuf_querybuf(bttv_queue(fh), b);
2857}
3357 2858
3358 case VIDIOC_QBUF: 2859static int bttv_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
3359 { 2860{
3360 int res = bttv_resource(fh); 2861 struct bttv_fh *fh = priv;
2862 struct bttv *btv = fh->btv;
2863 int res = bttv_resource(fh);
3361 2864
3362 if (!check_alloc_btres(btv, fh, res)) 2865 if (!check_alloc_btres(btv, fh, res))
3363 return -EBUSY; 2866 return -EBUSY;
3364 return videobuf_qbuf(bttv_queue(fh),arg);
3365 }
3366 2867
3367 case VIDIOC_DQBUF: 2868 return videobuf_qbuf(bttv_queue(fh), b);
3368 return videobuf_dqbuf(bttv_queue(fh),arg, 2869}
3369 file->f_flags & O_NONBLOCK);
3370 2870
3371 case VIDIOC_STREAMON: 2871static int bttv_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
3372 { 2872{
3373 int res = bttv_resource(fh); 2873 struct bttv_fh *fh = priv;
2874 return videobuf_dqbuf(bttv_queue(fh), b,
2875 file->f_flags & O_NONBLOCK);
2876}
3374 2877
3375 if (!check_alloc_btres(btv,fh,res)) 2878static int bttv_streamon(struct file *file, void *priv,
3376 return -EBUSY; 2879 enum v4l2_buf_type type)
3377 return videobuf_streamon(bttv_queue(fh)); 2880{
3378 } 2881 struct bttv_fh *fh = priv;
3379 case VIDIOC_STREAMOFF: 2882 struct bttv *btv = fh->btv;
3380 { 2883 int res = bttv_resource(fh);
3381 int res = bttv_resource(fh);
3382 2884
3383 retval = videobuf_streamoff(bttv_queue(fh)); 2885 if (!check_alloc_btres(btv, fh, res))
3384 if (retval < 0) 2886 return -EBUSY;
3385 return retval; 2887 return videobuf_streamon(bttv_queue(fh));
3386 free_btres(btv,fh,res); 2888}
3387 return 0;
3388 }
3389 2889
3390 case VIDIOC_QUERYCTRL:
3391 {
3392 struct v4l2_queryctrl *c = arg;
3393 int i;
3394 2890
3395 if ((c->id < V4L2_CID_BASE || 2891static int bttv_streamoff(struct file *file, void *priv,
3396 c->id >= V4L2_CID_LASTP1) && 2892 enum v4l2_buf_type type)
3397 (c->id < V4L2_CID_PRIVATE_BASE || 2893{
3398 c->id >= V4L2_CID_PRIVATE_LASTP1)) 2894 struct bttv_fh *fh = priv;
3399 return -EINVAL; 2895 struct bttv *btv = fh->btv;
3400 for (i = 0; i < BTTV_CTLS; i++) 2896 int retval;
3401 if (bttv_ctls[i].id == c->id) 2897 int res = bttv_resource(fh);
3402 break;
3403 if (i == BTTV_CTLS) {
3404 *c = no_ctl;
3405 return 0;
3406 }
3407 *c = bttv_ctls[i];
3408 if (btv->audio_hook && i >= 4 && i <= 8) {
3409 struct video_audio va;
3410 memset(&va,0,sizeof(va));
3411 btv->audio_hook(btv,&va,0);
3412 switch (bttv_ctls[i].id) {
3413 case V4L2_CID_AUDIO_VOLUME:
3414 if (!(va.flags & VIDEO_AUDIO_VOLUME))
3415 *c = no_ctl;
3416 break;
3417 case V4L2_CID_AUDIO_BALANCE:
3418 if (!(va.flags & VIDEO_AUDIO_BALANCE))
3419 *c = no_ctl;
3420 break;
3421 case V4L2_CID_AUDIO_BASS:
3422 if (!(va.flags & VIDEO_AUDIO_BASS))
3423 *c = no_ctl;
3424 break;
3425 case V4L2_CID_AUDIO_TREBLE:
3426 if (!(va.flags & VIDEO_AUDIO_TREBLE))
3427 *c = no_ctl;
3428 break;
3429 }
3430 }
3431 return 0;
3432 }
3433 case VIDIOC_G_CTRL:
3434 return get_control(btv,arg);
3435 case VIDIOC_S_CTRL:
3436 return set_control(btv,arg);
3437 case VIDIOC_G_PARM:
3438 {
3439 struct v4l2_streamparm *parm = arg;
3440 struct v4l2_standard s;
3441 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
3442 return -EINVAL;
3443 memset(parm,0,sizeof(*parm));
3444 v4l2_video_std_construct(&s, bttv_tvnorms[btv->tvnorm].v4l2_id,
3445 bttv_tvnorms[btv->tvnorm].name);
3446 parm->parm.capture.timeperframe = s.frameperiod;
3447 return 0;
3448 }
3449 2898
3450 case VIDIOC_G_PRIORITY:
3451 {
3452 enum v4l2_priority *p = arg;
3453 2899
3454 *p = v4l2_prio_max(&btv->prio); 2900 retval = videobuf_streamoff(bttv_queue(fh));
3455 return 0; 2901 if (retval < 0)
3456 } 2902 return retval;
3457 case VIDIOC_S_PRIORITY: 2903 free_btres(btv, fh, res);
3458 { 2904 return 0;
3459 enum v4l2_priority *prio = arg; 2905}
3460 2906
3461 return v4l2_prio_change(&btv->prio, &fh->prio, *prio); 2907static int bttv_queryctrl(struct file *file, void *priv,
3462 } 2908 struct v4l2_queryctrl *c)
2909{
2910 struct bttv_fh *fh = priv;
2911 struct bttv *btv = fh->btv;
2912 const struct v4l2_queryctrl *ctrl;
3463 2913
3464 case VIDIOC_CROPCAP: 2914 if ((c->id < V4L2_CID_BASE ||
3465 { 2915 c->id >= V4L2_CID_LASTP1) &&
3466 struct v4l2_cropcap *cap = arg; 2916 (c->id < V4L2_CID_PRIVATE_BASE ||
3467 enum v4l2_buf_type type; 2917 c->id >= V4L2_CID_PRIVATE_LASTP1))
2918 return -EINVAL;
3468 2919
3469 type = cap->type; 2920 if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME))
2921 *c = no_ctl;
2922 else {
2923 ctrl = ctrl_by_id(c->id);
3470 2924
3471 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE && 2925 *c = (NULL != ctrl) ? *ctrl : no_ctl;
3472 type != V4L2_BUF_TYPE_VIDEO_OVERLAY) 2926 }
3473 return -EINVAL;
3474 2927
3475 *cap = bttv_tvnorms[btv->tvnorm].cropcap; 2928 return 0;
3476 cap->type = type; 2929}
3477 2930
3478 return 0; 2931static int bttv_g_parm(struct file *file, void *f,
3479 } 2932 struct v4l2_streamparm *parm)
3480 case VIDIOC_G_CROP: 2933{
3481 { 2934 struct bttv_fh *fh = f;
3482 struct v4l2_crop * crop = arg; 2935 struct bttv *btv = fh->btv;
2936 struct v4l2_standard s;
3483 2937
3484 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && 2938 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
3485 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) 2939 return -EINVAL;
3486 return -EINVAL; 2940 v4l2_video_std_construct(&s, bttv_tvnorms[btv->tvnorm].v4l2_id,
2941 bttv_tvnorms[btv->tvnorm].name);
2942 parm->parm.capture.timeperframe = s.frameperiod;
2943 return 0;
2944}
3487 2945
3488 /* No fh->do_crop = 1; because btv->crop[1] may be 2946static int bttv_g_tuner(struct file *file, void *priv,
3489 inconsistent with fh->width or fh->height and apps 2947 struct v4l2_tuner *t)
3490 do not expect a change here. */ 2948{
2949 struct bttv_fh *fh = priv;
2950 struct bttv *btv = fh->btv;
3491 2951
3492 crop->c = btv->crop[!!fh->do_crop].rect; 2952 if (UNSET == bttv_tvcards[btv->c.type].tuner)
2953 return -EINVAL;
2954 if (0 != t->index)
2955 return -EINVAL;
3493 2956
3494 return 0; 2957 mutex_lock(&btv->lock);
3495 } 2958 memset(t, 0, sizeof(*t));
3496 case VIDIOC_S_CROP: 2959 t->rxsubchans = V4L2_TUNER_SUB_MONO;
3497 { 2960 bttv_call_i2c_clients(btv, VIDIOC_G_TUNER, t);
3498 struct v4l2_crop *crop = arg; 2961 strcpy(t->name, "Television");
3499 const struct v4l2_rect *b; 2962 t->capability = V4L2_TUNER_CAP_NORM;
3500 struct bttv_crop c; 2963 t->type = V4L2_TUNER_ANALOG_TV;
3501 __s32 b_left; 2964 if (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC)
3502 __s32 b_top; 2965 t->signal = 0xffff;
3503 __s32 b_right; 2966
3504 __s32 b_bottom; 2967 if (btv->audio_mode_gpio)
3505 2968 btv->audio_mode_gpio(btv, t, 0);
3506 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
3507 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
3508 return -EINVAL;
3509 2969
3510 retval = v4l2_prio_check(&btv->prio,&fh->prio); 2970 mutex_unlock(&btv->lock);
3511 if (0 != retval) 2971 return 0;
3512 return retval; 2972}
3513 2973
3514 /* Make sure tvnorm, vbi_end and the current cropping 2974static int bttv_g_priority(struct file *file, void *f, enum v4l2_priority *p)
3515 parameters remain consistent until we're done. Note 2975{
3516 read() may change vbi_end in check_alloc_btres(). */ 2976 struct bttv_fh *fh = f;
3517 mutex_lock(&btv->lock); 2977 struct bttv *btv = fh->btv;
3518 2978
3519 retval = -EBUSY; 2979 *p = v4l2_prio_max(&btv->prio);
3520 2980
3521 if (locked_btres(fh->btv, VIDEO_RESOURCES)) 2981 return 0;
3522 goto btv_unlock_and_return; 2982}
3523 2983
3524 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; 2984static int bttv_s_priority(struct file *file, void *f,
2985 enum v4l2_priority prio)
2986{
2987 struct bttv_fh *fh = f;
2988 struct bttv *btv = fh->btv;
3525 2989
3526 b_left = b->left; 2990 return v4l2_prio_change(&btv->prio, &fh->prio, prio);
3527 b_right = b_left + b->width; 2991}
3528 b_bottom = b->top + b->height;
3529 2992
3530 b_top = max(b->top, btv->vbi_end); 2993static int bttv_cropcap(struct file *file, void *priv,
3531 if (b_top + 32 >= b_bottom) 2994 struct v4l2_cropcap *cap)
3532 goto btv_unlock_and_return; 2995{
2996 struct bttv_fh *fh = priv;
2997 struct bttv *btv = fh->btv;
3533 2998
3534 /* Min. scaled size 48 x 32. */ 2999 if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
3535 c.rect.left = clamp(crop->c.left, b_left, b_right - 48); 3000 cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
3536 c.rect.left = min(c.rect.left, (__s32) MAX_HDELAY); 3001 return -EINVAL;
3537 3002
3538 c.rect.width = clamp(crop->c.width, 3003 *cap = bttv_tvnorms[btv->tvnorm].cropcap;
3539 48, b_right - c.rect.left);
3540 3004
3541 c.rect.top = clamp(crop->c.top, b_top, b_bottom - 32); 3005 return 0;
3542 /* Top and height must be a multiple of two. */ 3006}
3543 c.rect.top = (c.rect.top + 1) & ~1;
3544 3007
3545 c.rect.height = clamp(crop->c.height, 3008static int bttv_g_crop(struct file *file, void *f, struct v4l2_crop *crop)
3546 32, b_bottom - c.rect.top); 3009{
3547 c.rect.height = (c.rect.height + 1) & ~1; 3010 struct bttv_fh *fh = f;
3011 struct bttv *btv = fh->btv;
3548 3012
3549 bttv_crop_calc_limits(&c); 3013 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
3014 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
3015 return -EINVAL;
3550 3016
3551 btv->crop[1] = c; 3017 /* No fh->do_crop = 1; because btv->crop[1] may be
3018 inconsistent with fh->width or fh->height and apps
3019 do not expect a change here. */
3552 3020
3553 mutex_unlock(&btv->lock); 3021 crop->c = btv->crop[!!fh->do_crop].rect;
3554 3022
3555 fh->do_crop = 1; 3023 return 0;
3024}
3556 3025
3557 mutex_lock(&fh->cap.lock); 3026static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop)
3027{
3028 struct bttv_fh *fh = f;
3029 struct bttv *btv = fh->btv;
3030 const struct v4l2_rect *b;
3031 int retval;
3032 struct bttv_crop c;
3033 __s32 b_left;
3034 __s32 b_top;
3035 __s32 b_right;
3036 __s32 b_bottom;
3558 3037
3559 if (fh->width < c.min_scaled_width) { 3038 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
3560 fh->width = c.min_scaled_width; 3039 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
3561 btv->init.width = c.min_scaled_width; 3040 return -EINVAL;
3562 } else if (fh->width > c.max_scaled_width) {
3563 fh->width = c.max_scaled_width;
3564 btv->init.width = c.max_scaled_width;
3565 }
3566 3041
3567 if (fh->height < c.min_scaled_height) { 3042 retval = v4l2_prio_check(&btv->prio, &fh->prio);
3568 fh->height = c.min_scaled_height; 3043 if (0 != retval)
3569 btv->init.height = c.min_scaled_height; 3044 return retval;
3570 } else if (fh->height > c.max_scaled_height) {
3571 fh->height = c.max_scaled_height;
3572 btv->init.height = c.max_scaled_height;
3573 }
3574 3045
3575 mutex_unlock(&fh->cap.lock); 3046 /* Make sure tvnorm, vbi_end and the current cropping
3047 parameters remain consistent until we're done. Note
3048 read() may change vbi_end in check_alloc_btres(). */
3049 mutex_lock(&btv->lock);
3576 3050
3577 return 0; 3051 retval = -EBUSY;
3052
3053 if (locked_btres(fh->btv, VIDEO_RESOURCES)) {
3054 mutex_unlock(&btv->lock);
3055 return retval;
3578 } 3056 }
3579 3057
3580 case VIDIOC_ENUMSTD: 3058 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
3581 case VIDIOC_G_STD:
3582 case VIDIOC_S_STD:
3583 case VIDIOC_ENUMINPUT:
3584 case VIDIOC_G_INPUT:
3585 case VIDIOC_S_INPUT:
3586 case VIDIOC_G_TUNER:
3587 case VIDIOC_S_TUNER:
3588 case VIDIOC_G_FREQUENCY:
3589 case VIDIOC_S_FREQUENCY:
3590 case VIDIOC_LOG_STATUS:
3591 case VIDIOC_DBG_G_REGISTER:
3592 case VIDIOC_DBG_S_REGISTER:
3593 return bttv_common_ioctls(btv,cmd,arg);
3594 3059
3595 default: 3060 b_left = b->left;
3596 return -ENOIOCTLCMD; 3061 b_right = b_left + b->width;
3062 b_bottom = b->top + b->height;
3063
3064 b_top = max(b->top, btv->vbi_end);
3065 if (b_top + 32 >= b_bottom) {
3066 mutex_unlock(&btv->lock);
3067 return retval;
3597 } 3068 }
3598 return 0;
3599 3069
3600 fh_unlock_and_return: 3070 /* Min. scaled size 48 x 32. */
3601 mutex_unlock(&fh->cap.lock); 3071 c.rect.left = clamp(crop->c.left, b_left, b_right - 48);
3602 return retval; 3072 c.rect.left = min(c.rect.left, (__s32) MAX_HDELAY);
3603 3073
3604 btv_unlock_and_return: 3074 c.rect.width = clamp(crop->c.width,
3605 mutex_unlock(&btv->lock); 3075 48, b_right - c.rect.left);
3606 return retval;
3607}
3608 3076
3609static int bttv_ioctl(struct inode *inode, struct file *file, 3077 c.rect.top = clamp(crop->c.top, b_top, b_bottom - 32);
3610 unsigned int cmd, unsigned long arg) 3078 /* Top and height must be a multiple of two. */
3611{ 3079 c.rect.top = (c.rect.top + 1) & ~1;
3612 struct bttv_fh *fh = file->private_data;
3613 3080
3614 switch (cmd) { 3081 c.rect.height = clamp(crop->c.height,
3615 case BTTV_VBISIZE: 3082 32, b_bottom - c.rect.top);
3616 { 3083 c.rect.height = (c.rect.height + 1) & ~1;
3617 const struct bttv_tvnorm *tvnorm;
3618 3084
3619 tvnorm = fh->vbi_fmt.tvnorm; 3085 bttv_crop_calc_limits(&c);
3620 3086
3621 if (fh->vbi_fmt.fmt.start[0] != tvnorm->vbistart[0] || 3087 btv->crop[1] = c;
3622 fh->vbi_fmt.fmt.start[1] != tvnorm->vbistart[1] || 3088
3623 fh->vbi_fmt.fmt.count[0] != fh->vbi_fmt.fmt.count[1]) { 3089 mutex_unlock(&btv->lock);
3624 /* BTTV_VBISIZE cannot express these parameters, 3090
3625 however open() resets the paramters to defaults 3091 fh->do_crop = 1;
3626 and apps shouldn't call BTTV_VBISIZE after
3627 VIDIOC_S_FMT. */
3628 return -EINVAL;
3629 }
3630 3092
3631 bttv_switch_type(fh,V4L2_BUF_TYPE_VBI_CAPTURE); 3093 mutex_lock(&fh->cap.lock);
3632 return (fh->vbi_fmt.fmt.count[0] * 2 3094
3633 * fh->vbi_fmt.fmt.samples_per_line); 3095 if (fh->width < c.min_scaled_width) {
3096 fh->width = c.min_scaled_width;
3097 btv->init.width = c.min_scaled_width;
3098 } else if (fh->width > c.max_scaled_width) {
3099 fh->width = c.max_scaled_width;
3100 btv->init.width = c.max_scaled_width;
3634 } 3101 }
3635 3102
3636 default: 3103 if (fh->height < c.min_scaled_height) {
3637 return video_usercopy(inode, file, cmd, arg, bttv_do_ioctl); 3104 fh->height = c.min_scaled_height;
3105 btv->init.height = c.min_scaled_height;
3106 } else if (fh->height > c.max_scaled_height) {
3107 fh->height = c.max_scaled_height;
3108 btv->init.height = c.max_scaled_height;
3638 } 3109 }
3110
3111 mutex_unlock(&fh->cap.lock);
3112
3113 return 0;
3114}
3115
3116static int bttv_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
3117{
3118 strcpy(a->name, "audio");
3119 return 0;
3120}
3121
3122static int bttv_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
3123{
3124 return 0;
3639} 3125}
3640 3126
3641static ssize_t bttv_read(struct file *file, char __user *data, 3127static ssize_t bttv_read(struct file *file, char __user *data,
@@ -3719,8 +3205,8 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3719 } 3205 }
3720 3206
3721 poll_wait(file, &buf->vb.done, wait); 3207 poll_wait(file, &buf->vb.done, wait);
3722 if (buf->vb.state == STATE_DONE || 3208 if (buf->vb.state == VIDEOBUF_DONE ||
3723 buf->vb.state == STATE_ERROR) 3209 buf->vb.state == VIDEOBUF_ERROR)
3724 return POLLIN|POLLRDNORM; 3210 return POLLIN|POLLRDNORM;
3725 return 0; 3211 return 0;
3726} 3212}
@@ -3777,7 +3263,7 @@ static int bttv_open(struct inode *inode, struct file *file)
3777 V4L2_FIELD_SEQ_TB, 3263 V4L2_FIELD_SEQ_TB,
3778 sizeof(struct bttv_buffer), 3264 sizeof(struct bttv_buffer),
3779 fh); 3265 fh);
3780 i2c_vidiocschan(btv); 3266 set_tvnorm(btv,btv->tvnorm);
3781 3267
3782 btv->users++; 3268 btv->users++;
3783 3269
@@ -3857,7 +3343,7 @@ static const struct file_operations bttv_fops =
3857 .owner = THIS_MODULE, 3343 .owner = THIS_MODULE,
3858 .open = bttv_open, 3344 .open = bttv_open,
3859 .release = bttv_release, 3345 .release = bttv_release,
3860 .ioctl = bttv_ioctl, 3346 .ioctl = video_ioctl2,
3861 .compat_ioctl = v4l_compat_ioctl32, 3347 .compat_ioctl = v4l_compat_ioctl32,
3862 .llseek = no_llseek, 3348 .llseek = no_llseek,
3863 .read = bttv_read, 3349 .read = bttv_read,
@@ -3867,19 +3353,61 @@ static const struct file_operations bttv_fops =
3867 3353
3868static struct video_device bttv_video_template = 3354static struct video_device bttv_video_template =
3869{ 3355{
3870 .name = "UNSET",
3871 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|
3872 VID_TYPE_CLIPPING|VID_TYPE_SCALES,
3873 .fops = &bttv_fops,
3874 .minor = -1,
3875};
3876
3877static struct video_device bttv_vbi_template =
3878{
3879 .name = "bt848/878 vbi",
3880 .type = VID_TYPE_TUNER|VID_TYPE_TELETEXT,
3881 .fops = &bttv_fops, 3356 .fops = &bttv_fops,
3882 .minor = -1, 3357 .minor = -1,
3358 .vidioc_querycap = bttv_querycap,
3359 .vidioc_enum_fmt_cap = bttv_enum_fmt_cap,
3360 .vidioc_g_fmt_cap = bttv_g_fmt_cap,
3361 .vidioc_try_fmt_cap = bttv_try_fmt_cap,
3362 .vidioc_s_fmt_cap = bttv_s_fmt_cap,
3363 .vidioc_enum_fmt_overlay = bttv_enum_fmt_overlay,
3364 .vidioc_g_fmt_overlay = bttv_g_fmt_overlay,
3365 .vidioc_try_fmt_overlay = bttv_try_fmt_overlay,
3366 .vidioc_s_fmt_overlay = bttv_s_fmt_overlay,
3367 .vidioc_enum_fmt_vbi = bttv_enum_fmt_vbi,
3368 .vidioc_g_fmt_vbi = bttv_g_fmt_vbi,
3369 .vidioc_try_fmt_vbi = bttv_try_fmt_vbi,
3370 .vidioc_s_fmt_vbi = bttv_s_fmt_vbi,
3371 .vidioc_g_audio = bttv_g_audio,
3372 .vidioc_s_audio = bttv_s_audio,
3373 .vidioc_cropcap = bttv_cropcap,
3374 .vidioc_reqbufs = bttv_reqbufs,
3375 .vidioc_querybuf = bttv_querybuf,
3376 .vidioc_qbuf = bttv_qbuf,
3377 .vidioc_dqbuf = bttv_dqbuf,
3378 .vidioc_s_std = bttv_s_std,
3379 .vidioc_enum_input = bttv_enum_input,
3380 .vidioc_g_input = bttv_g_input,
3381 .vidioc_s_input = bttv_s_input,
3382 .vidioc_queryctrl = bttv_queryctrl,
3383 .vidioc_g_ctrl = bttv_g_ctrl,
3384 .vidioc_s_ctrl = bttv_s_ctrl,
3385 .vidioc_streamon = bttv_streamon,
3386 .vidioc_streamoff = bttv_streamoff,
3387 .vidioc_g_tuner = bttv_g_tuner,
3388 .vidioc_s_tuner = bttv_s_tuner,
3389#ifdef CONFIG_VIDEO_V4L1_COMPAT
3390 .vidiocgmbuf = vidiocgmbuf,
3391#endif
3392 .vidioc_g_crop = bttv_g_crop,
3393 .vidioc_g_crop = bttv_g_crop,
3394 .vidioc_s_crop = bttv_s_crop,
3395 .vidioc_g_fbuf = bttv_g_fbuf,
3396 .vidioc_s_fbuf = bttv_s_fbuf,
3397 .vidioc_overlay = bttv_overlay,
3398 .vidioc_g_priority = bttv_g_priority,
3399 .vidioc_s_priority = bttv_s_priority,
3400 .vidioc_g_parm = bttv_g_parm,
3401 .vidioc_g_frequency = bttv_g_frequency,
3402 .vidioc_s_frequency = bttv_s_frequency,
3403 .vidioc_log_status = bttv_log_status,
3404 .vidioc_querystd = bttv_querystd,
3405#ifdef CONFIG_VIDEO_ADV_DEBUG
3406 .vidioc_g_register = bttv_g_register,
3407 .vidioc_s_register = bttv_s_register,
3408#endif
3409 .tvnorms = BTTV_NORMS,
3410 .current_norm = V4L2_STD_PAL,
3883}; 3411};
3884 3412
3885/* ----------------------------------------------------------------------- */ 3413/* ----------------------------------------------------------------------- */
@@ -3918,7 +3446,7 @@ static int radio_open(struct inode *inode, struct file *file)
3918 3446
3919static int radio_release(struct inode *inode, struct file *file) 3447static int radio_release(struct inode *inode, struct file *file)
3920{ 3448{
3921 struct bttv *btv = file->private_data; 3449 struct bttv *btv = file->private_data;
3922 struct rds_command cmd; 3450 struct rds_command cmd;
3923 3451
3924 btv->radio_user--; 3452 btv->radio_user--;
@@ -3928,59 +3456,116 @@ static int radio_release(struct inode *inode, struct file *file)
3928 return 0; 3456 return 0;
3929} 3457}
3930 3458
3931static int radio_do_ioctl(struct inode *inode, struct file *file, 3459static int radio_querycap(struct file *file, void *priv,
3932 unsigned int cmd, void *arg) 3460 struct v4l2_capability *cap)
3933{ 3461{
3934 struct bttv *btv = file->private_data; 3462 struct bttv_fh *fh = priv;
3463 struct bttv *btv = fh->btv;
3935 3464
3936 switch (cmd) { 3465 strcpy(cap->driver, "bttv");
3937 case VIDIOCGCAP: 3466 strlcpy(cap->card, btv->radio_dev->name, sizeof(cap->card));
3938 { 3467 sprintf(cap->bus_info, "PCI:%s", pci_name(btv->c.pci));
3939 struct video_capability *cap = arg; 3468 cap->version = BTTV_VERSION_CODE;
3469 cap->capabilities = V4L2_CAP_TUNER;
3940 3470
3941 memset(cap,0,sizeof(*cap)); 3471 return 0;
3942 strcpy(cap->name,btv->radio_dev->name); 3472}
3943 cap->type = VID_TYPE_TUNER;
3944 cap->channels = 1;
3945 cap->audios = 1;
3946 return 0;
3947 }
3948 3473
3949 case VIDIOCGTUNER: 3474static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
3950 { 3475{
3951 struct video_tuner *v = arg; 3476 struct bttv_fh *fh = priv;
3477 struct bttv *btv = fh->btv;
3952 3478
3953 if(v->tuner) 3479 if (UNSET == bttv_tvcards[btv->c.type].tuner)
3954 return -EINVAL; 3480 return -EINVAL;
3955 memset(v,0,sizeof(*v)); 3481 if (0 != t->index)
3956 strcpy(v->name, "Radio"); 3482 return -EINVAL;
3957 bttv_call_i2c_clients(btv,cmd,v); 3483 mutex_lock(&btv->lock);
3958 return 0; 3484 memset(t, 0, sizeof(*t));
3959 } 3485 strcpy(t->name, "Radio");
3960 case VIDIOCSTUNER: 3486 t->type = V4L2_TUNER_RADIO;
3961 /* nothing to do */
3962 return 0;
3963 3487
3964 case BTTV_VERSION: 3488 bttv_call_i2c_clients(btv, VIDIOC_G_TUNER, t);
3965 case VIDIOCGFREQ: 3489
3966 case VIDIOCSFREQ: 3490 if (btv->audio_mode_gpio)
3967 case VIDIOCGAUDIO: 3491 btv->audio_mode_gpio(btv, t, 0);
3968 case VIDIOCSAUDIO: 3492
3969 case VIDIOC_LOG_STATUS: 3493 mutex_unlock(&btv->lock);
3970 case VIDIOC_DBG_G_REGISTER: 3494
3971 case VIDIOC_DBG_S_REGISTER: 3495 return 0;
3972 return bttv_common_ioctls(btv,cmd,arg); 3496}
3497
3498static int radio_enum_input(struct file *file, void *priv,
3499 struct v4l2_input *i)
3500{
3501 if (i->index != 0)
3502 return -EINVAL;
3503
3504 strcpy(i->name, "Radio");
3505 i->type = V4L2_INPUT_TYPE_TUNER;
3506
3507 return 0;
3508}
3509
3510static int radio_g_audio(struct file *file, void *priv,
3511 struct v4l2_audio *a)
3512{
3513 memset(a, 0, sizeof(*a));
3514 strcpy(a->name, "Radio");
3515 return 0;
3516}
3517
3518static int radio_s_tuner(struct file *file, void *priv,
3519 struct v4l2_tuner *t)
3520{
3521 struct bttv_fh *fh = priv;
3522 struct bttv *btv = fh->btv;
3523
3524 if (0 != t->index)
3525 return -EINVAL;
3526
3527 bttv_call_i2c_clients(btv, VIDIOC_G_TUNER, t);
3528 return 0;
3529}
3530
3531static int radio_s_audio(struct file *file, void *priv,
3532 struct v4l2_audio *a)
3533{
3534 return 0;
3535}
3536
3537static int radio_s_input(struct file *filp, void *priv, unsigned int i)
3538{
3539 return 0;
3540}
3541
3542static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm)
3543{
3544 return 0;
3545}
3546
3547static int radio_queryctrl(struct file *file, void *priv,
3548 struct v4l2_queryctrl *c)
3549{
3550 const struct v4l2_queryctrl *ctrl;
3551
3552 if (c->id < V4L2_CID_BASE ||
3553 c->id >= V4L2_CID_LASTP1)
3554 return -EINVAL;
3555
3556 if (c->id == V4L2_CID_AUDIO_MUTE) {
3557 ctrl = ctrl_by_id(c->id);
3558 *c = *ctrl;
3559 } else
3560 *c = no_ctl;
3973 3561
3974 default:
3975 return -ENOIOCTLCMD;
3976 }
3977 return 0; 3562 return 0;
3978} 3563}
3979 3564
3980static int radio_ioctl(struct inode *inode, struct file *file, 3565static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
3981 unsigned int cmd, unsigned long arg)
3982{ 3566{
3983 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl); 3567 *i = 0;
3568 return 0;
3984} 3569}
3985 3570
3986static ssize_t radio_read(struct file *file, char __user *data, 3571static ssize_t radio_read(struct file *file, char __user *data,
@@ -4016,17 +3601,29 @@ static const struct file_operations radio_fops =
4016 .open = radio_open, 3601 .open = radio_open,
4017 .read = radio_read, 3602 .read = radio_read,
4018 .release = radio_release, 3603 .release = radio_release,
4019 .ioctl = radio_ioctl, 3604 .ioctl = video_ioctl2,
4020 .llseek = no_llseek, 3605 .llseek = no_llseek,
4021 .poll = radio_poll, 3606 .poll = radio_poll,
4022}; 3607};
4023 3608
4024static struct video_device radio_template = 3609static struct video_device radio_template =
4025{ 3610{
4026 .name = "bt848/878 radio",
4027 .type = VID_TYPE_TUNER,
4028 .fops = &radio_fops, 3611 .fops = &radio_fops,
4029 .minor = -1, 3612 .minor = -1,
3613 .vidioc_querycap = radio_querycap,
3614 .vidioc_g_tuner = radio_g_tuner,
3615 .vidioc_enum_input = radio_enum_input,
3616 .vidioc_g_audio = radio_g_audio,
3617 .vidioc_s_tuner = radio_s_tuner,
3618 .vidioc_s_audio = radio_s_audio,
3619 .vidioc_s_input = radio_s_input,
3620 .vidioc_s_std = radio_s_std,
3621 .vidioc_queryctrl = radio_queryctrl,
3622 .vidioc_g_input = radio_g_input,
3623 .vidioc_g_ctrl = bttv_g_ctrl,
3624 .vidioc_s_ctrl = bttv_s_ctrl,
3625 .vidioc_g_frequency = bttv_g_frequency,
3626 .vidioc_s_frequency = bttv_s_frequency,
4030}; 3627};
4031 3628
4032/* ----------------------------------------------------------------------- */ 3629/* ----------------------------------------------------------------------- */
@@ -4308,20 +3905,20 @@ static void bttv_irq_timeout(unsigned long data)
4308 bttv_set_dma(btv, 0); 3905 bttv_set_dma(btv, 0);
4309 3906
4310 /* wake up */ 3907 /* wake up */
4311 bttv_irq_wakeup_video(btv, &old, &new, STATE_ERROR); 3908 bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_ERROR);
4312 bttv_irq_wakeup_vbi(btv, ovbi, STATE_ERROR); 3909 bttv_irq_wakeup_vbi(btv, ovbi, VIDEOBUF_ERROR);
4313 3910
4314 /* cancel all outstanding capture / vbi requests */ 3911 /* cancel all outstanding capture / vbi requests */
4315 while (!list_empty(&btv->capture)) { 3912 while (!list_empty(&btv->capture)) {
4316 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue); 3913 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue);
4317 list_del(&item->vb.queue); 3914 list_del(&item->vb.queue);
4318 item->vb.state = STATE_ERROR; 3915 item->vb.state = VIDEOBUF_ERROR;
4319 wake_up(&item->vb.done); 3916 wake_up(&item->vb.done);
4320 } 3917 }
4321 while (!list_empty(&btv->vcapture)) { 3918 while (!list_empty(&btv->vcapture)) {
4322 item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue); 3919 item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue);
4323 list_del(&item->vb.queue); 3920 list_del(&item->vb.queue);
4324 item->vb.state = STATE_ERROR; 3921 item->vb.state = VIDEOBUF_ERROR;
4325 wake_up(&item->vb.done); 3922 wake_up(&item->vb.done);
4326 } 3923 }
4327 3924
@@ -4344,7 +3941,7 @@ bttv_irq_wakeup_top(struct bttv *btv)
4344 3941
4345 do_gettimeofday(&wakeup->vb.ts); 3942 do_gettimeofday(&wakeup->vb.ts);
4346 wakeup->vb.field_count = btv->field_count; 3943 wakeup->vb.field_count = btv->field_count;
4347 wakeup->vb.state = STATE_DONE; 3944 wakeup->vb.state = VIDEOBUF_DONE;
4348 wake_up(&wakeup->vb.done); 3945 wake_up(&wakeup->vb.done);
4349 spin_unlock(&btv->s_lock); 3946 spin_unlock(&btv->s_lock);
4350} 3947}
@@ -4393,7 +3990,7 @@ bttv_irq_switch_video(struct bttv *btv)
4393 } 3990 }
4394 3991
4395 /* wake up finished buffers */ 3992 /* wake up finished buffers */
4396 bttv_irq_wakeup_video(btv, &old, &new, STATE_DONE); 3993 bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_DONE);
4397 spin_unlock(&btv->s_lock); 3994 spin_unlock(&btv->s_lock);
4398} 3995}
4399 3996
@@ -4426,7 +4023,7 @@ bttv_irq_switch_vbi(struct bttv *btv)
4426 bttv_buffer_activate_vbi(btv, new); 4023 bttv_buffer_activate_vbi(btv, new);
4427 bttv_set_dma(btv, 0); 4024 bttv_set_dma(btv, 0);
4428 4025
4429 bttv_irq_wakeup_vbi(btv, old, STATE_DONE); 4026 bttv_irq_wakeup_vbi(btv, old, VIDEOBUF_DONE);
4430 spin_unlock(&btv->s_lock); 4027 spin_unlock(&btv->s_lock);
4431} 4028}
4432 4029
@@ -4548,8 +4145,9 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
4548/* initialitation */ 4145/* initialitation */
4549 4146
4550static struct video_device *vdev_init(struct bttv *btv, 4147static struct video_device *vdev_init(struct bttv *btv,
4551 struct video_device *template, 4148 const struct video_device *template,
4552 char *type) 4149 const char *type_name,
4150 const int type)
4553{ 4151{
4554 struct video_device *vfd; 4152 struct video_device *vfd;
4555 4153
@@ -4560,9 +4158,10 @@ static struct video_device *vdev_init(struct bttv *btv,
4560 vfd->minor = -1; 4158 vfd->minor = -1;
4561 vfd->dev = &btv->c.pci->dev; 4159 vfd->dev = &btv->c.pci->dev;
4562 vfd->release = video_device_release; 4160 vfd->release = video_device_release;
4161 vfd->type = type;
4563 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", 4162 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
4564 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", 4163 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
4565 type, bttv_tvcards[btv->c.type].name); 4164 type_name, bttv_tvcards[btv->c.type].name);
4566 return vfd; 4165 return vfd;
4567} 4166}
4568 4167
@@ -4594,6 +4193,11 @@ static void bttv_unregister_video(struct bttv *btv)
4594/* register video4linux devices */ 4193/* register video4linux devices */
4595static int __devinit bttv_register_video(struct bttv *btv) 4194static int __devinit bttv_register_video(struct bttv *btv)
4596{ 4195{
4196 int video_type = VID_TYPE_CAPTURE |
4197 VID_TYPE_TUNER |
4198 VID_TYPE_CLIPPING|
4199 VID_TYPE_SCALES;
4200
4597 if (no_overlay <= 0) { 4201 if (no_overlay <= 0) {
4598 bttv_video_template.type |= VID_TYPE_OVERLAY; 4202 bttv_video_template.type |= VID_TYPE_OVERLAY;
4599 } else { 4203 } else {
@@ -4601,7 +4205,9 @@ static int __devinit bttv_register_video(struct bttv *btv)
4601 } 4205 }
4602 4206
4603 /* video */ 4207 /* video */
4604 btv->video_dev = vdev_init(btv, &bttv_video_template, "video"); 4208 btv->video_dev = vdev_init(btv, &bttv_video_template,
4209 "video", video_type);
4210
4605 if (NULL == btv->video_dev) 4211 if (NULL == btv->video_dev)
4606 goto err; 4212 goto err;
4607 if (video_register_device(btv->video_dev,VFL_TYPE_GRABBER,video_nr)<0) 4213 if (video_register_device(btv->video_dev,VFL_TYPE_GRABBER,video_nr)<0)
@@ -4616,7 +4222,9 @@ static int __devinit bttv_register_video(struct bttv *btv)
4616 } 4222 }
4617 4223
4618 /* vbi */ 4224 /* vbi */
4619 btv->vbi_dev = vdev_init(btv, &bttv_vbi_template, "vbi"); 4225 btv->vbi_dev = vdev_init(btv, &bttv_video_template,
4226 "vbi", VID_TYPE_TUNER | VID_TYPE_TELETEXT);
4227
4620 if (NULL == btv->vbi_dev) 4228 if (NULL == btv->vbi_dev)
4621 goto err; 4229 goto err;
4622 if (video_register_device(btv->vbi_dev,VFL_TYPE_VBI,vbi_nr)<0) 4230 if (video_register_device(btv->vbi_dev,VFL_TYPE_VBI,vbi_nr)<0)
@@ -4627,7 +4235,8 @@ static int __devinit bttv_register_video(struct bttv *btv)
4627 if (!btv->has_radio) 4235 if (!btv->has_radio)
4628 return 0; 4236 return 0;
4629 /* radio */ 4237 /* radio */
4630 btv->radio_dev = vdev_init(btv, &radio_template, "radio"); 4238 btv->radio_dev = vdev_init(btv, &radio_template,
4239 "radio", VID_TYPE_TUNER);
4631 if (NULL == btv->radio_dev) 4240 if (NULL == btv->radio_dev)
4632 goto err; 4241 goto err;
4633 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,radio_nr)<0) 4242 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,radio_nr)<0)
@@ -4768,7 +4377,7 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4768 btv->init.btv = btv; 4377 btv->init.btv = btv;
4769 btv->init.ov.w.width = 320; 4378 btv->init.ov.w.width = 320;
4770 btv->init.ov.w.height = 240; 4379 btv->init.ov.w.height = 240;
4771 btv->init.fmt = format_by_palette(VIDEO_PALETTE_RGB24); 4380 btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
4772 btv->init.width = 320; 4381 btv->init.width = 320;
4773 btv->init.height = 240; 4382 btv->init.height = 240;
4774 btv->input = 0; 4383 btv->input = 0;
@@ -5013,14 +4622,17 @@ static int __init bttv_init_module(void)
5013 printk(KERN_WARNING "bttv: bus_register error: %d\n", ret); 4622 printk(KERN_WARNING "bttv: bus_register error: %d\n", ret);
5014 return ret; 4623 return ret;
5015 } 4624 }
5016 return pci_register_driver(&bttv_pci_driver); 4625 ret = pci_register_driver(&bttv_pci_driver);
4626 if (ret < 0)
4627 bus_unregister(&bttv_sub_bus_type);
4628
4629 return ret;
5017} 4630}
5018 4631
5019static void __exit bttv_cleanup_module(void) 4632static void __exit bttv_cleanup_module(void)
5020{ 4633{
5021 pci_unregister_driver(&bttv_pci_driver); 4634 pci_unregister_driver(&bttv_pci_driver);
5022 bus_unregister(&bttv_sub_bus_type); 4635 bus_unregister(&bttv_sub_bus_type);
5023 return;
5024} 4636}
5025 4637
5026module_init(bttv_init_module); 4638module_init(bttv_init_module);
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index e7c521b8444a..fc9ecb21eec6 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -69,6 +69,11 @@ static void ir_handle_key(struct bttv *btv)
69 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { 69 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
70 ir_input_keydown(ir->dev,&ir->ir,data,data); 70 ir_input_keydown(ir->dev,&ir->ir,data,data);
71 } else { 71 } else {
72 /* HACK: Probably, ir->mask_keydown is missing
73 for this board */
74 if (btv->c.type == BTTV_BOARD_WINFAST2000)
75 ir_input_keydown(ir->dev, &ir->ir, data, data);
76
72 ir_input_nokey(ir->dev,&ir->ir); 77 ir_input_nokey(ir->dev,&ir->ir);
73 } 78 }
74 79
diff --git a/drivers/media/video/bt8xx/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c
index 58986f1a5f1a..e5979f77504c 100644
--- a/drivers/media/video/bt8xx/bttv-risc.c
+++ b/drivers/media/video/bt8xx/bttv-risc.c
@@ -582,7 +582,7 @@ bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf
582 videobuf_dma_free(dma); 582 videobuf_dma_free(dma);
583 btcx_riscmem_free(btv->c.pci,&buf->bottom); 583 btcx_riscmem_free(btv->c.pci,&buf->bottom);
584 btcx_riscmem_free(btv->c.pci,&buf->top); 584 btcx_riscmem_free(btv->c.pci,&buf->top);
585 buf->vb.state = STATE_NEEDS_INIT; 585 buf->vb.state = VIDEOBUF_NEEDS_INIT;
586} 586}
587 587
588int 588int
@@ -602,7 +602,7 @@ bttv_buffer_activate_vbi(struct bttv *btv,
602 if (vbi) { 602 if (vbi) {
603 unsigned int crop, vdelay; 603 unsigned int crop, vdelay;
604 604
605 vbi->vb.state = STATE_ACTIVE; 605 vbi->vb.state = VIDEOBUF_ACTIVE;
606 list_del(&vbi->vb.queue); 606 list_del(&vbi->vb.queue);
607 607
608 /* VDELAY is start of video, end of VBI capturing. */ 608 /* VDELAY is start of video, end of VBI capturing. */
@@ -644,12 +644,12 @@ bttv_buffer_activate_video(struct bttv *btv,
644 /* video capture */ 644 /* video capture */
645 if (NULL != set->top && NULL != set->bottom) { 645 if (NULL != set->top && NULL != set->bottom) {
646 if (set->top == set->bottom) { 646 if (set->top == set->bottom) {
647 set->top->vb.state = STATE_ACTIVE; 647 set->top->vb.state = VIDEOBUF_ACTIVE;
648 if (set->top->vb.queue.next) 648 if (set->top->vb.queue.next)
649 list_del(&set->top->vb.queue); 649 list_del(&set->top->vb.queue);
650 } else { 650 } else {
651 set->top->vb.state = STATE_ACTIVE; 651 set->top->vb.state = VIDEOBUF_ACTIVE;
652 set->bottom->vb.state = STATE_ACTIVE; 652 set->bottom->vb.state = VIDEOBUF_ACTIVE;
653 if (set->top->vb.queue.next) 653 if (set->top->vb.queue.next)
654 list_del(&set->top->vb.queue); 654 list_del(&set->top->vb.queue);
655 if (set->bottom->vb.queue.next) 655 if (set->bottom->vb.queue.next)
@@ -666,7 +666,7 @@ bttv_buffer_activate_video(struct bttv *btv,
666 btaor((set->top->btswap & 0x0a) | (set->bottom->btswap & 0x05), 666 btaor((set->top->btswap & 0x0a) | (set->bottom->btswap & 0x05),
667 ~0x0f, BT848_COLOR_CTL); 667 ~0x0f, BT848_COLOR_CTL);
668 } else if (NULL != set->top) { 668 } else if (NULL != set->top) {
669 set->top->vb.state = STATE_ACTIVE; 669 set->top->vb.state = VIDEOBUF_ACTIVE;
670 if (set->top->vb.queue.next) 670 if (set->top->vb.queue.next)
671 list_del(&set->top->vb.queue); 671 list_del(&set->top->vb.queue);
672 bttv_apply_geo(btv, &set->top->geo,1); 672 bttv_apply_geo(btv, &set->top->geo,1);
@@ -677,7 +677,7 @@ bttv_buffer_activate_video(struct bttv *btv,
677 btaor(set->top->btformat & 0xff, ~0xff, BT848_COLOR_FMT); 677 btaor(set->top->btformat & 0xff, ~0xff, BT848_COLOR_FMT);
678 btaor(set->top->btswap & 0x0f, ~0x0f, BT848_COLOR_CTL); 678 btaor(set->top->btswap & 0x0f, ~0x0f, BT848_COLOR_CTL);
679 } else if (NULL != set->bottom) { 679 } else if (NULL != set->bottom) {
680 set->bottom->vb.state = STATE_ACTIVE; 680 set->bottom->vb.state = VIDEOBUF_ACTIVE;
681 if (set->bottom->vb.queue.next) 681 if (set->bottom->vb.queue.next)
682 list_del(&set->bottom->vb.queue); 682 list_del(&set->bottom->vb.queue);
683 bttv_apply_geo(btv, &set->bottom->geo,1); 683 bttv_apply_geo(btv, &set->bottom->geo,1);
diff --git a/drivers/media/video/bt8xx/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
index 346ce019bdcb..1f0cc79e2a33 100644
--- a/drivers/media/video/bt8xx/bttv-vbi.c
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -142,7 +142,7 @@ static int vbi_buffer_prepare(struct videobuf_queue *q,
142 redo_dma_risc = 1; 142 redo_dma_risc = 1;
143 } 143 }
144 144
145 if (STATE_NEEDS_INIT == buf->vb.state) { 145 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
146 redo_dma_risc = 1; 146 redo_dma_risc = 1;
147 if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL))) 147 if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL)))
148 goto fail; 148 goto fail;
@@ -189,7 +189,7 @@ static int vbi_buffer_prepare(struct videobuf_queue *q,
189 /* For bttv_buffer_activate_vbi(). */ 189 /* For bttv_buffer_activate_vbi(). */
190 buf->geo.vdelay = min_vdelay; 190 buf->geo.vdelay = min_vdelay;
191 191
192 buf->vb.state = STATE_PREPARED; 192 buf->vb.state = VIDEOBUF_PREPARED;
193 buf->vb.field = field; 193 buf->vb.field = field;
194 dprintk("buf prepare %p: top=%p bottom=%p field=%s\n", 194 dprintk("buf prepare %p: top=%p bottom=%p field=%s\n",
195 vb, &buf->top, &buf->bottom, 195 vb, &buf->top, &buf->bottom,
@@ -209,7 +209,7 @@ vbi_buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
209 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); 209 struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb);
210 210
211 dprintk("queue %p\n",vb); 211 dprintk("queue %p\n",vb);
212 buf->vb.state = STATE_QUEUED; 212 buf->vb.state = VIDEOBUF_QUEUED;
213 list_add_tail(&buf->vb.queue,&btv->vcapture); 213 list_add_tail(&buf->vb.queue,&btv->vcapture);
214 if (NULL == btv->cvbi) { 214 if (NULL == btv->cvbi) {
215 fh->btv->loop_irq |= 4; 215 fh->btv->loop_irq |= 4;
@@ -236,10 +236,8 @@ struct videobuf_queue_ops bttv_vbi_qops = {
236 236
237/* ----------------------------------------------------------------------- */ 237/* ----------------------------------------------------------------------- */
238 238
239static int 239static int try_fmt(struct v4l2_vbi_format *f, const struct bttv_tvnorm *tvnorm,
240try_fmt (struct v4l2_vbi_format * f, 240 __s32 crop_start)
241 const struct bttv_tvnorm * tvnorm,
242 __s32 crop_start)
243{ 241{
244 __s32 min_start, max_start, max_end, f2_offset; 242 __s32 min_start, max_start, max_end, f2_offset;
245 unsigned int i; 243 unsigned int i;
@@ -305,10 +303,9 @@ try_fmt (struct v4l2_vbi_format * f,
305 return 0; 303 return 0;
306} 304}
307 305
308int 306int bttv_try_fmt_vbi(struct file *file, void *f, struct v4l2_format *frt)
309bttv_vbi_try_fmt (struct bttv_fh * fh,
310 struct v4l2_vbi_format * f)
311{ 307{
308 struct bttv_fh *fh = f;
312 struct bttv *btv = fh->btv; 309 struct bttv *btv = fh->btv;
313 const struct bttv_tvnorm *tvnorm; 310 const struct bttv_tvnorm *tvnorm;
314 __s32 crop_start; 311 __s32 crop_start;
@@ -320,13 +317,13 @@ bttv_vbi_try_fmt (struct bttv_fh * fh,
320 317
321 mutex_unlock(&btv->lock); 318 mutex_unlock(&btv->lock);
322 319
323 return try_fmt(f, tvnorm, crop_start); 320 return try_fmt(&frt->fmt.vbi, tvnorm, crop_start);
324} 321}
325 322
326int 323
327bttv_vbi_set_fmt (struct bttv_fh * fh, 324int bttv_s_fmt_vbi(struct file *file, void *f, struct v4l2_format *frt)
328 struct v4l2_vbi_format * f)
329{ 325{
326 struct bttv_fh *fh = f;
330 struct bttv *btv = fh->btv; 327 struct bttv *btv = fh->btv;
331 const struct bttv_tvnorm *tvnorm; 328 const struct bttv_tvnorm *tvnorm;
332 __s32 start1, end; 329 __s32 start1, end;
@@ -340,11 +337,12 @@ bttv_vbi_set_fmt (struct bttv_fh * fh,
340 337
341 tvnorm = &bttv_tvnorms[btv->tvnorm]; 338 tvnorm = &bttv_tvnorms[btv->tvnorm];
342 339
343 rc = try_fmt(f, tvnorm, btv->crop_start); 340 rc = try_fmt(&frt->fmt.vbi, tvnorm, btv->crop_start);
344 if (0 != rc) 341 if (0 != rc)
345 goto fail; 342 goto fail;
346 343
347 start1 = f->start[1] - tvnorm->vbistart[1] + tvnorm->vbistart[0]; 344 start1 = frt->fmt.vbi.start[1] - tvnorm->vbistart[1] +
345 tvnorm->vbistart[0];
348 346
349 /* First possible line of video capturing. Should be 347 /* First possible line of video capturing. Should be
350 max(f->start[0] + f->count[0], start1 + f->count[1]) * 2 348 max(f->start[0] + f->count[0], start1 + f->count[1]) * 2
@@ -352,11 +350,11 @@ bttv_vbi_set_fmt (struct bttv_fh * fh,
352 pretend the VBI and video capture window may overlap, 350 pretend the VBI and video capture window may overlap,
353 so end = start + 1, the lowest possible value, times two 351 so end = start + 1, the lowest possible value, times two
354 because vbi_fmt.end counts field lines times two. */ 352 because vbi_fmt.end counts field lines times two. */
355 end = max(f->start[0], start1) * 2 + 2; 353 end = max(frt->fmt.vbi.start[0], start1) * 2 + 2;
356 354
357 mutex_lock(&fh->vbi.lock); 355 mutex_lock(&fh->vbi.lock);
358 356
359 fh->vbi_fmt.fmt = *f; 357 fh->vbi_fmt.fmt = frt->fmt.vbi;
360 fh->vbi_fmt.tvnorm = tvnorm; 358 fh->vbi_fmt.tvnorm = tvnorm;
361 fh->vbi_fmt.end = end; 359 fh->vbi_fmt.end = end;
362 360
@@ -370,13 +368,13 @@ bttv_vbi_set_fmt (struct bttv_fh * fh,
370 return rc; 368 return rc;
371} 369}
372 370
373void 371
374bttv_vbi_get_fmt (struct bttv_fh * fh, 372int bttv_g_fmt_vbi(struct file *file, void *f, struct v4l2_format *frt)
375 struct v4l2_vbi_format * f)
376{ 373{
374 struct bttv_fh *fh = f;
377 const struct bttv_tvnorm *tvnorm; 375 const struct bttv_tvnorm *tvnorm;
378 376
379 *f = fh->vbi_fmt.fmt; 377 frt->fmt.vbi = fh->vbi_fmt.fmt;
380 378
381 tvnorm = &bttv_tvnorms[fh->btv->tvnorm]; 379 tvnorm = &bttv_tvnorms[fh->btv->tvnorm];
382 380
@@ -391,28 +389,28 @@ bttv_vbi_get_fmt (struct bttv_fh * fh,
391 max_end = (tvnorm->cropcap.bounds.top 389 max_end = (tvnorm->cropcap.bounds.top
392 + tvnorm->cropcap.bounds.height) >> 1; 390 + tvnorm->cropcap.bounds.height) >> 1;
393 391
394 f->sampling_rate = tvnorm->Fsc; 392 frt->fmt.vbi.sampling_rate = tvnorm->Fsc;
395 393
396 for (i = 0; i < 2; ++i) { 394 for (i = 0; i < 2; ++i) {
397 __s32 new_start; 395 __s32 new_start;
398 396
399 new_start = f->start[i] 397 new_start = frt->fmt.vbi.start[i]
400 + tvnorm->vbistart[i] 398 + tvnorm->vbistart[i]
401 - fh->vbi_fmt.tvnorm->vbistart[i]; 399 - fh->vbi_fmt.tvnorm->vbistart[i];
402 400
403 f->start[i] = min(new_start, max_end - 1); 401 frt->fmt.vbi.start[i] = min(new_start, max_end - 1);
404 f->count[i] = min((__s32) f->count[i], 402 frt->fmt.vbi.count[i] =
405 max_end - f->start[i]); 403 min((__s32) frt->fmt.vbi.count[i],
404 max_end - frt->fmt.vbi.start[i]);
406 405
407 max_end += tvnorm->vbistart[1] 406 max_end += tvnorm->vbistart[1]
408 - tvnorm->vbistart[0]; 407 - tvnorm->vbistart[0];
409 } 408 }
410 } 409 }
410 return 0;
411} 411}
412 412
413void 413void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, int norm)
414bttv_vbi_fmt_reset (struct bttv_vbi_fmt * f,
415 int norm)
416{ 414{
417 const struct bttv_tvnorm *tvnorm; 415 const struct bttv_tvnorm *tvnorm;
418 unsigned int real_samples_per_line; 416 unsigned int real_samples_per_line;
diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h
index 19e75d50a107..bf4c339a520c 100644
--- a/drivers/media/video/bt8xx/bttv.h
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -241,7 +241,10 @@ struct tvcard
241 unsigned int radio_addr; 241 unsigned int radio_addr;
242 242
243 unsigned int has_radio; 243 unsigned int has_radio;
244 void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set); 244
245 void (*volume_gpio)(struct bttv *btv, __u16 volume);
246 void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
247
245 void (*muxsel_hook)(struct bttv *btv, unsigned int input); 248 void (*muxsel_hook)(struct bttv *btv, unsigned int input);
246}; 249};
247 250
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index d4ac4c4b49b4..1305d315cfc5 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -84,6 +84,11 @@
84 84
85#define clamp(x, low, high) min (max (low, x), high) 85#define clamp(x, low, high) min (max (low, x), high)
86 86
87#define BTTV_NORMS (\
88 V4L2_STD_PAL | V4L2_STD_PAL_N | \
89 V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
90 V4L2_STD_NTSC | V4L2_STD_PAL_M | \
91 V4L2_STD_PAL_60)
87/* ---------------------------------------------------------- */ 92/* ---------------------------------------------------------- */
88 93
89struct bttv_tvnorm { 94struct bttv_tvnorm {
@@ -112,7 +117,6 @@ extern const struct bttv_tvnorm bttv_tvnorms[];
112 117
113struct bttv_format { 118struct bttv_format {
114 char *name; 119 char *name;
115 int palette; /* video4linux 1 */
116 int fourcc; /* video4linux 2 */ 120 int fourcc; /* video4linux 2 */
117 int btformat; /* BT848_COLOR_FMT_* */ 121 int btformat; /* BT848_COLOR_FMT_* */
118 int btswap; /* BT848_COLOR_CTL_* */ 122 int btswap; /* BT848_COLOR_CTL_* */
@@ -253,9 +257,9 @@ int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
253/* ---------------------------------------------------------- */ 257/* ---------------------------------------------------------- */
254/* bttv-vbi.c */ 258/* bttv-vbi.c */
255 259
256int bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_vbi_format *f); 260int bttv_try_fmt_vbi(struct file *file, void *fh, struct v4l2_format *f);
257void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_vbi_format *f); 261int bttv_g_fmt_vbi(struct file *file, void *fh, struct v4l2_format *f);
258int bttv_vbi_set_fmt(struct bttv_fh *fh, struct v4l2_vbi_format *f); 262int bttv_s_fmt_vbi(struct file *file, void *fh, struct v4l2_format *f);
259 263
260extern struct videobuf_queue_ops bttv_vbi_qops; 264extern struct videobuf_queue_ops bttv_vbi_qops;
261 265
@@ -337,7 +341,9 @@ struct bttv {
337 /* old gpio interface */ 341 /* old gpio interface */
338 wait_queue_head_t gpioq; 342 wait_queue_head_t gpioq;
339 int shutdown; 343 int shutdown;
340 void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set); 344
345 void (*volume_gpio)(struct bttv *btv, __u16 volume);
346 void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
341 347
342 /* new gpio interface */ 348 /* new gpio interface */
343 spinlock_t gpio_lock; 349 spinlock_t gpio_lock;
@@ -458,10 +464,6 @@ struct bttv {
458extern unsigned int bttv_num; 464extern unsigned int bttv_num;
459extern struct bttv bttvs[BTTV_MAX]; 465extern struct bttv bttvs[BTTV_MAX];
460 466
461/* private ioctls */
462#define BTTV_VERSION _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
463#define BTTV_VBISIZE _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
464
465#endif 467#endif
466 468
467#define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr)) 469#define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index 58423525591f..032265383df2 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -82,11 +82,16 @@ OTHER DEALINGS IN THE SOFTWARE.
82static unsigned int maxpoll=250; /* Maximum busy-loop count for qcam I/O */ 82static unsigned int maxpoll=250; /* Maximum busy-loop count for qcam I/O */
83static unsigned int yieldlines=4; /* Yield after this many during capture */ 83static unsigned int yieldlines=4; /* Yield after this many during capture */
84static int video_nr = -1; 84static int video_nr = -1;
85static unsigned int force_init; /* Whether to probe aggressively */
85 86
86module_param(maxpoll, int, 0); 87module_param(maxpoll, int, 0);
87module_param(yieldlines, int, 0); 88module_param(yieldlines, int, 0);
88module_param(video_nr, int, 0); 89module_param(video_nr, int, 0);
89 90
91/* Set force_init=1 to avoid detection by polling status register and
92 * immediately attempt to initialize qcam */
93module_param(force_init, int, 0);
94
90static inline int read_lpstatus(struct qcam_device *q) 95static inline int read_lpstatus(struct qcam_device *q)
91{ 96{
92 return parport_read_status(q->pport); 97 return parport_read_status(q->pport);
@@ -331,6 +336,9 @@ static int qc_detect(struct qcam_device *q)
331 int count = 0; 336 int count = 0;
332 int i; 337 int i;
333 338
339 if (force_init)
340 return 1;
341
334 lastreg = reg = read_lpstatus(q) & 0xf0; 342 lastreg = reg = read_lpstatus(q) & 0xf0;
335 343
336 for (i = 0; i < 500; i++) 344 for (i = 0; i < 500; i++)
@@ -354,12 +362,12 @@ static int qc_detect(struct qcam_device *q)
354 362
355 /* Be (even more) liberal in what you accept... */ 363 /* Be (even more) liberal in what you accept... */
356 364
357/* if (count > 30 && count < 200) */
358 if (count > 20 && count < 400) { 365 if (count > 20 && count < 400) {
359 return 1; /* found */ 366 return 1; /* found */
360 } else { 367 } else {
361 printk(KERN_ERR "No Quickcam found on port %s\n", 368 printk(KERN_ERR "No Quickcam found on port %s\n",
362 q->pport->name); 369 q->pport->name);
370 printk(KERN_DEBUG "Quickcam detection counter: %u\n", count);
363 return 0; /* not found */ 371 return 0; /* not found */
364 } 372 }
365} 373}
diff --git a/drivers/media/video/cs5345.c b/drivers/media/video/cs5345.c
new file mode 100644
index 000000000000..fae469ce16f5
--- /dev/null
+++ b/drivers/media/video/cs5345.c
@@ -0,0 +1,168 @@
1/*
2 * cs5345 Cirrus Logic 24-bit, 192 kHz Stereo Audio ADC
3 * Copyright (C) 2007 Hans Verkuil
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21#include <linux/version.h>
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/i2c.h>
25#include <linux/videodev2.h>
26#include <media/v4l2-i2c-drv.h>
27#include <media/v4l2-common.h>
28#include <media/v4l2-chip-ident.h>
29
30MODULE_DESCRIPTION("i2c device driver for cs5345 Audio ADC");
31MODULE_AUTHOR("Hans Verkuil");
32MODULE_LICENSE("GPL");
33
34static int debug;
35
36module_param(debug, bool, 0644);
37
38MODULE_PARM_DESC(debug, "Debugging messages\n\t\t\t0=Off (default), 1=On");
39
40
41/* ----------------------------------------------------------------------- */
42
43static inline int cs5345_write(struct i2c_client *client, u8 reg, u8 value)
44{
45 return i2c_smbus_write_byte_data(client, reg, value);
46}
47
48static inline int cs5345_read(struct i2c_client *client, u8 reg)
49{
50 return i2c_smbus_read_byte_data(client, reg);
51}
52
53static int cs5345_command(struct i2c_client *client, unsigned cmd, void *arg)
54{
55 struct v4l2_routing *route = arg;
56 struct v4l2_control *ctrl = arg;
57
58 switch (cmd) {
59 case VIDIOC_INT_G_AUDIO_ROUTING:
60 route->input = cs5345_read(client, 0x09) & 7;
61 route->input |= cs5345_read(client, 0x05) & 0x70;
62 route->output = 0;
63 break;
64
65 case VIDIOC_INT_S_AUDIO_ROUTING:
66 if ((route->input & 0xf) > 6) {
67 v4l_err(client, "Invalid input %d.\n", route->input);
68 return -EINVAL;
69 }
70 cs5345_write(client, 0x09, route->input & 0xf);
71 cs5345_write(client, 0x05, route->input & 0xf0);
72 break;
73
74 case VIDIOC_G_CTRL:
75 if (ctrl->id == V4L2_CID_AUDIO_MUTE) {
76 ctrl->value = (cs5345_read(client, 0x04) & 0x08) != 0;
77 break;
78 }
79 if (ctrl->id != V4L2_CID_AUDIO_VOLUME)
80 return -EINVAL;
81 ctrl->value = cs5345_read(client, 0x07) & 0x3f;
82 if (ctrl->value >= 32)
83 ctrl->value = ctrl->value - 64;
84 break;
85
86 case VIDIOC_S_CTRL:
87 break;
88 if (ctrl->id == V4L2_CID_AUDIO_MUTE) {
89 cs5345_write(client, 0x04, ctrl->value ? 0x80 : 0);
90 break;
91 }
92 if (ctrl->id != V4L2_CID_AUDIO_VOLUME)
93 return -EINVAL;
94 if (ctrl->value > 24 || ctrl->value < -24)
95 return -EINVAL;
96 cs5345_write(client, 0x07, ((u8)ctrl->value) & 0x3f);
97 cs5345_write(client, 0x08, ((u8)ctrl->value) & 0x3f);
98 break;
99
100#ifdef CONFIG_VIDEO_ADV_DEBUG
101 case VIDIOC_DBG_G_REGISTER:
102 case VIDIOC_DBG_S_REGISTER:
103 {
104 struct v4l2_register *reg = arg;
105
106 if (!v4l2_chip_match_i2c_client(client,
107 reg->match_type, reg->match_chip))
108 return -EINVAL;
109 if (!capable(CAP_SYS_ADMIN))
110 return -EPERM;
111 if (cmd == VIDIOC_DBG_G_REGISTER)
112 reg->val = cs5345_read(client, reg->reg & 0x1f);
113 else
114 cs5345_write(client, reg->reg & 0x1f, reg->val & 0x1f);
115 break;
116 }
117#endif
118
119 case VIDIOC_G_CHIP_IDENT:
120 return v4l2_chip_ident_i2c_client(client,
121 arg, V4L2_IDENT_CS5345, 0);
122
123 case VIDIOC_LOG_STATUS:
124 {
125 u8 v = cs5345_read(client, 0x09) & 7;
126 u8 m = cs5345_read(client, 0x04);
127 int vol = cs5345_read(client, 0x08) & 0x3f;
128
129 v4l_info(client, "Input: %d%s\n", v,
130 (m & 0x80) ? " (muted)" : "");
131 if (vol >= 32)
132 vol = vol - 64;
133 v4l_info(client, "Volume: %d dB\n", vol);
134 break;
135 }
136
137 default:
138 return -EINVAL;
139 }
140 return 0;
141}
142
143/* ----------------------------------------------------------------------- */
144
145static int cs5345_probe(struct i2c_client *client)
146{
147 /* Check if the adapter supports the needed features */
148 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
149 return -EIO;
150
151 v4l_info(client, "chip found @ 0x%x (%s)\n",
152 client->addr << 1, client->adapter->name);
153
154 cs5345_write(client, 0x02, 0x00);
155 cs5345_write(client, 0x04, 0x01);
156 cs5345_write(client, 0x09, 0x01);
157 return 0;
158}
159
160/* ----------------------------------------------------------------------- */
161
162static struct v4l2_i2c_driver_data v4l2_i2c_data = {
163 .name = "cs5345",
164 .driverid = I2C_DRIVERID_CS5345,
165 .command = cs5345_command,
166 .probe = cs5345_probe,
167};
168
diff --git a/drivers/media/video/cs53l32a.c b/drivers/media/video/cs53l32a.c
index a73e285af730..f41bfde045fe 100644
--- a/drivers/media/video/cs53l32a.c
+++ b/drivers/media/video/cs53l32a.c
@@ -29,12 +29,13 @@
29#include <linux/videodev.h> 29#include <linux/videodev.h>
30#include <media/v4l2-common.h> 30#include <media/v4l2-common.h>
31#include <media/v4l2-chip-ident.h> 31#include <media/v4l2-chip-ident.h>
32#include <media/v4l2-i2c-drv-legacy.h>
32 33
33MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC"); 34MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC");
34MODULE_AUTHOR("Martin Vaughan"); 35MODULE_AUTHOR("Martin Vaughan");
35MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
36 37
37static int debug = 0; 38static int debug;
38 39
39module_param(debug, bool, 0644); 40module_param(debug, bool, 0644);
40 41
@@ -57,8 +58,7 @@ static int cs53l32a_read(struct i2c_client *client, u8 reg)
57 return i2c_smbus_read_byte_data(client, reg); 58 return i2c_smbus_read_byte_data(client, reg);
58} 59}
59 60
60static int cs53l32a_command(struct i2c_client *client, unsigned int cmd, 61static int cs53l32a_command(struct i2c_client *client, unsigned cmd, void *arg)
61 void *arg)
62{ 62{
63 struct v4l2_routing *route = arg; 63 struct v4l2_routing *route = arg;
64 struct v4l2_control *ctrl = arg; 64 struct v4l2_control *ctrl = arg;
@@ -105,7 +105,8 @@ static int cs53l32a_command(struct i2c_client *client, unsigned int cmd,
105 break; 105 break;
106 106
107 case VIDIOC_G_CHIP_IDENT: 107 case VIDIOC_G_CHIP_IDENT:
108 return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_CS53l32A, 0); 108 return v4l2_chip_ident_i2c_client(client,
109 arg, V4L2_IDENT_CS53l32A, 0);
109 110
110 case VIDIOC_LOG_STATUS: 111 case VIDIOC_LOG_STATUS:
111 { 112 {
@@ -134,27 +135,18 @@ static int cs53l32a_command(struct i2c_client *client, unsigned int cmd,
134 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 135 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
135 */ 136 */
136 137
137static struct i2c_driver i2c_driver; 138static int cs53l32a_probe(struct i2c_client *client)
138
139static int cs53l32a_attach(struct i2c_adapter *adapter, int address, int kind)
140{ 139{
141 struct i2c_client *client;
142 int i; 140 int i;
143 141
144 /* Check if the adapter supports the needed features */ 142 /* Check if the adapter supports the needed features */
145 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 143 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
146 return 0; 144 return -EIO;
147
148 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
149 if (client == 0)
150 return -ENOMEM;
151 145
152 client->addr = address;
153 client->adapter = adapter;
154 client->driver = &i2c_driver;
155 snprintf(client->name, sizeof(client->name) - 1, "cs53l32a"); 146 snprintf(client->name, sizeof(client->name) - 1, "cs53l32a");
156 147
157 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name); 148 v4l_info(client, "chip found @ 0x%x (%s)\n",
149 client->addr << 1, client->adapter->name);
158 150
159 for (i = 1; i <= 7; i++) { 151 for (i = 1; i <= 7; i++) {
160 u8 v = cs53l32a_read(client, i); 152 u8 v = cs53l32a_read(client, i);
@@ -179,55 +171,13 @@ static int cs53l32a_attach(struct i2c_adapter *adapter, int address, int kind)
179 171
180 v4l_dbg(1, debug, client, "Read Reg %d %02x\n", i, v); 172 v4l_dbg(1, debug, client, "Read Reg %d %02x\n", i, v);
181 } 173 }
182
183 i2c_attach_client(client);
184
185 return 0; 174 return 0;
186} 175}
187 176
188static int cs53l32a_probe(struct i2c_adapter *adapter) 177static struct v4l2_i2c_driver_data v4l2_i2c_data = {
189{ 178 .name = "cs53l32a",
190 if (adapter->class & I2C_CLASS_TV_ANALOG) 179 .driverid = I2C_DRIVERID_CS53L32A,
191 return i2c_probe(adapter, &addr_data, cs53l32a_attach);
192 return 0;
193}
194
195static int cs53l32a_detach(struct i2c_client *client)
196{
197 int err;
198
199 err = i2c_detach_client(client);
200 if (err) {
201 return err;
202 }
203 kfree(client);
204
205 return 0;
206}
207
208/* ----------------------------------------------------------------------- */
209
210/* i2c implementation */
211static struct i2c_driver i2c_driver = {
212 .driver = {
213 .name = "cs53l32a",
214 },
215 .id = I2C_DRIVERID_CS53L32A,
216 .attach_adapter = cs53l32a_probe,
217 .detach_client = cs53l32a_detach,
218 .command = cs53l32a_command, 180 .command = cs53l32a_command,
181 .probe = cs53l32a_probe,
219}; 182};
220 183
221
222static int __init cs53l32a_init_module(void)
223{
224 return i2c_add_driver(&i2c_driver);
225}
226
227static void __exit cs53l32a_cleanup_module(void)
228{
229 i2c_del_driver(&i2c_driver);
230}
231
232module_init(cs53l32a_init_module);
233module_exit(cs53l32a_cleanup_module);
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 62304255dcae..c592899a2317 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -34,7 +34,7 @@ MODULE_DESCRIPTION("cx23415/6 driver");
34MODULE_AUTHOR("Hans Verkuil"); 34MODULE_AUTHOR("Hans Verkuil");
35MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
36 36
37static int debug = 0; 37static int debug;
38module_param(debug, int, 0644); 38module_param(debug, int, 0644);
39MODULE_PARM_DESC(debug, "Debug level (0-1)"); 39MODULE_PARM_DESC(debug, "Debug level (0-1)");
40 40
@@ -75,6 +75,7 @@ const u32 cx2341x_mpeg_ctrls[] = {
75 V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS, 75 V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS,
76 0 76 0
77}; 77};
78EXPORT_SYMBOL(cx2341x_mpeg_ctrls);
78 79
79 80
80/* Map the control ID to the correct field in the cx2341x_mpeg_params 81/* Map the control ID to the correct field in the cx2341x_mpeg_params
@@ -281,13 +282,14 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, int busy,
281 return -EBUSY; 282 return -EBUSY;
282 params->stream_type = ctrl->value; 283 params->stream_type = ctrl->value;
283 params->video_encoding = 284 params->video_encoding =
284 (params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_SS || 285 (params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_SS ||
285 params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_VCD) ? 286 params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_VCD) ?
286 V4L2_MPEG_VIDEO_ENCODING_MPEG_1 : V4L2_MPEG_VIDEO_ENCODING_MPEG_2; 287 V4L2_MPEG_VIDEO_ENCODING_MPEG_1 :
287 if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) { 288 V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
289 if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
288 /* MPEG-1 implies CBR */ 290 /* MPEG-1 implies CBR */
289 params->video_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR; 291 params->video_bitrate_mode =
290 } 292 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR;
291 break; 293 break;
292 case V4L2_CID_MPEG_STREAM_VBI_FMT: 294 case V4L2_CID_MPEG_STREAM_VBI_FMT:
293 params->stream_vbi_fmt = ctrl->value; 295 params->stream_vbi_fmt = ctrl->value;
@@ -334,7 +336,8 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, int busy,
334 return 0; 336 return 0;
335} 337}
336 338
337static int cx2341x_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def) 339static int cx2341x_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
340 s32 min, s32 max, s32 step, s32 def)
338{ 341{
339 const char *name; 342 const char *name;
340 343
@@ -417,7 +420,8 @@ static int cx2341x_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 ma
417 return 0; 420 return 0;
418} 421}
419 422
420int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params, struct v4l2_queryctrl *qctrl) 423int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params,
424 struct v4l2_queryctrl *qctrl)
421{ 425{
422 int err; 426 int err;
423 427
@@ -440,7 +444,8 @@ int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params, struct v4l2_queryctrl
440 444
441 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: 445 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
442 err = v4l2_ctrl_query_fill_std(qctrl); 446 err = v4l2_ctrl_query_fill_std(qctrl);
443 if (err == 0 && params->audio_mode != V4L2_MPEG_AUDIO_MODE_JOINT_STEREO) 447 if (err == 0 &&
448 params->audio_mode != V4L2_MPEG_AUDIO_MODE_JOINT_STEREO)
444 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 449 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
445 return err; 450 return err;
446 451
@@ -455,13 +460,16 @@ int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params, struct v4l2_queryctrl
455 460
456 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 461 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
457 err = v4l2_ctrl_query_fill_std(qctrl); 462 err = v4l2_ctrl_query_fill_std(qctrl);
458 if (err == 0 && params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) 463 if (err == 0 &&
464 params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
459 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 465 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
460 return err; 466 return err;
461 467
462 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: 468 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
463 err = v4l2_ctrl_query_fill_std(qctrl); 469 err = v4l2_ctrl_query_fill_std(qctrl);
464 if (err == 0 && params->video_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) 470 if (err == 0 &&
471 params->video_bitrate_mode ==
472 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
465 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 473 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
466 return err; 474 return err;
467 475
@@ -476,80 +484,90 @@ int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params, struct v4l2_queryctrl
476 /* CX23415/6 specific */ 484 /* CX23415/6 specific */
477 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: 485 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
478 return cx2341x_ctrl_query_fill(qctrl, 486 return cx2341x_ctrl_query_fill(qctrl,
479 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL, 487 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL,
480 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO, 1, 488 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO, 1,
481 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL); 489 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL);
482 490
483 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER: 491 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER:
484 cx2341x_ctrl_query_fill(qctrl, 0, 15, 1, 0); 492 cx2341x_ctrl_query_fill(qctrl, 0, 15, 1, 0);
485 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; 493 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
486 if (params->video_spatial_filter_mode == V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO) 494 if (params->video_spatial_filter_mode ==
487 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 495 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO)
496 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
488 return 0; 497 return 0;
489 498
490 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE: 499 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE:
491 cx2341x_ctrl_query_fill(qctrl, 500 cx2341x_ctrl_query_fill(qctrl,
492 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF, 501 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF,
493 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE, 1, 502 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE,
494 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF); 503 1,
495 if (params->video_spatial_filter_mode == V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO) 504 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF);
496 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 505 if (params->video_spatial_filter_mode ==
506 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO)
507 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
497 return 0; 508 return 0;
498 509
499 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE: 510 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE:
500 cx2341x_ctrl_query_fill(qctrl, 511 cx2341x_ctrl_query_fill(qctrl,
501 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF, 512 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF,
502 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR, 1, 513 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR,
503 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF); 514 1,
504 if (params->video_spatial_filter_mode == V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO) 515 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF);
505 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 516 if (params->video_spatial_filter_mode ==
517 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO)
518 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
506 return 0; 519 return 0;
507 520
508 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: 521 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE:
509 return cx2341x_ctrl_query_fill(qctrl, 522 return cx2341x_ctrl_query_fill(qctrl,
510 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL, 523 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL,
511 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO, 1, 524 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO, 1,
512 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL); 525 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL);
513 526
514 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER: 527 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER:
515 cx2341x_ctrl_query_fill(qctrl, 0, 31, 1, 0); 528 cx2341x_ctrl_query_fill(qctrl, 0, 31, 1, 0);
516 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; 529 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
517 if (params->video_temporal_filter_mode == V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO) 530 if (params->video_temporal_filter_mode ==
518 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 531 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO)
532 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
519 return 0; 533 return 0;
520 534
521 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: 535 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE:
522 return cx2341x_ctrl_query_fill(qctrl, 536 return cx2341x_ctrl_query_fill(qctrl,
523 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF, 537 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF,
524 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG, 1, 538 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG, 1,
525 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF); 539 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF);
526 540
527 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP: 541 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP:
528 cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 255); 542 cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 255);
529 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; 543 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
530 if (params->video_median_filter_type == V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF) 544 if (params->video_median_filter_type ==
531 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 545 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF)
546 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
532 return 0; 547 return 0;
533 548
534 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM: 549 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM:
535 cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 0); 550 cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 0);
536 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; 551 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
537 if (params->video_median_filter_type == V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF) 552 if (params->video_median_filter_type ==
538 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 553 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF)
554 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
539 return 0; 555 return 0;
540 556
541 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP: 557 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP:
542 cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 255); 558 cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 255);
543 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; 559 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
544 if (params->video_median_filter_type == V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF) 560 if (params->video_median_filter_type ==
545 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 561 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF)
562 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
546 return 0; 563 return 0;
547 564
548 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM: 565 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM:
549 cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 0); 566 cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 0);
550 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; 567 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
551 if (params->video_median_filter_type == V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF) 568 if (params->video_median_filter_type ==
552 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 569 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF)
570 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
553 return 0; 571 return 0;
554 572
555 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS: 573 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS:
@@ -560,6 +578,7 @@ int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params, struct v4l2_queryctrl
560 578
561 } 579 }
562} 580}
581EXPORT_SYMBOL(cx2341x_ctrl_query);
563 582
564const char **cx2341x_ctrl_get_menu(u32 id) 583const char **cx2341x_ctrl_get_menu(u32 id)
565{ 584{
@@ -629,6 +648,7 @@ const char **cx2341x_ctrl_get_menu(u32 id)
629 return v4l2_ctrl_get_menu(id); 648 return v4l2_ctrl_get_menu(id);
630 } 649 }
631} 650}
651EXPORT_SYMBOL(cx2341x_ctrl_get_menu);
632 652
633static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params) 653static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params)
634{ 654{
@@ -637,9 +657,8 @@ static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params)
637 ((1 + params->audio_l2_bitrate) << 4) | 657 ((1 + params->audio_l2_bitrate) << 4) |
638 (params->audio_mode << 8) | 658 (params->audio_mode << 8) |
639 (params->audio_mode_extension << 10) | 659 (params->audio_mode_extension << 10) |
640 (((params->audio_emphasis == V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17) ? 660 (((params->audio_emphasis == V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17)
641 3 : 661 ? 3 : params->audio_emphasis) << 12) |
642 params->audio_emphasis) << 12) |
643 (params->audio_crc << 14); 662 (params->audio_crc << 14);
644} 663}
645 664
@@ -679,19 +698,19 @@ int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int busy,
679 if (err) 698 if (err)
680 break; 699 break;
681 } 700 }
682 if (err == 0 && params->video_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR && 701 if (err == 0 &&
683 params->video_bitrate_peak < params->video_bitrate) { 702 params->video_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR &&
703 params->video_bitrate_peak < params->video_bitrate) {
684 err = -ERANGE; 704 err = -ERANGE;
685 ctrls->error_idx = ctrls->count; 705 ctrls->error_idx = ctrls->count;
686 } 706 }
687 if (err) { 707 if (err)
688 ctrls->error_idx = i; 708 ctrls->error_idx = i;
689 } 709 else
690 else {
691 cx2341x_calc_audio_properties(params); 710 cx2341x_calc_audio_properties(params);
692 }
693 return err; 711 return err;
694} 712}
713EXPORT_SYMBOL(cx2341x_ext_ctrls);
695 714
696void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p) 715void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p)
697{ 716{
@@ -732,13 +751,18 @@ void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p)
732 .video_mute_yuv = 0x008080, /* YCbCr value for black */ 751 .video_mute_yuv = 0x008080, /* YCbCr value for black */
733 752
734 /* encoding filters */ 753 /* encoding filters */
735 .video_spatial_filter_mode = V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL, 754 .video_spatial_filter_mode =
755 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL,
736 .video_spatial_filter = 0, 756 .video_spatial_filter = 0,
737 .video_luma_spatial_filter_type = V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR, 757 .video_luma_spatial_filter_type =
738 .video_chroma_spatial_filter_type = V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR, 758 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR,
739 .video_temporal_filter_mode = V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL, 759 .video_chroma_spatial_filter_type =
760 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR,
761 .video_temporal_filter_mode =
762 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL,
740 .video_temporal_filter = 8, 763 .video_temporal_filter = 8,
741 .video_median_filter_type = V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF, 764 .video_median_filter_type =
765 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF,
742 .video_luma_median_filter_top = 255, 766 .video_luma_median_filter_top = 255,
743 .video_luma_median_filter_bottom = 0, 767 .video_luma_median_filter_bottom = 0,
744 .video_chroma_median_filter_top = 255, 768 .video_chroma_median_filter_top = 255,
@@ -748,8 +772,10 @@ void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p)
748 *p = default_params; 772 *p = default_params;
749 cx2341x_calc_audio_properties(p); 773 cx2341x_calc_audio_properties(p);
750} 774}
775EXPORT_SYMBOL(cx2341x_fill_defaults);
751 776
752static int cx2341x_api(void *priv, cx2341x_mbox_func func, int cmd, int args, ...) 777static int cx2341x_api(void *priv, cx2341x_mbox_func func,
778 u32 cmd, int args, ...)
753{ 779{
754 u32 data[CX2341X_MBOX_MAX_DATA]; 780 u32 data[CX2341X_MBOX_MAX_DATA];
755 va_list vargs; 781 va_list vargs;
@@ -757,15 +783,17 @@ static int cx2341x_api(void *priv, cx2341x_mbox_func func, int cmd, int args, ..
757 783
758 va_start(vargs, args); 784 va_start(vargs, args);
759 785
760 for (i = 0; i < args; i++) { 786 for (i = 0; i < args; i++)
761 data[i] = va_arg(vargs, int); 787 data[i] = va_arg(vargs, int);
762 }
763 va_end(vargs); 788 va_end(vargs);
764 return func(priv, cmd, args, 0, data); 789 return func(priv, cmd, args, 0, data);
765} 790}
766 791
792#define NEQ(field) (old->field != new->field)
793
767int cx2341x_update(void *priv, cx2341x_mbox_func func, 794int cx2341x_update(void *priv, cx2341x_mbox_func func,
768 const struct cx2341x_mpeg_params *old, const struct cx2341x_mpeg_params *new) 795 const struct cx2341x_mpeg_params *old,
796 const struct cx2341x_mpeg_params *new)
769{ 797{
770 static int mpeg_stream_type[] = { 798 static int mpeg_stream_type[] = {
771 0, /* MPEG-2 PS */ 799 0, /* MPEG-2 PS */
@@ -777,17 +805,18 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
777 }; 805 };
778 806
779 int err = 0; 807 int err = 0;
808 int force = (old == NULL);
780 u16 temporal = new->video_temporal_filter; 809 u16 temporal = new->video_temporal_filter;
781 810
782 cx2341x_api(priv, func, CX2341X_ENC_SET_OUTPUT_PORT, 2, new->port, 0); 811 cx2341x_api(priv, func, CX2341X_ENC_SET_OUTPUT_PORT, 2, new->port, 0);
783 812
784 if (old == NULL || old->is_50hz != new->is_50hz) { 813 if (force || NEQ(is_50hz)) {
785 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_RATE, 1, new->is_50hz); 814 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_RATE, 1,
815 new->is_50hz);
786 if (err) return err; 816 if (err) return err;
787 } 817 }
788 818
789 if (old == NULL || old->width != new->width || old->height != new->height || 819 if (force || NEQ(width) || NEQ(height) || NEQ(video_encoding)) {
790 old->video_encoding != new->video_encoding) {
791 u16 w = new->width; 820 u16 w = new->width;
792 u16 h = new->height; 821 u16 h = new->height;
793 822
@@ -795,69 +824,74 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
795 w /= 2; 824 w /= 2;
796 h /= 2; 825 h /= 2;
797 } 826 }
798 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2, h, w); 827 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2,
828 h, w);
799 if (err) return err; 829 if (err) return err;
800 } 830 }
801 831
802 if (new->width != 720 || new->height != (new->is_50hz ? 576 : 480)) { 832 if (new->width != 720 || new->height != (new->is_50hz ? 576 : 480)) {
803 /* Adjust temporal filter if necessary. The problem with the temporal 833 /* Adjust temporal filter if necessary. The problem with the
804 filter is that it works well with full resolution capturing, but 834 temporal filter is that it works well with full resolution
805 not when the capture window is scaled (the filter introduces 835 capturing, but not when the capture window is scaled (the
806 a ghosting effect). So if the capture window is scaled, then 836 filter introduces a ghosting effect). So if the capture
807 force the filter to 0. 837 window is scaled, then force the filter to 0.
808 838
809 For full resolution the filter really improves the video 839 For full resolution the filter really improves the video
810 quality, especially if the original video quality is suboptimal. */ 840 quality, especially if the original video quality is
841 suboptimal. */
811 temporal = 0; 842 temporal = 0;
812 } 843 }
813 844
814 if (old == NULL || old->stream_type != new->stream_type) { 845 if (force || NEQ(stream_type)) {
815 err = cx2341x_api(priv, func, CX2341X_ENC_SET_STREAM_TYPE, 1, mpeg_stream_type[new->stream_type]); 846 err = cx2341x_api(priv, func, CX2341X_ENC_SET_STREAM_TYPE, 1,
847 mpeg_stream_type[new->stream_type]);
816 if (err) return err; 848 if (err) return err;
817 } 849 }
818 if (old == NULL || old->video_aspect != new->video_aspect) { 850 if (force || NEQ(video_aspect)) {
819 err = cx2341x_api(priv, func, CX2341X_ENC_SET_ASPECT_RATIO, 1, 1 + new->video_aspect); 851 err = cx2341x_api(priv, func, CX2341X_ENC_SET_ASPECT_RATIO, 1,
852 1 + new->video_aspect);
820 if (err) return err; 853 if (err) return err;
821 } 854 }
822 if (old == NULL || old->video_b_frames != new->video_b_frames || 855 if (force || NEQ(video_b_frames) || NEQ(video_gop_size)) {
823 old->video_gop_size != new->video_gop_size) {
824 err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_PROPERTIES, 2, 856 err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_PROPERTIES, 2,
825 new->video_gop_size, new->video_b_frames + 1); 857 new->video_gop_size, new->video_b_frames + 1);
826 if (err) return err; 858 if (err) return err;
827 } 859 }
828 if (old == NULL || old->video_gop_closure != new->video_gop_closure) { 860 if (force || NEQ(video_gop_closure)) {
829 err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_CLOSURE, 1, new->video_gop_closure); 861 err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_CLOSURE, 1,
862 new->video_gop_closure);
830 if (err) return err; 863 if (err) return err;
831 } 864 }
832 if (old == NULL || old->audio_properties != new->audio_properties) { 865 if (force || NEQ(audio_properties)) {
833 err = cx2341x_api(priv, func, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, new->audio_properties); 866 err = cx2341x_api(priv, func, CX2341X_ENC_SET_AUDIO_PROPERTIES,
867 1, new->audio_properties);
834 if (err) return err; 868 if (err) return err;
835 } 869 }
836 if (old == NULL || old->audio_mute != new->audio_mute) { 870 if (force || NEQ(audio_mute)) {
837 err = cx2341x_api(priv, func, CX2341X_ENC_MUTE_AUDIO, 1, new->audio_mute); 871 err = cx2341x_api(priv, func, CX2341X_ENC_MUTE_AUDIO, 1,
872 new->audio_mute);
838 if (err) return err; 873 if (err) return err;
839 } 874 }
840 if (old == NULL || old->video_bitrate_mode != new->video_bitrate_mode || 875 if (force || NEQ(video_bitrate_mode) || NEQ(video_bitrate) ||
841 old->video_bitrate != new->video_bitrate || 876 NEQ(video_bitrate_peak)) {
842 old->video_bitrate_peak != new->video_bitrate_peak) {
843 err = cx2341x_api(priv, func, CX2341X_ENC_SET_BIT_RATE, 5, 877 err = cx2341x_api(priv, func, CX2341X_ENC_SET_BIT_RATE, 5,
844 new->video_bitrate_mode, new->video_bitrate, 878 new->video_bitrate_mode, new->video_bitrate,
845 new->video_bitrate_peak / 400, 0, 0); 879 new->video_bitrate_peak / 400, 0, 0);
846 if (err) return err; 880 if (err) return err;
847 } 881 }
848 if (old == NULL || old->video_spatial_filter_mode != new->video_spatial_filter_mode || 882 if (force || NEQ(video_spatial_filter_mode) ||
849 old->video_temporal_filter_mode != new->video_temporal_filter_mode || 883 NEQ(video_temporal_filter_mode) ||
850 old->video_median_filter_type != new->video_median_filter_type) { 884 NEQ(video_median_filter_type)) {
851 err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_MODE, 2, 885 err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_MODE,
852 new->video_spatial_filter_mode | (new->video_temporal_filter_mode << 1), 886 2, new->video_spatial_filter_mode |
887 (new->video_temporal_filter_mode << 1),
853 new->video_median_filter_type); 888 new->video_median_filter_type);
854 if (err) return err; 889 if (err) return err;
855 } 890 }
856 if (old == NULL || 891 if (force || NEQ(video_luma_median_filter_bottom) ||
857 old->video_luma_median_filter_bottom != new->video_luma_median_filter_bottom || 892 NEQ(video_luma_median_filter_top) ||
858 old->video_luma_median_filter_top != new->video_luma_median_filter_top || 893 NEQ(video_chroma_median_filter_bottom) ||
859 old->video_chroma_median_filter_bottom != new->video_chroma_median_filter_bottom || 894 NEQ(video_chroma_median_filter_top)) {
860 old->video_chroma_median_filter_top != new->video_chroma_median_filter_top) {
861 err = cx2341x_api(priv, func, CX2341X_ENC_SET_CORING_LEVELS, 4, 895 err = cx2341x_api(priv, func, CX2341X_ENC_SET_CORING_LEVELS, 4,
862 new->video_luma_median_filter_bottom, 896 new->video_luma_median_filter_bottom,
863 new->video_luma_median_filter_top, 897 new->video_luma_median_filter_top,
@@ -865,36 +899,39 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
865 new->video_chroma_median_filter_top); 899 new->video_chroma_median_filter_top);
866 if (err) return err; 900 if (err) return err;
867 } 901 }
868 if (old == NULL || 902 if (force || NEQ(video_luma_spatial_filter_type) ||
869 old->video_luma_spatial_filter_type != new->video_luma_spatial_filter_type || 903 NEQ(video_chroma_spatial_filter_type)) {
870 old->video_chroma_spatial_filter_type != new->video_chroma_spatial_filter_type) { 904 err = cx2341x_api(priv, func,
871 err = cx2341x_api(priv, func, CX2341X_ENC_SET_SPATIAL_FILTER_TYPE, 2, 905 CX2341X_ENC_SET_SPATIAL_FILTER_TYPE,
872 new->video_luma_spatial_filter_type, new->video_chroma_spatial_filter_type); 906 2, new->video_luma_spatial_filter_type,
907 new->video_chroma_spatial_filter_type);
873 if (err) return err; 908 if (err) return err;
874 } 909 }
875 if (old == NULL || 910 if (force || NEQ(video_spatial_filter) ||
876 old->video_spatial_filter != new->video_spatial_filter || 911 old->video_temporal_filter != temporal) {
877 old->video_temporal_filter != temporal) { 912 err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_PROPS,
878 err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2, 913 2, new->video_spatial_filter, temporal);
879 new->video_spatial_filter, temporal);
880 if (err) return err; 914 if (err) return err;
881 } 915 }
882 if (old == NULL || old->video_temporal_decimation != new->video_temporal_decimation) { 916 if (force || NEQ(video_temporal_decimation)) {
883 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_DROP_RATE, 1, 917 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_DROP_RATE,
884 new->video_temporal_decimation); 918 1, new->video_temporal_decimation);
885 if (err) return err; 919 if (err) return err;
886 } 920 }
887 if (old == NULL || old->video_mute != new->video_mute || 921 if (force || NEQ(video_mute) ||
888 (new->video_mute && old->video_mute_yuv != new->video_mute_yuv)) { 922 (new->video_mute && NEQ(video_mute_yuv))) {
889 err = cx2341x_api(priv, func, CX2341X_ENC_MUTE_VIDEO, 1, new->video_mute | (new->video_mute_yuv << 8)); 923 err = cx2341x_api(priv, func, CX2341X_ENC_MUTE_VIDEO, 1,
924 new->video_mute | (new->video_mute_yuv << 8));
890 if (err) return err; 925 if (err) return err;
891 } 926 }
892 if (old == NULL || old->stream_insert_nav_packets != new->stream_insert_nav_packets) { 927 if (force || NEQ(stream_insert_nav_packets)) {
893 err = cx2341x_api(priv, func, CX2341X_ENC_MISC, 2, 7, new->stream_insert_nav_packets); 928 err = cx2341x_api(priv, func, CX2341X_ENC_MISC, 2,
929 7, new->stream_insert_nav_packets);
894 if (err) return err; 930 if (err) return err;
895 } 931 }
896 return 0; 932 return 0;
897} 933}
934EXPORT_SYMBOL(cx2341x_update);
898 935
899static const char *cx2341x_menu_item(struct cx2341x_mpeg_params *p, u32 id) 936static const char *cx2341x_menu_item(struct cx2341x_mpeg_params *p, u32 id)
900{ 937{
@@ -943,18 +980,17 @@ void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix)
943 cx2341x_menu_item(p, V4L2_CID_MPEG_VIDEO_ASPECT), 980 cx2341x_menu_item(p, V4L2_CID_MPEG_VIDEO_ASPECT),
944 cx2341x_menu_item(p, V4L2_CID_MPEG_VIDEO_BITRATE_MODE), 981 cx2341x_menu_item(p, V4L2_CID_MPEG_VIDEO_BITRATE_MODE),
945 p->video_bitrate); 982 p->video_bitrate);
946 if (p->video_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) { 983 if (p->video_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR)
947 printk(", Peak %d", p->video_bitrate_peak); 984 printk(", Peak %d", p->video_bitrate_peak);
948 }
949 printk("\n"); 985 printk("\n");
950 printk(KERN_INFO "%s: Video: GOP Size %d, %d B-Frames, %sGOP Closure\n", 986 printk(KERN_INFO
987 "%s: Video: GOP Size %d, %d B-Frames, %sGOP Closure\n",
951 prefix, 988 prefix,
952 p->video_gop_size, p->video_b_frames, 989 p->video_gop_size, p->video_b_frames,
953 p->video_gop_closure ? "" : "No "); 990 p->video_gop_closure ? "" : "No ");
954 if (p->video_temporal_decimation) { 991 if (p->video_temporal_decimation)
955 printk(KERN_INFO "%s: Video: Temporal Decimation %d\n", 992 printk(KERN_INFO "%s: Video: Temporal Decimation %d\n",
956 prefix, p->video_temporal_decimation); 993 prefix, p->video_temporal_decimation);
957 }
958 994
959 /* Audio */ 995 /* Audio */
960 printk(KERN_INFO "%s: Audio: %s, %s, %s, %s%s", 996 printk(KERN_INFO "%s: Audio: %s, %s, %s, %s%s",
@@ -964,10 +1000,9 @@ void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix)
964 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_L2_BITRATE), 1000 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_L2_BITRATE),
965 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_MODE), 1001 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_MODE),
966 p->audio_mute ? " (muted)" : ""); 1002 p->audio_mute ? " (muted)" : "");
967 if (p->audio_mode == V4L2_MPEG_AUDIO_MODE_JOINT_STEREO) { 1003 if (p->audio_mode == V4L2_MPEG_AUDIO_MODE_JOINT_STEREO)
968 printk(", %s", 1004 printk(", %s", cx2341x_menu_item(p,
969 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_MODE_EXTENSION)); 1005 V4L2_CID_MPEG_AUDIO_MODE_EXTENSION));
970 }
971 printk(", %s, %s\n", 1006 printk(", %s, %s\n",
972 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_EMPHASIS), 1007 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_EMPHASIS),
973 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_CRC)); 1008 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_CRC));
@@ -975,33 +1010,33 @@ void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix)
975 /* Encoding filters */ 1010 /* Encoding filters */
976 printk(KERN_INFO "%s: Spatial Filter: %s, Luma %s, Chroma %s, %d\n", 1011 printk(KERN_INFO "%s: Spatial Filter: %s, Luma %s, Chroma %s, %d\n",
977 prefix, 1012 prefix,
978 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE), 1013 cx2341x_menu_item(p,
979 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE), 1014 V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE),
980 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE), 1015 cx2341x_menu_item(p,
1016 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE),
1017 cx2341x_menu_item(p,
1018 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE),
981 p->video_spatial_filter); 1019 p->video_spatial_filter);
982 if (p->width != 720 || p->height != (p->is_50hz ? 576 : 480)) { 1020
1021 if (p->width != 720 || p->height != (p->is_50hz ? 576 : 480))
983 temporal = 0; 1022 temporal = 0;
984 } 1023
985 printk(KERN_INFO "%s: Temporal Filter: %s, %d\n", 1024 printk(KERN_INFO "%s: Temporal Filter: %s, %d\n",
986 prefix, 1025 prefix,
987 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE), 1026 cx2341x_menu_item(p,
1027 V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE),
988 temporal); 1028 temporal);
989 printk(KERN_INFO "%s: Median Filter: %s, Luma [%d, %d], Chroma [%d, %d]\n", 1029 printk(KERN_INFO
1030 "%s: Median Filter: %s, Luma [%d, %d], Chroma [%d, %d]\n",
990 prefix, 1031 prefix,
991 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE), 1032 cx2341x_menu_item(p,
1033 V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE),
992 p->video_luma_median_filter_bottom, 1034 p->video_luma_median_filter_bottom,
993 p->video_luma_median_filter_top, 1035 p->video_luma_median_filter_top,
994 p->video_chroma_median_filter_bottom, 1036 p->video_chroma_median_filter_bottom,
995 p->video_chroma_median_filter_top); 1037 p->video_chroma_median_filter_top);
996} 1038}
997
998EXPORT_SYMBOL(cx2341x_fill_defaults);
999EXPORT_SYMBOL(cx2341x_ctrl_query);
1000EXPORT_SYMBOL(cx2341x_ctrl_get_menu);
1001EXPORT_SYMBOL(cx2341x_ext_ctrls);
1002EXPORT_SYMBOL(cx2341x_update);
1003EXPORT_SYMBOL(cx2341x_log_status); 1039EXPORT_SYMBOL(cx2341x_log_status);
1004EXPORT_SYMBOL(cx2341x_mpeg_ctrls);
1005 1040
1006/* 1041/*
1007 * Local variables: 1042 * Local variables:
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index 081ee6e1536f..1fd326fe4113 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -12,6 +12,10 @@ config VIDEO_CX23885
12 select DVB_S5H1409 if !DVB_FE_CUSTOMISE 12 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
13 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 13 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
14 select DVB_PLL if !DVB_FE_CUSTOMISE 14 select DVB_PLL if !DVB_FE_CUSTOMISE
15 select TUNER_XC2028 if !DVB_FE_CUSTOMIZE
16 select TUNER_TDA8290 if !DVB_FE_CUSTOMIZE
17 select DVB_TDA18271 if !DVB_FE_CUSTOMIZE
18 select DVB_TUNER_XC5000 if !DVB_FE_CUSTOMIZE
15 ---help--- 19 ---help---
16 This is a video4linux driver for Conexant 23885 based 20 This is a video4linux driver for Conexant 23885 based
17 TV cards. 21 TV cards.
diff --git a/drivers/media/video/cx23885/Makefile b/drivers/media/video/cx23885/Makefile
index 665067022d2a..32c90be50602 100644
--- a/drivers/media/video/cx23885/Makefile
+++ b/drivers/media/video/cx23885/Makefile
@@ -1,4 +1,4 @@
1cx23885-objs := cx23885-cards.o cx23885-core.o cx23885-i2c.o cx23885-dvb.o 1cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o cx23885-core.o cx23885-i2c.o cx23885-dvb.o
2 2
3obj-$(CONFIG_VIDEO_CX23885) += cx23885.o 3obj-$(CONFIG_VIDEO_CX23885) += cx23885.o
4 4
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index b9012acabb2f..2d414dad5c31 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -23,6 +23,7 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/pci.h> 24#include <linux/pci.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <media/cx25840.h>
26 27
27#include "cx23885.h" 28#include "cx23885.h"
28 29
@@ -32,6 +33,8 @@
32struct cx23885_board cx23885_boards[] = { 33struct cx23885_board cx23885_boards[] = {
33 [CX23885_BOARD_UNKNOWN] = { 34 [CX23885_BOARD_UNKNOWN] = {
34 .name = "UNKNOWN/GENERIC", 35 .name = "UNKNOWN/GENERIC",
36 /* Ensure safe default for unknown boards */
37 .clk_freq = 0,
35 .input = {{ 38 .input = {{
36 .type = CX23885_VMUX_COMPOSITE1, 39 .type = CX23885_VMUX_COMPOSITE1,
37 .vmux = 0, 40 .vmux = 0,
@@ -69,23 +72,29 @@ struct cx23885_board cx23885_boards[] = {
69 }, 72 },
70 [CX23885_BOARD_HAUPPAUGE_HVR1800] = { 73 [CX23885_BOARD_HAUPPAUGE_HVR1800] = {
71 .name = "Hauppauge WinTV-HVR1800", 74 .name = "Hauppauge WinTV-HVR1800",
75 .porta = CX23885_ANALOG_VIDEO,
72 .portc = CX23885_MPEG_DVB, 76 .portc = CX23885_MPEG_DVB,
77 .tuner_type = TUNER_PHILIPS_TDA8290,
78 .tuner_addr = 0x42, /* 0x84 >> 1 */
73 .input = {{ 79 .input = {{
74 .type = CX23885_VMUX_TELEVISION, 80 .type = CX23885_VMUX_TELEVISION,
75 .vmux = 0, 81 .vmux = CX25840_VIN7_CH3 |
76 .gpio0 = 0xff00, 82 CX25840_VIN5_CH2 |
77 },{ 83 CX25840_VIN2_CH1,
78 .type = CX23885_VMUX_DEBUG, 84 .gpio0 = 0,
79 .vmux = 0,
80 .gpio0 = 0xff01,
81 },{ 85 },{
82 .type = CX23885_VMUX_COMPOSITE1, 86 .type = CX23885_VMUX_COMPOSITE1,
83 .vmux = 1, 87 .vmux = CX25840_VIN7_CH3 |
84 .gpio0 = 0xff02, 88 CX25840_VIN4_CH2 |
89 CX25840_VIN6_CH1,
90 .gpio0 = 0,
85 },{ 91 },{
86 .type = CX23885_VMUX_SVIDEO, 92 .type = CX23885_VMUX_SVIDEO,
87 .vmux = 2, 93 .vmux = CX25840_VIN7_CH3 |
88 .gpio0 = 0xff02, 94 CX25840_VIN4_CH2 |
95 CX25840_VIN8_CH1 |
96 CX25840_SVIDEO_ON,
97 .gpio0 = 0,
89 }}, 98 }},
90 }, 99 },
91 [CX23885_BOARD_HAUPPAUGE_HVR1250] = { 100 [CX23885_BOARD_HAUPPAUGE_HVR1250] = {
@@ -113,6 +122,14 @@ struct cx23885_board cx23885_boards[] = {
113 .name = "DViCO FusionHDTV5 Express", 122 .name = "DViCO FusionHDTV5 Express",
114 .portb = CX23885_MPEG_DVB, 123 .portb = CX23885_MPEG_DVB,
115 }, 124 },
125 [CX23885_BOARD_HAUPPAUGE_HVR1500Q] = {
126 .name = "Hauppauge WinTV-HVR1500Q",
127 .portc = CX23885_MPEG_DVB,
128 },
129 [CX23885_BOARD_HAUPPAUGE_HVR1500] = {
130 .name = "Hauppauge WinTV-HVR1500",
131 .portc = CX23885_MPEG_DVB,
132 },
116}; 133};
117const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); 134const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
118 135
@@ -138,12 +155,32 @@ struct cx23885_subid cx23885_subids[] = {
138 .card = CX23885_BOARD_HAUPPAUGE_HVR1800, 155 .card = CX23885_BOARD_HAUPPAUGE_HVR1800,
139 },{ 156 },{
140 .subvendor = 0x0070, 157 .subvendor = 0x0070,
158 .subdevice = 0x7809,
159 .card = CX23885_BOARD_HAUPPAUGE_HVR1800,
160 },{
161 .subvendor = 0x0070,
141 .subdevice = 0x7911, 162 .subdevice = 0x7911,
142 .card = CX23885_BOARD_HAUPPAUGE_HVR1250, 163 .card = CX23885_BOARD_HAUPPAUGE_HVR1250,
143 },{ 164 },{
144 .subvendor = 0x18ac, 165 .subvendor = 0x18ac,
145 .subdevice = 0xd500, 166 .subdevice = 0xd500,
146 .card = CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP, 167 .card = CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP,
168 },{
169 .subvendor = 0x0070,
170 .subdevice = 0x7790,
171 .card = CX23885_BOARD_HAUPPAUGE_HVR1500Q,
172 },{
173 .subvendor = 0x0070,
174 .subdevice = 0x7797,
175 .card = CX23885_BOARD_HAUPPAUGE_HVR1500Q,
176 },{
177 .subvendor = 0x0070,
178 .subdevice = 0x7710,
179 .card = CX23885_BOARD_HAUPPAUGE_HVR1500,
180 },{
181 .subvendor = 0x0070,
182 .subdevice = 0x7717,
183 .card = CX23885_BOARD_HAUPPAUGE_HVR1500,
147 }, 184 },
148}; 185};
149const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); 186const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -184,9 +221,19 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
184 switch (tv.model) 221 switch (tv.model)
185 { 222 {
186 case 76601: /* WinTV-HVR1800lp (PCIe, Retail, No IR, Dual channel ATSC and MPEG2 HW Encoder */ 223 case 76601: /* WinTV-HVR1800lp (PCIe, Retail, No IR, Dual channel ATSC and MPEG2 HW Encoder */
187 case 77001: /* WinTV-HVR1500 (Express Card, Retail, No IR, ATSC and Basic analog */ 224 case 77001: /* WinTV-HVR1500 (Express Card, OEM, No IR, ATSC and Basic analog */
188 case 78501: /* WinTV-HVR1800 (PCIe, Retail, IR, Dual channel ATSC and MPEG2 HW Encoder */ 225 case 77011: /* WinTV-HVR1500 (Express Card, Retail, No IR, ATSC and Basic analog */
189 case 78521: /* WinTV-HVR1800 (PCIe, Retail, IR, Dual channel ATSC and MPEG2 HW Encoder */ 226 case 77041: /* WinTV-HVR1500Q (Express Card, OEM, No IR, ATSC/QAM and Basic analog */
227 case 77051: /* WinTV-HVR1500Q (Express Card, Retail, No IR, ATSC/QAM and Basic analog */
228 case 78011: /* WinTV-HVR1800 (PCIe, Retail, 3.5mm in, IR, No FM, Dual channel ATSC and MPEG2 HW Encoder */
229 case 78501: /* WinTV-HVR1800 (PCIe, OEM, RCA in, No IR, FM, Dual channel ATSC and MPEG2 HW Encoder */
230 case 78521: /* WinTV-HVR1800 (PCIe, OEM, RCA in, No IR, FM, Dual channel ATSC and MPEG2 HW Encoder */
231 case 78531: /* WinTV-HVR1800 (PCIe, OEM, RCA in, No IR, No FM, Dual channel ATSC and MPEG2 HW Encoder */
232 case 78631: /* WinTV-HVR1800 (PCIe, OEM, No IR, No FM, Dual channel ATSC and MPEG2 HW Encoder */
233 case 79001: /* WinTV-HVR1250 (PCIe, Retail, IR, full height, ATSC and Basic analog */
234 case 79101: /* WinTV-HVR1250 (PCIe, Retail, IR, half height, ATSC and Basic analog */
235 case 79571: /* WinTV-HVR1250 (PCIe, OEM, No IR, full height, ATSC and Basic analog */
236 case 79671: /* WinTV-HVR1250 (PCIe, OEM, No IR, half height, ATSC and Basic analog */
190 break; 237 break;
191 default: 238 default:
192 printk("%s: warning: unknown hauppauge model #%d\n", dev->name, tv.model); 239 printk("%s: warning: unknown hauppauge model #%d\n", dev->name, tv.model);
@@ -197,6 +244,34 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
197 dev->name, tv.model); 244 dev->name, tv.model);
198} 245}
199 246
247/* Tuner callback function for cx23885 boards. Currently only needed
248 * for HVR1500Q, which has an xc5000 tuner.
249 */
250int cx23885_tuner_callback(void *priv, int command, int arg)
251{
252 struct cx23885_i2c *bus = priv;
253 struct cx23885_dev *dev = bus->dev;
254
255 switch(dev->board) {
256 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
257 if(command == 0) { /* Tuner Reset Command from xc5000 */
258 /* Drive the tuner into reset and out */
259 cx_clear(GP0_IO, 0x00000004);
260 mdelay(200);
261 cx_set(GP0_IO, 0x00000004);
262 return 0;
263 }
264 else {
265 printk(KERN_ERR
266 "%s(): Unknow command.\n", __FUNCTION__);
267 return -EINVAL;
268 }
269 break;
270 }
271
272 return 0; /* Should never be here */
273}
274
200void cx23885_gpio_setup(struct cx23885_dev *dev) 275void cx23885_gpio_setup(struct cx23885_dev *dev)
201{ 276{
202 switch(dev->board) { 277 switch(dev->board) {
@@ -204,6 +279,23 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
204 /* GPIO-0 cx24227 demodulator reset */ 279 /* GPIO-0 cx24227 demodulator reset */
205 cx_set(GP0_IO, 0x00010001); /* Bring the part out of reset */ 280 cx_set(GP0_IO, 0x00010001); /* Bring the part out of reset */
206 break; 281 break;
282 case CX23885_BOARD_HAUPPAUGE_HVR1500:
283 /* GPIO-0 cx24227 demodulator */
284 /* GPIO-2 xc3028 tuner */
285
286 /* Put the parts into reset */
287 cx_set(GP0_IO, 0x00050000);
288 cx_clear(GP0_IO, 0x00000005);
289 msleep(5);
290
291 /* Bring the parts out of reset */
292 cx_set(GP0_IO, 0x00050005);
293 break;
294 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
295 /* GPIO-0 cx24227 demodulator reset */
296 /* GPIO-2 xc5000 tuner reset */
297 cx_set(GP0_IO, 0x00050005); /* Bring the part out of reset */
298 break;
207 case CX23885_BOARD_HAUPPAUGE_HVR1800: 299 case CX23885_BOARD_HAUPPAUGE_HVR1800:
208 /* GPIO-0 656_CLK */ 300 /* GPIO-0 656_CLK */
209 /* GPIO-1 656_D0 */ 301 /* GPIO-1 656_D0 */
@@ -212,7 +304,14 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
212 /* GPIO-11-14 cx23417 addr0-3 */ 304 /* GPIO-11-14 cx23417 addr0-3 */
213 /* GPIO-15-18 cx23417 READY, CS, RD, WR */ 305 /* GPIO-15-18 cx23417 READY, CS, RD, WR */
214 /* GPIO-19 IR_RX */ 306 /* GPIO-19 IR_RX */
215 // FIXME: Analog requires the tuner is brought out of reset 307
308 /* Force the TDA8295A into reset and back */
309 cx_set(GP0_IO, 0x00040004);
310 mdelay(20);
311 cx_clear(GP0_IO, 0x00000004);
312 mdelay(20);
313 cx_set(GP0_IO, 0x00040004);
314 mdelay(20);
216 break; 315 break;
217 } 316 }
218} 317}
@@ -221,6 +320,8 @@ int cx23885_ir_init(struct cx23885_dev *dev)
221{ 320{
222 switch (dev->board) { 321 switch (dev->board) {
223 case CX23885_BOARD_HAUPPAUGE_HVR1250: 322 case CX23885_BOARD_HAUPPAUGE_HVR1250:
323 case CX23885_BOARD_HAUPPAUGE_HVR1500:
324 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
224 case CX23885_BOARD_HAUPPAUGE_HVR1800: 325 case CX23885_BOARD_HAUPPAUGE_HVR1800:
225 /* FIXME: Implement me */ 326 /* FIXME: Implement me */
226 break; 327 break;
@@ -244,6 +345,8 @@ void cx23885_card_setup(struct cx23885_dev *dev)
244 345
245 switch (dev->board) { 346 switch (dev->board) {
246 case CX23885_BOARD_HAUPPAUGE_HVR1250: 347 case CX23885_BOARD_HAUPPAUGE_HVR1250:
348 case CX23885_BOARD_HAUPPAUGE_HVR1500:
349 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
247 case CX23885_BOARD_HAUPPAUGE_HVR1800: 350 case CX23885_BOARD_HAUPPAUGE_HVR1800:
248 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 351 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
249 if (dev->i2c_bus[0].i2c_rc == 0) 352 if (dev->i2c_bus[0].i2c_rc == 0)
@@ -258,6 +361,8 @@ void cx23885_card_setup(struct cx23885_dev *dev)
258 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 361 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
259 break; 362 break;
260 case CX23885_BOARD_HAUPPAUGE_HVR1250: 363 case CX23885_BOARD_HAUPPAUGE_HVR1250:
364 case CX23885_BOARD_HAUPPAUGE_HVR1500:
365 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
261 case CX23885_BOARD_HAUPPAUGE_HVR1800: 366 case CX23885_BOARD_HAUPPAUGE_HVR1800:
262 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 367 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
263 default: 368 default:
@@ -270,8 +375,6 @@ void cx23885_card_setup(struct cx23885_dev *dev)
270 375
271/* ------------------------------------------------------------------ */ 376/* ------------------------------------------------------------------ */
272 377
273EXPORT_SYMBOL(cx23885_boards);
274
275/* 378/*
276 * Local variables: 379 * Local variables:
277 * c-basic-offset: 8 380 * c-basic-offset: 8
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
index 3cdd136477e5..8e40c7bcc06d 100644
--- a/drivers/media/video/cx23885/cx23885-core.c
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -36,7 +36,7 @@ MODULE_DESCRIPTION("Driver for cx23885 based TV cards");
36MODULE_AUTHOR("Steven Toth <stoth@hauppauge.com>"); 36MODULE_AUTHOR("Steven Toth <stoth@hauppauge.com>");
37MODULE_LICENSE("GPL"); 37MODULE_LICENSE("GPL");
38 38
39static unsigned int debug = 0; 39static unsigned int debug;
40module_param(debug,int,0644); 40module_param(debug,int,0644);
41MODULE_PARM_DESC(debug,"enable debug messages"); 41MODULE_PARM_DESC(debug,"enable debug messages");
42 42
@@ -44,13 +44,15 @@ static unsigned int card[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
44module_param_array(card, int, NULL, 0444); 44module_param_array(card, int, NULL, 0444);
45MODULE_PARM_DESC(card,"card type"); 45MODULE_PARM_DESC(card,"card type");
46 46
47#define dprintk(level,fmt, arg...) if (debug >= level) \ 47#define dprintk(level, fmt, arg...)\
48 printk(KERN_DEBUG "%s/0: " fmt, dev->name , ## arg) 48 do { if (debug >= level)\
49 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
50 } while (0)
49 51
50static unsigned int cx23885_devcount; 52static unsigned int cx23885_devcount;
51 53
52static DEFINE_MUTEX(devlist); 54static DEFINE_MUTEX(devlist);
53static LIST_HEAD(cx23885_devlist); 55LIST_HEAD(cx23885_devlist);
54 56
55#define NO_SYNC_LINE (-1U) 57#define NO_SYNC_LINE (-1U)
56 58
@@ -73,14 +75,14 @@ static LIST_HEAD(cx23885_devlist);
73 * 0x00010ea0 0x00010xxx Free 75 * 0x00010ea0 0x00010xxx Free
74 */ 76 */
75 77
76struct sram_channel cx23885_sram_channels[] = { 78static struct sram_channel cx23885_sram_channels[] = {
77 [SRAM_CH01] = { 79 [SRAM_CH01] = {
78 .name = "test ch1", 80 .name = "VID A",
79 .cmds_start = 0x10000, 81 .cmds_start = 0x10000,
80 .ctrl_start = 0x10500, 82 .ctrl_start = 0x105b0,
81 .cdt = 0x10900, 83 .cdt = 0x107b0,
82 .fifo_start = 0x3000, 84 .fifo_start = 0x40,
83 .fifo_size = 0x1000, 85 .fifo_size = 0x2800,
84 .ptr1_reg = DMA1_PTR1, 86 .ptr1_reg = DMA1_PTR1,
85 .ptr2_reg = DMA1_PTR2, 87 .ptr2_reg = DMA1_PTR2,
86 .cnt1_reg = DMA1_CNT1, 88 .cnt1_reg = DMA1_CNT1,
@@ -102,8 +104,8 @@ struct sram_channel cx23885_sram_channels[] = {
102 [SRAM_CH03] = { 104 [SRAM_CH03] = {
103 .name = "TS1 B", 105 .name = "TS1 B",
104 .cmds_start = 0x100A0, 106 .cmds_start = 0x100A0,
105 .ctrl_start = 0x10780, 107 .ctrl_start = 0x10630,
106 .cdt = 0x10400, 108 .cdt = 0x10870,
107 .fifo_start = 0x5000, 109 .fifo_start = 0x5000,
108 .fifo_size = 0x1000, 110 .fifo_size = 0x1000,
109 .ptr1_reg = DMA3_PTR1, 111 .ptr1_reg = DMA3_PTR1,
@@ -139,7 +141,7 @@ struct sram_channel cx23885_sram_channels[] = {
139 .name = "TS2 C", 141 .name = "TS2 C",
140 .cmds_start = 0x10140, 142 .cmds_start = 0x10140,
141 .ctrl_start = 0x10680, 143 .ctrl_start = 0x10680,
142 .cdt = 0x10480, 144 .cdt = 0x108d0,
143 .fifo_start = 0x6000, 145 .fifo_start = 0x6000,
144 .fifo_size = 0x1000, 146 .fifo_size = 0x1000,
145 .ptr1_reg = DMA5_PTR1, 147 .ptr1_reg = DMA5_PTR1,
@@ -205,14 +207,14 @@ struct sram_channel cx23885_sram_channels[] = {
205 * 0x00010ea0 0x00010xxx Free 207 * 0x00010ea0 0x00010xxx Free
206 */ 208 */
207 209
208struct sram_channel cx23887_sram_channels[] = { 210static struct sram_channel cx23887_sram_channels[] = {
209 [SRAM_CH01] = { 211 [SRAM_CH01] = {
210 .name = "test ch1", 212 .name = "VID A",
211 .cmds_start = 0x0, 213 .cmds_start = 0x10000,
212 .ctrl_start = 0x0, 214 .ctrl_start = 0x105b0,
213 .cdt = 0x0, 215 .cdt = 0x107b0,
214 .fifo_start = 0x0, 216 .fifo_start = 0x40,
215 .fifo_size = 0x0, 217 .fifo_size = 0x2800,
216 .ptr1_reg = DMA1_PTR1, 218 .ptr1_reg = DMA1_PTR1,
217 .ptr2_reg = DMA1_PTR2, 219 .ptr2_reg = DMA1_PTR2,
218 .cnt1_reg = DMA1_CNT1, 220 .cnt1_reg = DMA1_CNT1,
@@ -231,12 +233,12 @@ struct sram_channel cx23887_sram_channels[] = {
231 .cnt2_reg = DMA2_CNT2, 233 .cnt2_reg = DMA2_CNT2,
232 }, 234 },
233 [SRAM_CH03] = { 235 [SRAM_CH03] = {
234 .name = "ch3", 236 .name = "TS1 B",
235 .cmds_start = 0x0, 237 .cmds_start = 0x100A0,
236 .ctrl_start = 0x0, 238 .ctrl_start = 0x10780,
237 .cdt = 0x0, 239 .cdt = 0x10400,
238 .fifo_start = 0x0, 240 .fifo_start = 0x5000,
239 .fifo_size = 0x0, 241 .fifo_size = 0x1000,
240 .ptr1_reg = DMA3_PTR1, 242 .ptr1_reg = DMA3_PTR1,
241 .ptr2_reg = DMA3_PTR2, 243 .ptr2_reg = DMA3_PTR2,
242 .cnt1_reg = DMA3_CNT1, 244 .cnt1_reg = DMA3_CNT1,
@@ -357,7 +359,7 @@ static int cx23885_risc_decode(u32 risc)
357} 359}
358 360
359void cx23885_wakeup(struct cx23885_tsport *port, 361void cx23885_wakeup(struct cx23885_tsport *port,
360 struct cx23885_dmaqueue *q, u32 count) 362 struct cx23885_dmaqueue *q, u32 count)
361{ 363{
362 struct cx23885_dev *dev = port->dev; 364 struct cx23885_dev *dev = port->dev;
363 struct cx23885_buffer *buf; 365 struct cx23885_buffer *buf;
@@ -378,7 +380,7 @@ void cx23885_wakeup(struct cx23885_tsport *port,
378 do_gettimeofday(&buf->vb.ts); 380 do_gettimeofday(&buf->vb.ts);
379 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i, 381 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
380 count, buf->count); 382 count, buf->count);
381 buf->vb.state = STATE_DONE; 383 buf->vb.state = VIDEOBUF_DONE;
382 list_del(&buf->vb.queue); 384 list_del(&buf->vb.queue);
383 wake_up(&buf->vb.done); 385 wake_up(&buf->vb.done);
384 } 386 }
@@ -391,12 +393,10 @@ void cx23885_wakeup(struct cx23885_tsport *port,
391 printk("%s: %d buffers handled (should be 1)\n", 393 printk("%s: %d buffers handled (should be 1)\n",
392 __FUNCTION__, bc); 394 __FUNCTION__, bc);
393} 395}
394void cx23885_sram_channel_dump(struct cx23885_dev *dev,
395 struct sram_channel *ch);
396 396
397int cx23885_sram_channel_setup(struct cx23885_dev *dev, 397int cx23885_sram_channel_setup(struct cx23885_dev *dev,
398 struct sram_channel *ch, 398 struct sram_channel *ch,
399 unsigned int bpl, u32 risc) 399 unsigned int bpl, u32 risc)
400{ 400{
401 unsigned int i, lines; 401 unsigned int i, lines;
402 u32 cdt; 402 u32 cdt;
@@ -468,7 +468,7 @@ int cx23885_sram_channel_setup(struct cx23885_dev *dev,
468} 468}
469 469
470void cx23885_sram_channel_dump(struct cx23885_dev *dev, 470void cx23885_sram_channel_dump(struct cx23885_dev *dev,
471 struct sram_channel *ch) 471 struct sram_channel *ch)
472{ 472{
473 static char *name[] = { 473 static char *name[] = {
474 "init risc lo", 474 "init risc lo",
@@ -529,8 +529,8 @@ void cx23885_sram_channel_dump(struct cx23885_dev *dev,
529 dev->name, cx_read(ch->cnt2_reg)); 529 dev->name, cx_read(ch->cnt2_reg));
530} 530}
531 531
532void cx23885_risc_disasm(struct cx23885_tsport *port, 532static void cx23885_risc_disasm(struct cx23885_tsport *port,
533 struct btcx_riscmem *risc) 533 struct btcx_riscmem *risc)
534{ 534{
535 struct cx23885_dev *dev = port->dev; 535 struct cx23885_dev *dev = port->dev;
536 unsigned int i, j, n; 536 unsigned int i, j, n;
@@ -548,7 +548,7 @@ void cx23885_risc_disasm(struct cx23885_tsport *port,
548 } 548 }
549} 549}
550 550
551void cx23885_shutdown(struct cx23885_dev *dev) 551static void cx23885_shutdown(struct cx23885_dev *dev)
552{ 552{
553 /* disable RISC controller */ 553 /* disable RISC controller */
554 cx_write(DEV_CNTRL2, 0); 554 cx_write(DEV_CNTRL2, 0);
@@ -578,7 +578,7 @@ void cx23885_shutdown(struct cx23885_dev *dev)
578 578
579} 579}
580 580
581void cx23885_reset(struct cx23885_dev *dev) 581static void cx23885_reset(struct cx23885_dev *dev)
582{ 582{
583 dprintk(1, "%s()\n", __FUNCTION__); 583 dprintk(1, "%s()\n", __FUNCTION__);
584 584
@@ -594,15 +594,18 @@ void cx23885_reset(struct cx23885_dev *dev)
594 594
595 mdelay(100); 595 mdelay(100);
596 596
597 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH01 ], 188*4, 0); 597 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01],
598 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH02 ], 128, 0); 598 720*4, 0);
599 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH03 ], 188*4, 0); 599 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH02], 128, 0);
600 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH04 ], 128, 0); 600 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH03],
601 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH05 ], 128, 0); 601 188*4, 0);
602 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH06 ], 188*4, 0); 602 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH04], 128, 0);
603 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH07 ], 128, 0); 603 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH05], 128, 0);
604 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH08 ], 128, 0); 604 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH06],
605 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH09 ], 128, 0); 605 188*4, 0);
606 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH07], 128, 0);
607 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH08], 128, 0);
608 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH09], 128, 0);
606 609
607 cx23885_gpio_setup(dev); 610 cx23885_gpio_setup(dev);
608} 611}
@@ -637,7 +640,7 @@ static int get_resources(struct cx23885_dev *dev)
637 640
638static void cx23885_timeout(unsigned long data); 641static void cx23885_timeout(unsigned long data);
639int cx23885_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc, 642int cx23885_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
640 u32 reg, u32 mask, u32 value); 643 u32 reg, u32 mask, u32 value);
641 644
642static int cx23885_init_tsport(struct cx23885_dev *dev, struct cx23885_tsport *port, int portno) 645static int cx23885_init_tsport(struct cx23885_dev *dev, struct cx23885_tsport *port, int portno)
643{ 646{
@@ -704,6 +707,44 @@ static int cx23885_init_tsport(struct cx23885_dev *dev, struct cx23885_tsport *p
704 return 0; 707 return 0;
705} 708}
706 709
710static void cx23885_dev_checkrevision(struct cx23885_dev *dev)
711{
712 switch (cx_read(RDR_CFG2) & 0xff) {
713 case 0x00:
714 /* cx23885 */
715 dev->hwrevision = 0xa0;
716 break;
717 case 0x01:
718 /* CX23885-12Z */
719 dev->hwrevision = 0xa1;
720 break;
721 case 0x02:
722 /* CX23885-13Z */
723 dev->hwrevision = 0xb0;
724 break;
725 case 0x03:
726 /* CX23888-22Z */
727 dev->hwrevision = 0xc0;
728 break;
729 case 0x0e:
730 /* CX23887-15Z */
731 dev->hwrevision = 0xc0;
732 case 0x0f:
733 /* CX23887-14Z */
734 dev->hwrevision = 0xb1;
735 break;
736 default:
737 printk(KERN_ERR "%s() New hardware revision found 0x%x\n",
738 __FUNCTION__, dev->hwrevision);
739 }
740 if (dev->hwrevision)
741 printk(KERN_INFO "%s() Hardware revision = 0x%02x\n",
742 __FUNCTION__, dev->hwrevision);
743 else
744 printk(KERN_ERR "%s() Hardware revision unknown 0x%x\n",
745 __FUNCTION__, dev->hwrevision);
746}
747
707static int cx23885_dev_setup(struct cx23885_dev *dev) 748static int cx23885_dev_setup(struct cx23885_dev *dev)
708{ 749{
709 int i; 750 int i;
@@ -723,10 +764,14 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
723 if(dev->pci->device == 0x8880) { 764 if(dev->pci->device == 0x8880) {
724 dev->bridge = CX23885_BRIDGE_887; 765 dev->bridge = CX23885_BRIDGE_887;
725 dev->sram_channels = cx23887_sram_channels; 766 dev->sram_channels = cx23887_sram_channels;
767 /* Apply a sensible clock frequency for the PCIe bridge */
768 dev->clk_freq = 25000000;
726 } else 769 } else
727 if(dev->pci->device == 0x8852) { 770 if(dev->pci->device == 0x8852) {
728 dev->bridge = CX23885_BRIDGE_885; 771 dev->bridge = CX23885_BRIDGE_885;
729 dev->sram_channels = cx23885_sram_channels; 772 dev->sram_channels = cx23885_sram_channels;
773 /* Apply a sensible clock frequency for the PCIe bridge */
774 dev->clk_freq = 28000000;
730 } else 775 } else
731 BUG(); 776 BUG();
732 777
@@ -746,6 +791,10 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
746 cx23885_card_list(dev); 791 cx23885_card_list(dev);
747 } 792 }
748 793
794 /* If the user specific a clk freq override, apply it */
795 if (cx23885_boards[dev->board].clk_freq > 0)
796 dev->clk_freq = cx23885_boards[dev->board].clk_freq;
797
749 dev->pci_bus = dev->pci->bus->number; 798 dev->pci_bus = dev->pci->bus->number;
750 dev->pci_slot = PCI_SLOT(dev->pci->devfn); 799 dev->pci_slot = PCI_SLOT(dev->pci->devfn);
751 dev->pci_irqmask = 0x001f00; 800 dev->pci_irqmask = 0x001f00;
@@ -810,6 +859,17 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
810 859
811 cx23885_pci_quirks(dev); 860 cx23885_pci_quirks(dev);
812 861
862 /* Assume some sensible defaults */
863 dev->tuner_type = cx23885_boards[dev->board].tuner_type;
864 dev->tuner_addr = cx23885_boards[dev->board].tuner_addr;
865 dev->radio_type = cx23885_boards[dev->board].radio_type;
866 dev->radio_addr = cx23885_boards[dev->board].radio_addr;
867
868 dprintk(1, "%s() tuner_type = 0x%x tuner_addr = 0x%x\n",
869 __FUNCTION__, dev->tuner_type, dev->tuner_addr);
870 dprintk(1, "%s() radio_type = 0x%x radio_addr = 0x%x\n",
871 __FUNCTION__, dev->radio_type, dev->radio_addr);
872
813 /* init hardware */ 873 /* init hardware */
814 cx23885_reset(dev); 874 cx23885_reset(dev);
815 875
@@ -820,24 +880,33 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
820 cx23885_card_setup(dev); 880 cx23885_card_setup(dev);
821 cx23885_ir_init(dev); 881 cx23885_ir_init(dev);
822 882
823 if(cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) { 883 if (cx23885_boards[dev->board].porta == CX23885_ANALOG_VIDEO) {
884 if (cx23885_video_register(dev) < 0) {
885 printk(KERN_ERR "%s() Failed to register analog "
886 "video adapters on VID_A\n", __FUNCTION__);
887 }
888 }
889
890 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) {
824 if (cx23885_dvb_register(&dev->ts1) < 0) { 891 if (cx23885_dvb_register(&dev->ts1) < 0) {
825 printk(KERN_ERR "%s() Failed to register dvb adapters on VID_B\n", 892 printk(KERN_ERR "%s() Failed to register dvb adapters on VID_B\n",
826 __FUNCTION__); 893 __FUNCTION__);
827 } 894 }
828 } 895 }
829 896
830 if(cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) { 897 if (cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) {
831 if (cx23885_dvb_register(&dev->ts2) < 0) { 898 if (cx23885_dvb_register(&dev->ts2) < 0) {
832 printk(KERN_ERR "%s() Failed to register dvb adapters on VID_C\n", 899 printk(KERN_ERR "%s() Failed to register dvb adapters on VID_C\n",
833 __FUNCTION__); 900 __FUNCTION__);
834 } 901 }
835 } 902 }
836 903
904 cx23885_dev_checkrevision(dev);
905
837 return 0; 906 return 0;
838} 907}
839 908
840void cx23885_dev_unregister(struct cx23885_dev *dev) 909static void cx23885_dev_unregister(struct cx23885_dev *dev)
841{ 910{
842 release_mem_region(pci_resource_start(dev->pci,0), 911 release_mem_region(pci_resource_start(dev->pci,0),
843 pci_resource_len(dev->pci,0)); 912 pci_resource_len(dev->pci,0));
@@ -845,6 +914,9 @@ void cx23885_dev_unregister(struct cx23885_dev *dev)
845 if (!atomic_dec_and_test(&dev->refcount)) 914 if (!atomic_dec_and_test(&dev->refcount))
846 return; 915 return;
847 916
917 if (cx23885_boards[dev->board].porta == CX23885_ANALOG_VIDEO)
918 cx23885_video_unregister(dev);
919
848 if(cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) 920 if(cx23885_boards[dev->board].portb == CX23885_MPEG_DVB)
849 cx23885_dvb_unregister(&dev->ts1); 921 cx23885_dvb_unregister(&dev->ts1);
850 922
@@ -952,9 +1024,11 @@ int cx23885_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
952 return 0; 1024 return 0;
953} 1025}
954 1026
955int cx23885_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc, 1027static int cx23885_risc_databuffer(struct pci_dev *pci,
956 struct scatterlist *sglist, unsigned int bpl, 1028 struct btcx_riscmem *risc,
957 unsigned int lines) 1029 struct scatterlist *sglist,
1030 unsigned int bpl,
1031 unsigned int lines)
958{ 1032{
959 u32 instructions; 1033 u32 instructions;
960 u32 *rp; 1034 u32 *rp;
@@ -982,7 +1056,7 @@ int cx23885_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc,
982} 1056}
983 1057
984int cx23885_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc, 1058int cx23885_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
985 u32 reg, u32 mask, u32 value) 1059 u32 reg, u32 mask, u32 value)
986{ 1060{
987 u32 *rp; 1061 u32 *rp;
988 int rc; 1062 int rc;
@@ -1011,7 +1085,58 @@ void cx23885_free_buffer(struct videobuf_queue *q, struct cx23885_buffer *buf)
1011 videobuf_dma_unmap(q, dma); 1085 videobuf_dma_unmap(q, dma);
1012 videobuf_dma_free(dma); 1086 videobuf_dma_free(dma);
1013 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc); 1087 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc);
1014 buf->vb.state = STATE_NEEDS_INIT; 1088 buf->vb.state = VIDEOBUF_NEEDS_INIT;
1089}
1090
1091static void cx23885_tsport_reg_dump(struct cx23885_tsport *port)
1092{
1093 struct cx23885_dev *dev = port->dev;
1094
1095 dprintk(1, "%s() Register Dump\n", __FUNCTION__);
1096 dprintk(1, "%s() DEV_CNTRL2 0x%08X\n", __FUNCTION__,
1097 cx_read(DEV_CNTRL2));
1098 dprintk(1, "%s() PCI_INT_MSK 0x%08X\n", __FUNCTION__,
1099 cx_read(PCI_INT_MSK));
1100 dprintk(1, "%s() AUD_INT_INT_MSK 0x%08X\n", __FUNCTION__,
1101 cx_read(AUDIO_INT_INT_MSK));
1102 dprintk(1, "%s() AUD_INT_DMA_CTL 0x%08X\n", __FUNCTION__,
1103 cx_read(AUD_INT_DMA_CTL));
1104 dprintk(1, "%s() AUD_EXT_INT_MSK 0x%08X\n", __FUNCTION__,
1105 cx_read(AUDIO_EXT_INT_MSK));
1106 dprintk(1, "%s() AUD_EXT_DMA_CTL 0x%08X\n", __FUNCTION__,
1107 cx_read(AUD_EXT_DMA_CTL));
1108 dprintk(1, "%s() PAD_CTRL 0x%08X\n", __FUNCTION__,
1109 cx_read(PAD_CTRL));
1110 dprintk(1, "%s() ALT_PIN_OUT_SEL 0x%08X\n", __FUNCTION__,
1111 cx_read(ALT_PIN_OUT_SEL));
1112 dprintk(1, "%s() GPIO2 0x%08X\n", __FUNCTION__,
1113 cx_read(GPIO2));
1114 dprintk(1, "%s() gpcnt(0x%08X) 0x%08X\n", __FUNCTION__,
1115 port->reg_gpcnt, cx_read(port->reg_gpcnt));
1116 dprintk(1, "%s() gpcnt_ctl(0x%08X) 0x%08x\n", __FUNCTION__,
1117 port->reg_gpcnt_ctl, cx_read(port->reg_gpcnt_ctl));
1118 dprintk(1, "%s() dma_ctl(0x%08X) 0x%08x\n", __FUNCTION__,
1119 port->reg_dma_ctl, cx_read(port->reg_dma_ctl));
1120 dprintk(1, "%s() src_sel(0x%08X) 0x%08x\n", __FUNCTION__,
1121 port->reg_src_sel, cx_read(port->reg_src_sel));
1122 dprintk(1, "%s() lngth(0x%08X) 0x%08x\n", __FUNCTION__,
1123 port->reg_lngth, cx_read(port->reg_lngth));
1124 dprintk(1, "%s() hw_sop_ctrl(0x%08X) 0x%08x\n", __FUNCTION__,
1125 port->reg_hw_sop_ctrl, cx_read(port->reg_hw_sop_ctrl));
1126 dprintk(1, "%s() gen_ctrl(0x%08X) 0x%08x\n", __FUNCTION__,
1127 port->reg_gen_ctrl, cx_read(port->reg_gen_ctrl));
1128 dprintk(1, "%s() bd_pkt_status(0x%08X) 0x%08x\n", __FUNCTION__,
1129 port->reg_bd_pkt_status, cx_read(port->reg_bd_pkt_status));
1130 dprintk(1, "%s() sop_status(0x%08X) 0x%08x\n", __FUNCTION__,
1131 port->reg_sop_status, cx_read(port->reg_sop_status));
1132 dprintk(1, "%s() fifo_ovfl_stat(0x%08X) 0x%08x\n", __FUNCTION__,
1133 port->reg_fifo_ovfl_stat, cx_read(port->reg_fifo_ovfl_stat));
1134 dprintk(1, "%s() vld_misc(0x%08X) 0x%08x\n", __FUNCTION__,
1135 port->reg_vld_misc, cx_read(port->reg_vld_misc));
1136 dprintk(1, "%s() ts_clk_en(0x%08X) 0x%08x\n", __FUNCTION__,
1137 port->reg_ts_clk_en, cx_read(port->reg_ts_clk_en));
1138 dprintk(1, "%s() ts_int_msk(0x%08X) 0x%08x\n", __FUNCTION__,
1139 port->reg_ts_int_msk, cx_read(port->reg_ts_int_msk));
1015} 1140}
1016 1141
1017static int cx23885_start_dma(struct cx23885_tsport *port, 1142static int cx23885_start_dma(struct cx23885_tsport *port,
@@ -1076,6 +1201,9 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1076 1201
1077 cx_set(DEV_CNTRL2, (1<<5)); /* Enable RISC controller */ 1202 cx_set(DEV_CNTRL2, (1<<5)); /* Enable RISC controller */
1078 1203
1204 if (debug > 4)
1205 cx23885_tsport_reg_dump(port);
1206
1079 return 0; 1207 return 0;
1080} 1208}
1081 1209
@@ -1091,7 +1219,7 @@ static int cx23885_stop_dma(struct cx23885_tsport *port)
1091 return 0; 1219 return 0;
1092} 1220}
1093 1221
1094static int cx23885_restart_queue(struct cx23885_tsport *port, 1222int cx23885_restart_queue(struct cx23885_tsport *port,
1095 struct cx23885_dmaqueue *q) 1223 struct cx23885_dmaqueue *q)
1096{ 1224{
1097 struct cx23885_dev *dev = port->dev; 1225 struct cx23885_dev *dev = port->dev;
@@ -1114,7 +1242,7 @@ static int cx23885_restart_queue(struct cx23885_tsport *port,
1114 list_del(&buf->vb.queue); 1242 list_del(&buf->vb.queue);
1115 list_add_tail(&buf->vb.queue, &q->active); 1243 list_add_tail(&buf->vb.queue, &q->active);
1116 cx23885_start_dma(port, q, buf); 1244 cx23885_start_dma(port, q, buf);
1117 buf->vb.state = STATE_ACTIVE; 1245 buf->vb.state = VIDEOBUF_ACTIVE;
1118 buf->count = q->count++; 1246 buf->count = q->count++;
1119 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 1247 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
1120 dprintk(5, "[%p/%d] restart_queue - first active\n", 1248 dprintk(5, "[%p/%d] restart_queue - first active\n",
@@ -1125,7 +1253,7 @@ static int cx23885_restart_queue(struct cx23885_tsport *port,
1125 prev->fmt == buf->fmt) { 1253 prev->fmt == buf->fmt) {
1126 list_del(&buf->vb.queue); 1254 list_del(&buf->vb.queue);
1127 list_add_tail(&buf->vb.queue, &q->active); 1255 list_add_tail(&buf->vb.queue, &q->active);
1128 buf->vb.state = STATE_ACTIVE; 1256 buf->vb.state = VIDEOBUF_ACTIVE;
1129 buf->count = q->count++; 1257 buf->count = q->count++;
1130 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 1258 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
1131 prev->risc.jmp[2] = cpu_to_le32(0); /* 64 bit bits 63-32 */ 1259 prev->risc.jmp[2] = cpu_to_le32(0); /* 64 bit bits 63-32 */
@@ -1162,7 +1290,7 @@ int cx23885_buf_prepare(struct videobuf_queue *q, struct cx23885_tsport *port,
1162 if (0 != buf->vb.baddr && buf->vb.bsize < size) 1290 if (0 != buf->vb.baddr && buf->vb.bsize < size)
1163 return -EINVAL; 1291 return -EINVAL;
1164 1292
1165 if (STATE_NEEDS_INIT == buf->vb.state) { 1293 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
1166 buf->vb.width = port->ts_packet_size; 1294 buf->vb.width = port->ts_packet_size;
1167 buf->vb.height = port->ts_packet_count; 1295 buf->vb.height = port->ts_packet_count;
1168 buf->vb.size = size; 1296 buf->vb.size = size;
@@ -1174,7 +1302,7 @@ int cx23885_buf_prepare(struct videobuf_queue *q, struct cx23885_tsport *port,
1174 videobuf_to_dma(&buf->vb)->sglist, 1302 videobuf_to_dma(&buf->vb)->sglist,
1175 buf->vb.width, buf->vb.height); 1303 buf->vb.width, buf->vb.height);
1176 } 1304 }
1177 buf->vb.state = STATE_PREPARED; 1305 buf->vb.state = VIDEOBUF_PREPARED;
1178 return 0; 1306 return 0;
1179 1307
1180 fail: 1308 fail:
@@ -1197,7 +1325,7 @@ void cx23885_buf_queue(struct cx23885_tsport *port, struct cx23885_buffer *buf)
1197 dprintk( 1, "queue is empty - first active\n" ); 1325 dprintk( 1, "queue is empty - first active\n" );
1198 list_add_tail(&buf->vb.queue, &cx88q->active); 1326 list_add_tail(&buf->vb.queue, &cx88q->active);
1199 cx23885_start_dma(port, cx88q, buf); 1327 cx23885_start_dma(port, cx88q, buf);
1200 buf->vb.state = STATE_ACTIVE; 1328 buf->vb.state = VIDEOBUF_ACTIVE;
1201 buf->count = cx88q->count++; 1329 buf->count = cx88q->count++;
1202 mod_timer(&cx88q->timeout, jiffies + BUFFER_TIMEOUT); 1330 mod_timer(&cx88q->timeout, jiffies + BUFFER_TIMEOUT);
1203 dprintk(1, "[%p/%d] %s - first active\n", 1331 dprintk(1, "[%p/%d] %s - first active\n",
@@ -1207,7 +1335,7 @@ void cx23885_buf_queue(struct cx23885_tsport *port, struct cx23885_buffer *buf)
1207 prev = list_entry(cx88q->active.prev, struct cx23885_buffer, 1335 prev = list_entry(cx88q->active.prev, struct cx23885_buffer,
1208 vb.queue); 1336 vb.queue);
1209 list_add_tail(&buf->vb.queue, &cx88q->active); 1337 list_add_tail(&buf->vb.queue, &cx88q->active);
1210 buf->vb.state = STATE_ACTIVE; 1338 buf->vb.state = VIDEOBUF_ACTIVE;
1211 buf->count = cx88q->count++; 1339 buf->count = cx88q->count++;
1212 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 1340 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
1213 prev->risc.jmp[2] = cpu_to_le32(0); /* 64 bit bits 63-32 */ 1341 prev->risc.jmp[2] = cpu_to_le32(0); /* 64 bit bits 63-32 */
@@ -1231,7 +1359,7 @@ static void do_cancel_buffers(struct cx23885_tsport *port, char *reason,
1231 buf = list_entry(q->active.next, struct cx23885_buffer, 1359 buf = list_entry(q->active.next, struct cx23885_buffer,
1232 vb.queue); 1360 vb.queue);
1233 list_del(&buf->vb.queue); 1361 list_del(&buf->vb.queue);
1234 buf->vb.state = STATE_ERROR; 1362 buf->vb.state = VIDEOBUF_ERROR;
1235 wake_up(&buf->vb.done); 1363 wake_up(&buf->vb.done);
1236 dprintk(1, "[%p/%d] %s - dma=0x%08lx\n", 1364 dprintk(1, "[%p/%d] %s - dma=0x%08lx\n",
1237 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma); 1365 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma);
@@ -1243,16 +1371,6 @@ static void do_cancel_buffers(struct cx23885_tsport *port, char *reason,
1243 spin_unlock_irqrestore(&port->slock, flags); 1371 spin_unlock_irqrestore(&port->slock, flags);
1244} 1372}
1245 1373
1246void cx23885_cancel_buffers(struct cx23885_tsport *port)
1247{
1248 struct cx23885_dev *dev = port->dev;
1249 struct cx23885_dmaqueue *q = &port->mpegq;
1250
1251 dprintk(1, "%s()\n", __FUNCTION__);
1252 del_timer_sync(&q->timeout);
1253 cx23885_stop_dma(port);
1254 do_cancel_buffers(port, "cancel", 0);
1255}
1256 1374
1257static void cx23885_timeout(unsigned long data) 1375static void cx23885_timeout(unsigned long data)
1258{ 1376{
@@ -1325,12 +1443,15 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1325 struct cx23885_tsport *ts1 = &dev->ts1; 1443 struct cx23885_tsport *ts1 = &dev->ts1;
1326 struct cx23885_tsport *ts2 = &dev->ts2; 1444 struct cx23885_tsport *ts2 = &dev->ts2;
1327 u32 pci_status, pci_mask; 1445 u32 pci_status, pci_mask;
1446 u32 vida_status, vida_mask;
1328 u32 ts1_status, ts1_mask; 1447 u32 ts1_status, ts1_mask;
1329 u32 ts2_status, ts2_mask; 1448 u32 ts2_status, ts2_mask;
1330 int ts1_count = 0, ts2_count = 0, handled = 0; 1449 int vida_count = 0, ts1_count = 0, ts2_count = 0, handled = 0;
1331 1450
1332 pci_status = cx_read(PCI_INT_STAT); 1451 pci_status = cx_read(PCI_INT_STAT);
1333 pci_mask = cx_read(PCI_INT_MSK); 1452 pci_mask = cx_read(PCI_INT_MSK);
1453 vida_status = cx_read(VID_A_INT_STAT);
1454 vida_mask = cx_read(VID_A_INT_MSK);
1334 ts1_status = cx_read(VID_B_INT_STAT); 1455 ts1_status = cx_read(VID_B_INT_STAT);
1335 ts1_mask = cx_read(VID_B_INT_MSK); 1456 ts1_mask = cx_read(VID_B_INT_MSK);
1336 ts2_status = cx_read(VID_C_INT_STAT); 1457 ts2_status = cx_read(VID_C_INT_STAT);
@@ -1339,11 +1460,17 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1339 if ( (pci_status == 0) && (ts2_status == 0) && (ts1_status == 0) ) 1460 if ( (pci_status == 0) && (ts2_status == 0) && (ts1_status == 0) )
1340 goto out; 1461 goto out;
1341 1462
1463 vida_count = cx_read(VID_A_GPCNT);
1342 ts1_count = cx_read(ts1->reg_gpcnt); 1464 ts1_count = cx_read(ts1->reg_gpcnt);
1343 ts2_count = cx_read(ts2->reg_gpcnt); 1465 ts2_count = cx_read(ts2->reg_gpcnt);
1344 dprintk(7, "pci_status: 0x%08x pci_mask: 0x%08x\n", pci_status, pci_mask ); 1466 dprintk(7, "pci_status: 0x%08x pci_mask: 0x%08x\n",
1345 dprintk(7, "ts1_status: 0x%08x ts1_mask: 0x%08x count: 0x%x\n", ts1_status, ts1_mask, ts1_count ); 1467 pci_status, pci_mask);
1346 dprintk(7, "ts2_status: 0x%08x ts2_mask: 0x%08x count: 0x%x\n", ts2_status, ts2_mask, ts2_count ); 1468 dprintk(7, "vida_status: 0x%08x vida_mask: 0x%08x count: 0x%x\n",
1469 vida_status, vida_mask, vida_count);
1470 dprintk(7, "ts1_status: 0x%08x ts1_mask: 0x%08x count: 0x%x\n",
1471 ts1_status, ts1_mask, ts1_count);
1472 dprintk(7, "ts2_status: 0x%08x ts2_mask: 0x%08x count: 0x%x\n",
1473 ts2_status, ts2_mask, ts2_count);
1347 1474
1348 if ( (pci_status & PCI_MSK_RISC_RD) || 1475 if ( (pci_status & PCI_MSK_RISC_RD) ||
1349 (pci_status & PCI_MSK_RISC_WR) || 1476 (pci_status & PCI_MSK_RISC_WR) ||
@@ -1380,11 +1507,18 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1380 1507
1381 } 1508 }
1382 1509
1383 if (ts1_status) 1510 if (ts1_status) {
1384 handled += cx23885_irq_ts(ts1, ts1_status); 1511 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB)
1512 handled += cx23885_irq_ts(ts1, ts1_status);
1513 }
1514
1515 if (ts2_status) {
1516 if (cx23885_boards[dev->board].portc == CX23885_MPEG_DVB)
1517 handled += cx23885_irq_ts(ts2, ts2_status);
1518 }
1385 1519
1386 if (ts2_status) 1520 if (vida_status)
1387 handled += cx23885_irq_ts(ts2, ts2_status); 1521 handled += cx23885_video_irq(dev, vida_status);
1388 1522
1389 if (handled) 1523 if (handled)
1390 cx_write(PCI_INT_STAT, pci_status); 1524 cx_write(PCI_INT_STAT, pci_status);
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
index eda8c05d0931..ed465c007cea 100644
--- a/drivers/media/video/cx23885/cx23885-dvb.c
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -32,13 +32,26 @@
32 32
33#include "s5h1409.h" 33#include "s5h1409.h"
34#include "mt2131.h" 34#include "mt2131.h"
35#include "tda8290.h"
36#include "tda18271.h"
35#include "lgdt330x.h" 37#include "lgdt330x.h"
38#include "xc5000.h"
36#include "dvb-pll.h" 39#include "dvb-pll.h"
40#include "tuner-xc2028.h"
41#include "tuner-xc2028-types.h"
37 42
38static unsigned int debug = 0; 43static unsigned int debug;
39 44
40#define dprintk(level,fmt, arg...) if (debug >= level) \ 45#define dprintk(level, fmt, arg...)\
41 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg) 46 do { if (debug >= level)\
47 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
48 } while (0)
49
50/* ------------------------------------------------------------------ */
51
52static unsigned int alt_tuner;
53module_param(alt_tuner, int, 0644);
54MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
42 55
43/* ------------------------------------------------------------------ */ 56/* ------------------------------------------------------------------ */
44 57
@@ -85,18 +98,39 @@ static struct s5h1409_config hauppauge_generic_config = {
85 .demod_address = 0x32 >> 1, 98 .demod_address = 0x32 >> 1,
86 .output_mode = S5H1409_SERIAL_OUTPUT, 99 .output_mode = S5H1409_SERIAL_OUTPUT,
87 .gpio = S5H1409_GPIO_ON, 100 .gpio = S5H1409_GPIO_ON,
88 .if_freq = 44000, 101 .qam_if = 44000,
89 .inversion = S5H1409_INVERSION_OFF, 102 .inversion = S5H1409_INVERSION_OFF,
90 .status_mode = S5H1409_DEMODLOCKING 103 .status_mode = S5H1409_DEMODLOCKING,
104 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
105};
106
107static struct s5h1409_config hauppauge_ezqam_config = {
108 .demod_address = 0x32 >> 1,
109 .output_mode = S5H1409_SERIAL_OUTPUT,
110 .gpio = S5H1409_GPIO_OFF,
111 .qam_if = 4000,
112 .inversion = S5H1409_INVERSION_ON,
113 .status_mode = S5H1409_DEMODLOCKING,
114 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
91}; 115};
92 116
93static struct s5h1409_config hauppauge_hvr1800lp_config = { 117static struct s5h1409_config hauppauge_hvr1800lp_config = {
94 .demod_address = 0x32 >> 1, 118 .demod_address = 0x32 >> 1,
95 .output_mode = S5H1409_SERIAL_OUTPUT, 119 .output_mode = S5H1409_SERIAL_OUTPUT,
96 .gpio = S5H1409_GPIO_OFF, 120 .gpio = S5H1409_GPIO_OFF,
97 .if_freq = 44000, 121 .qam_if = 44000,
122 .inversion = S5H1409_INVERSION_OFF,
123 .status_mode = S5H1409_DEMODLOCKING,
124 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
125};
126
127static struct s5h1409_config hauppauge_hvr1500_config = {
128 .demod_address = 0x32 >> 1,
129 .output_mode = S5H1409_SERIAL_OUTPUT,
130 .gpio = S5H1409_GPIO_OFF,
98 .inversion = S5H1409_INVERSION_OFF, 131 .inversion = S5H1409_INVERSION_OFF,
99 .status_mode = S5H1409_DEMODLOCKING 132 .status_mode = S5H1409_DEMODLOCKING,
133 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
100}; 134};
101 135
102static struct mt2131_config hauppauge_generic_tunerconfig = { 136static struct mt2131_config hauppauge_generic_tunerconfig = {
@@ -109,6 +143,66 @@ static struct lgdt330x_config fusionhdtv_5_express = {
109 .serial_mpeg = 0x40, 143 .serial_mpeg = 0x40,
110}; 144};
111 145
146static struct s5h1409_config hauppauge_hvr1500q_config = {
147 .demod_address = 0x32 >> 1,
148 .output_mode = S5H1409_SERIAL_OUTPUT,
149 .gpio = S5H1409_GPIO_ON,
150 .qam_if = 44000,
151 .inversion = S5H1409_INVERSION_OFF,
152 .status_mode = S5H1409_DEMODLOCKING,
153 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
154};
155
156static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
157 .i2c_address = 0x61,
158 .if_khz = 5380,
159 .tuner_callback = cx23885_tuner_callback
160};
161
162static struct tda829x_config tda829x_no_probe = {
163 .probe_tuner = TDA829X_DONT_PROBE,
164};
165
166static struct tda18271_std_map hauppauge_tda18271_std_map = {
167 .atsc_6 = { .if_freq = 5380, .std_bits = 0x1b },
168 .qam_6 = { .if_freq = 4000, .std_bits = 0x18 },
169};
170
171static struct tda18271_config hauppauge_tda18271_config = {
172 .std_map = &hauppauge_tda18271_std_map,
173 .gate = TDA18271_GATE_ANALOG,
174};
175
176static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
177{
178 struct cx23885_tsport *port = ptr;
179 struct cx23885_dev *dev = port->dev;
180
181 switch (command) {
182 case XC2028_TUNER_RESET:
183 /* Send the tuner in then out of reset */
184 /* GPIO-2 xc3028 tuner */
185 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg);
186
187 cx_set(GP0_IO, 0x00040000);
188 cx_clear(GP0_IO, 0x00000004);
189 msleep(5);
190
191 cx_set(GP0_IO, 0x00040004);
192 msleep(5);
193 break;
194 case XC2028_RESET_CLK:
195 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg);
196 break;
197 default:
198 dprintk(1, "%s: unknown command %d, arg %d\n", __FUNCTION__,
199 command, arg);
200 return -EINVAL;
201 }
202
203 return 0;
204}
205
112static int dvb_register(struct cx23885_tsport *port) 206static int dvb_register(struct cx23885_tsport *port)
113{ 207{
114 struct cx23885_dev *dev = port->dev; 208 struct cx23885_dev *dev = port->dev;
@@ -120,7 +214,6 @@ static int dvb_register(struct cx23885_tsport *port)
120 /* init frontend */ 214 /* init frontend */
121 switch (dev->board) { 215 switch (dev->board) {
122 case CX23885_BOARD_HAUPPAUGE_HVR1250: 216 case CX23885_BOARD_HAUPPAUGE_HVR1250:
123 case CX23885_BOARD_HAUPPAUGE_HVR1800:
124 i2c_bus = &dev->i2c_bus[0]; 217 i2c_bus = &dev->i2c_bus[0];
125 port->dvb.frontend = dvb_attach(s5h1409_attach, 218 port->dvb.frontend = dvb_attach(s5h1409_attach,
126 &hauppauge_generic_config, 219 &hauppauge_generic_config,
@@ -131,6 +224,36 @@ static int dvb_register(struct cx23885_tsport *port)
131 &hauppauge_generic_tunerconfig, 0); 224 &hauppauge_generic_tunerconfig, 0);
132 } 225 }
133 break; 226 break;
227 case CX23885_BOARD_HAUPPAUGE_HVR1800:
228 i2c_bus = &dev->i2c_bus[0];
229 switch (alt_tuner) {
230 case 1:
231 port->dvb.frontend =
232 dvb_attach(s5h1409_attach,
233 &hauppauge_ezqam_config,
234 &i2c_bus->i2c_adap);
235 if (port->dvb.frontend != NULL) {
236 dvb_attach(tda829x_attach, port->dvb.frontend,
237 &dev->i2c_bus[1].i2c_adap, 0x42,
238 &tda829x_no_probe);
239 dvb_attach(tda18271_attach, port->dvb.frontend,
240 0x60, &dev->i2c_bus[1].i2c_adap,
241 &hauppauge_tda18271_config);
242 }
243 break;
244 case 0:
245 default:
246 port->dvb.frontend =
247 dvb_attach(s5h1409_attach,
248 &hauppauge_generic_config,
249 &i2c_bus->i2c_adap);
250 if (port->dvb.frontend != NULL)
251 dvb_attach(mt2131_attach, port->dvb.frontend,
252 &i2c_bus->i2c_adap,
253 &hauppauge_generic_tunerconfig, 0);
254 break;
255 }
256 break;
134 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 257 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
135 i2c_bus = &dev->i2c_bus[0]; 258 i2c_bus = &dev->i2c_bus[0];
136 port->dvb.frontend = dvb_attach(s5h1409_attach, 259 port->dvb.frontend = dvb_attach(s5h1409_attach,
@@ -152,6 +275,43 @@ static int dvb_register(struct cx23885_tsport *port)
152 &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF); 275 &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF);
153 } 276 }
154 break; 277 break;
278 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
279 i2c_bus = &dev->i2c_bus[1];
280 port->dvb.frontend = dvb_attach(s5h1409_attach,
281 &hauppauge_hvr1500q_config,
282 &dev->i2c_bus[0].i2c_adap);
283 if (port->dvb.frontend != NULL) {
284 hauppauge_hvr1500q_tunerconfig.priv = i2c_bus;
285 dvb_attach(xc5000_attach, port->dvb.frontend,
286 &i2c_bus->i2c_adap,
287 &hauppauge_hvr1500q_tunerconfig);
288 }
289 break;
290 case CX23885_BOARD_HAUPPAUGE_HVR1500:
291 i2c_bus = &dev->i2c_bus[1];
292 port->dvb.frontend = dvb_attach(s5h1409_attach,
293 &hauppauge_hvr1500_config,
294 &dev->i2c_bus[0].i2c_adap);
295 if (port->dvb.frontend != NULL) {
296 struct dvb_frontend *fe;
297 struct xc2028_config cfg = {
298 .i2c_adap = &i2c_bus->i2c_adap,
299 .i2c_addr = 0x61,
300 .video_dev = port,
301 .callback = cx23885_hvr1500_xc3028_callback,
302 };
303 static struct xc2028_ctrl ctl = {
304 .fname = "xc3028-v27.fw",
305 .max_len = 64,
306 .scode_table = OREN538,
307 };
308
309 fe = dvb_attach(xc2028_attach,
310 port->dvb.frontend, &cfg);
311 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
312 fe->ops.tuner_ops.set_config(fe, &ctl);
313 }
314 break;
155 default: 315 default:
156 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n", 316 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
157 dev->name); 317 dev->name);
@@ -165,6 +325,9 @@ static int dvb_register(struct cx23885_tsport *port)
165 /* Put the analog decoder in standby to keep it quiet */ 325 /* Put the analog decoder in standby to keep it quiet */
166 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL); 326 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
167 327
328 if (port->dvb.frontend->ops.analog_ops.standby)
329 port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend);
330
168 /* register everything */ 331 /* register everything */
169 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port, 332 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
170 &dev->pci->dev); 333 &dev->pci->dev);
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c
index 71da528932df..92fe0bd37c84 100644
--- a/drivers/media/video/cx23885/cx23885-i2c.c
+++ b/drivers/media/video/cx23885/cx23885-i2c.c
@@ -29,7 +29,7 @@
29 29
30#include <media/v4l2-common.h> 30#include <media/v4l2-common.h>
31 31
32static unsigned int i2c_debug = 0; 32static unsigned int i2c_debug;
33module_param(i2c_debug, int, 0644); 33module_param(i2c_debug, int, 0644);
34MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); 34MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
35 35
@@ -37,8 +37,10 @@ static unsigned int i2c_scan = 0;
37module_param(i2c_scan, int, 0444); 37module_param(i2c_scan, int, 0444);
38MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); 38MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
39 39
40#define dprintk(level,fmt, arg...) if (i2c_debug >= level) \ 40#define dprintk(level, fmt, arg...)\
41 printk(KERN_DEBUG "%s: " fmt, dev->name , ## arg) 41 do { if (i2c_debug >= level)\
42 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
43 } while (0)
42 44
43#define I2C_WAIT_DELAY 32 45#define I2C_WAIT_DELAY 32
44#define I2C_WAIT_RETRY 64 46#define I2C_WAIT_RETRY 64
@@ -77,14 +79,19 @@ static int i2c_wait_done(struct i2c_adapter *i2c_adap)
77} 79}
78 80
79static int i2c_sendbytes(struct i2c_adapter *i2c_adap, 81static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
80 const struct i2c_msg *msg, int last) 82 const struct i2c_msg *msg, int joined_rlen)
81{ 83{
82 struct cx23885_i2c *bus = i2c_adap->algo_data; 84 struct cx23885_i2c *bus = i2c_adap->algo_data;
83 struct cx23885_dev *dev = bus->dev; 85 struct cx23885_dev *dev = bus->dev;
84 u32 wdata, addr, ctrl; 86 u32 wdata, addr, ctrl;
85 int retval, cnt; 87 int retval, cnt;
86 88
87 dprintk(1, "%s()\n", __FUNCTION__); 89 if (joined_rlen)
90 dprintk(1, "%s(msg->wlen=%d, nextmsg->rlen=%d)\n", __FUNCTION__,
91 msg->len, joined_rlen);
92 else
93 dprintk(1, "%s(msg->len=%d)\n", __FUNCTION__, msg->len);
94
88 /* Deal with i2c probe functions with zero payload */ 95 /* Deal with i2c probe functions with zero payload */
89 if (msg->len == 0) { 96 if (msg->len == 0) {
90 cx_write(bus->reg_addr, msg->addr << 25); 97 cx_write(bus->reg_addr, msg->addr << 25);
@@ -106,6 +113,8 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
106 113
107 if (msg->len > 1) 114 if (msg->len > 1)
108 ctrl |= I2C_NOSTOP | I2C_EXTEND; 115 ctrl |= I2C_NOSTOP | I2C_EXTEND;
116 else if (joined_rlen)
117 ctrl |= I2C_NOSTOP;
109 118
110 cx_write(bus->reg_addr, addr); 119 cx_write(bus->reg_addr, addr);
111 cx_write(bus->reg_wdata, wdata); 120 cx_write(bus->reg_wdata, wdata);
@@ -127,8 +136,10 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
127 wdata = msg->buf[cnt]; 136 wdata = msg->buf[cnt];
128 ctrl = bus->i2c_period | (1 << 12) | (1 << 2); 137 ctrl = bus->i2c_period | (1 << 12) | (1 << 2);
129 138
130 if (cnt < msg->len-1 || !last) 139 if (cnt < msg->len - 1)
131 ctrl |= I2C_NOSTOP | I2C_EXTEND; 140 ctrl |= I2C_NOSTOP | I2C_EXTEND;
141 else if (joined_rlen)
142 ctrl |= I2C_NOSTOP;
132 143
133 cx_write(bus->reg_addr, addr); 144 cx_write(bus->reg_addr, addr);
134 cx_write(bus->reg_wdata, wdata); 145 cx_write(bus->reg_wdata, wdata);
@@ -150,19 +161,22 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
150 eio: 161 eio:
151 retval = -EIO; 162 retval = -EIO;
152 err: 163 err:
153 printk(" ERR: %d\n", retval); 164 if (i2c_debug)
165 printk(" ERR: %d\n", retval);
154 return retval; 166 return retval;
155} 167}
156 168
157static int i2c_readbytes(struct i2c_adapter *i2c_adap, 169static int i2c_readbytes(struct i2c_adapter *i2c_adap,
158 const struct i2c_msg *msg, int last) 170 const struct i2c_msg *msg, int joined)
159{ 171{
160 struct cx23885_i2c *bus = i2c_adap->algo_data; 172 struct cx23885_i2c *bus = i2c_adap->algo_data;
161 struct cx23885_dev *dev = bus->dev; 173 struct cx23885_dev *dev = bus->dev;
162 u32 ctrl, cnt; 174 u32 ctrl, cnt;
163 int retval; 175 int retval;
164 176
165 dprintk(1, "%s()\n", __FUNCTION__); 177
178 if (i2c_debug && !joined)
179 dprintk(1, "%s(msg->len=%d)\n", __FUNCTION__, msg->len);
166 180
167 /* Deal with i2c probe functions with zero payload */ 181 /* Deal with i2c probe functions with zero payload */
168 if (msg->len == 0) { 182 if (msg->len == 0) {
@@ -178,11 +192,18 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
178 return 0; 192 return 0;
179 } 193 }
180 194
195 if (i2c_debug) {
196 if (joined)
197 printk(" R");
198 else
199 printk(" <R %02x", (msg->addr << 1) + 1);
200 }
201
181 for(cnt = 0; cnt < msg->len; cnt++) { 202 for(cnt = 0; cnt < msg->len; cnt++) {
182 203
183 ctrl = bus->i2c_period | (1 << 12) | (1 << 2) | 1; 204 ctrl = bus->i2c_period | (1 << 12) | (1 << 2) | 1;
184 205
185 if (cnt < msg->len-1 || !last) 206 if (cnt < msg->len - 1)
186 ctrl |= I2C_NOSTOP | I2C_EXTEND; 207 ctrl |= I2C_NOSTOP | I2C_EXTEND;
187 208
188 cx_write(bus->reg_addr, msg->addr << 25); 209 cx_write(bus->reg_addr, msg->addr << 25);
@@ -195,9 +216,7 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
195 goto eio; 216 goto eio;
196 msg->buf[cnt] = cx_read(bus->reg_rdata) & 0xff; 217 msg->buf[cnt] = cx_read(bus->reg_rdata) & 0xff;
197 if (i2c_debug) { 218 if (i2c_debug) {
198 if (!(ctrl & I2C_NOSTOP)) 219 printk(" %02x", msg->buf[cnt]);
199 printk(" <R %02x", (msg->addr << 1) +1);
200 printk(" =%02x", msg->buf[cnt]);
201 if (!(ctrl & I2C_NOSTOP)) 220 if (!(ctrl & I2C_NOSTOP))
202 printk(" >\n"); 221 printk(" >\n");
203 } 222 }
@@ -207,7 +226,8 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
207 eio: 226 eio:
208 retval = -EIO; 227 retval = -EIO;
209 err: 228 err:
210 printk(" ERR: %d\n", retval); 229 if (i2c_debug)
230 printk(" ERR: %d\n", retval);
211 return retval; 231 return retval;
212} 232}
213 233
@@ -225,15 +245,22 @@ static int i2c_xfer(struct i2c_adapter *i2c_adap,
225 __FUNCTION__, num, msgs[i].addr, msgs[i].len); 245 __FUNCTION__, num, msgs[i].addr, msgs[i].len);
226 if (msgs[i].flags & I2C_M_RD) { 246 if (msgs[i].flags & I2C_M_RD) {
227 /* read */ 247 /* read */
228 retval = i2c_readbytes(i2c_adap, &msgs[i], i+1 == num); 248 retval = i2c_readbytes(i2c_adap, &msgs[i], 0);
249 } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) &&
250 msgs[i].addr == msgs[i + 1].addr) {
251 /* write then read from same address */
252 retval = i2c_sendbytes(i2c_adap, &msgs[i],
253 msgs[i + 1].len);
229 if (retval < 0) 254 if (retval < 0)
230 goto err; 255 goto err;
256 i++;
257 retval = i2c_readbytes(i2c_adap, &msgs[i], 1);
231 } else { 258 } else {
232 /* write */ 259 /* write */
233 retval = i2c_sendbytes(i2c_adap, &msgs[i], i+1 == num); 260 retval = i2c_sendbytes(i2c_adap, &msgs[i], 0);
234 if (retval < 0)
235 goto err;
236 } 261 }
262 if (retval < 0)
263 goto err;
237 } 264 }
238 return num; 265 return num;
239 266
@@ -243,7 +270,9 @@ static int i2c_xfer(struct i2c_adapter *i2c_adap,
243 270
244static int attach_inform(struct i2c_client *client) 271static int attach_inform(struct i2c_client *client)
245{ 272{
246 struct cx23885_dev *dev = i2c_get_adapdata(client->adapter); 273 struct cx23885_i2c *bus = i2c_get_adapdata(client->adapter);
274 struct cx23885_dev *dev = bus->dev;
275 struct tuner_setup tun_setup;
247 276
248 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n", 277 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
249 client->driver->driver.name, client->addr, client->name); 278 client->driver->driver.name, client->addr, client->name);
@@ -251,6 +280,31 @@ static int attach_inform(struct i2c_client *client)
251 if (!client->driver->command) 280 if (!client->driver->command)
252 return 0; 281 return 0;
253 282
283 if (dev->tuner_type != UNSET) {
284
285 dprintk(1, "%s (tuner) i2c attach [addr=0x%x,client=%s]\n",
286 client->driver->driver.name, client->addr,
287 client->name);
288
289 if ((dev->tuner_addr == ADDR_UNSET) ||
290 (dev->tuner_addr == client->addr)) {
291
292 dprintk(1, "%s (tuner || addr UNSET)\n",
293 client->driver->driver.name);
294
295 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
296 client->driver->driver.name,
297 client->addr, client->name);
298
299 tun_setup.mode_mask = T_ANALOG_TV;
300 tun_setup.type = dev->tuner_type;
301 tun_setup.addr = dev->tuner_addr;
302
303 client->driver->command(client, TUNER_SET_TYPE_ADDR,
304 &tun_setup);
305 }
306 }
307
254 return 0; 308 return 0;
255} 309}
256 310
@@ -289,6 +343,7 @@ static struct i2c_adapter cx23885_i2c_adap_template = {
289 .owner = THIS_MODULE, 343 .owner = THIS_MODULE,
290 .id = I2C_HW_B_CX23885, 344 .id = I2C_HW_B_CX23885,
291 .algo = &cx23885_i2c_algo_template, 345 .algo = &cx23885_i2c_algo_template,
346 .class = I2C_CLASS_TV_ANALOG,
292 .client_register = attach_inform, 347 .client_register = attach_inform,
293 .client_unregister = detach_inform, 348 .client_unregister = detach_inform,
294}; 349};
@@ -305,7 +360,7 @@ static char *i2c_devs[128] = {
305 [ 0x84 >> 1 ] = "tda8295", 360 [ 0x84 >> 1 ] = "tda8295",
306 [ 0xa0 >> 1 ] = "eeprom", 361 [ 0xa0 >> 1 ] = "eeprom",
307 [ 0xc0 >> 1 ] = "tuner/mt2131/tda8275", 362 [ 0xc0 >> 1 ] = "tuner/mt2131/tda8275",
308 [ 0xc2 >> 1 ] = "tuner/mt2131/tda8275", 363 [ 0xc2 >> 1 ] = "tuner/mt2131/tda8275/xc5000",
309}; 364};
310 365
311static void do_i2c_scan(char *name, struct i2c_client *c) 366static void do_i2c_scan(char *name, struct i2c_client *c)
@@ -344,6 +399,7 @@ int cx23885_i2c_register(struct cx23885_i2c *bus)
344 399
345 bus->i2c_algo.data = bus; 400 bus->i2c_algo.data = bus;
346 bus->i2c_adap.algo_data = bus; 401 bus->i2c_adap.algo_data = bus;
402 i2c_set_adapdata(&bus->i2c_adap, bus);
347 i2c_add_adapter(&bus->i2c_adap); 403 i2c_add_adapter(&bus->i2c_adap);
348 404
349 bus->i2c_client.adapter = &bus->i2c_adap; 405 bus->i2c_client.adapter = &bus->i2c_adap;
@@ -366,8 +422,6 @@ int cx23885_i2c_unregister(struct cx23885_i2c *bus)
366 422
367/* ----------------------------------------------------------------------- */ 423/* ----------------------------------------------------------------------- */
368 424
369EXPORT_SYMBOL(cx23885_call_i2c_clients);
370
371/* 425/*
372 * Local variables: 426 * Local variables:
373 * c-basic-offset: 8 427 * c-basic-offset: 8
diff --git a/drivers/media/video/cx23885/cx23885-reg.h b/drivers/media/video/cx23885/cx23885-reg.h
index 162169f9091b..bdd11bc513ad 100644
--- a/drivers/media/video/cx23885/cx23885-reg.h
+++ b/drivers/media/video/cx23885/cx23885-reg.h
@@ -233,6 +233,17 @@ Channel manager Data Structure entry = 20 DWORD
233#define VID_A_INT_SSTAT 0x0004002C 233#define VID_A_INT_SSTAT 0x0004002C
234 234
235#define VID_B_INT_MSK 0x00040030 235#define VID_B_INT_MSK 0x00040030
236#define VID_B_MSK_BAD_PKT (1 << 20)
237#define VID_B_MSK_VBI_OPC_ERR (1 << 17)
238#define VID_B_MSK_OPC_ERR (1 << 16)
239#define VID_B_MSK_VBI_SYNC (1 << 13)
240#define VID_B_MSK_SYNC (1 << 12)
241#define VID_B_MSK_VBI_OF (1 << 9)
242#define VID_B_MSK_OF (1 << 8)
243#define VID_B_MSK_VBI_RISCI2 (1 << 5)
244#define VID_B_MSK_RISCI2 (1 << 4)
245#define VID_B_MSK_VBI_RISCI1 (1 << 1)
246#define VID_B_MSK_RISCI1 1
236#define VID_B_INT_STAT 0x00040034 247#define VID_B_INT_STAT 0x00040034
237#define VID_B_INT_MSTAT 0x00040038 248#define VID_B_INT_MSTAT 0x00040038
238#define VID_B_INT_SSTAT 0x0004003C 249#define VID_B_INT_SSTAT 0x0004003C
@@ -276,6 +287,7 @@ Channel manager Data Structure entry = 20 DWORD
276 287
277#define RDR_CFG0 0x00050000 288#define RDR_CFG0 0x00050000
278#define RDR_CFG1 0x00050004 289#define RDR_CFG1 0x00050004
290#define RDR_CFG2 0x00050008
279#define RDR_TLCTL0 0x00050318 291#define RDR_TLCTL0 0x00050318
280 292
281/* APB DMAC Current Buffer Pointer */ 293/* APB DMAC Current Buffer Pointer */
@@ -335,6 +347,7 @@ Channel manager Data Structure entry = 20 DWORD
335/* GPIO (417 Microsoftcontroller) Output Enable, Low Active */ 347/* GPIO (417 Microsoftcontroller) Output Enable, Low Active */
336#define MC417_OEN 0x00110024 348#define MC417_OEN 0x00110024
337#define MC417_CTL 0x00110028 349#define MC417_CTL 0x00110028
350#define ALT_PIN_OUT_SEL 0x0011002C
338#define CLK_DELAY 0x00110048 351#define CLK_DELAY 0x00110048
339#define PAD_CTRL 0x0011004C 352#define PAD_CTRL 0x0011004C
340 353
diff --git a/drivers/media/video/cx23885/cx23885-vbi.c b/drivers/media/video/cx23885/cx23885-vbi.c
new file mode 100644
index 000000000000..e36e3fcae2fb
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-vbi.c
@@ -0,0 +1,258 @@
1/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
4 * Copyright (c) 2007 Steven Toth <stoth@hauppauge.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 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27
28#include "cx23885.h"
29
30static unsigned int vbibufs = 4;
31module_param(vbibufs, int, 0644);
32MODULE_PARM_DESC(vbibufs, "number of vbi buffers, range 2-32");
33
34static unsigned int vbi_debug;
35module_param(vbi_debug, int, 0644);
36MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]");
37
38#define dprintk(level, fmt, arg...)\
39 do { if (vbi_debug >= level)\
40 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
41 } while (0)
42
43/* ------------------------------------------------------------------ */
44
45int cx23885_vbi_fmt(struct file *file, void *priv,
46 struct v4l2_format *f)
47{
48 struct cx23885_fh *fh = priv;
49 struct cx23885_dev *dev = fh->dev;
50
51 if (dev->tvnorm & V4L2_STD_525_60) {
52 /* ntsc */
53 f->fmt.vbi.sampling_rate = 28636363;
54 f->fmt.vbi.start[0] = 10;
55 f->fmt.vbi.start[1] = 273;
56
57 } else if (dev->tvnorm & V4L2_STD_625_50) {
58 /* pal */
59 f->fmt.vbi.sampling_rate = 35468950;
60 f->fmt.vbi.start[0] = 7 - 1;
61 f->fmt.vbi.start[1] = 319 - 1;
62 }
63 return 0;
64}
65
66static int cx23885_start_vbi_dma(struct cx23885_dev *dev,
67 struct cx23885_dmaqueue *q,
68 struct cx23885_buffer *buf)
69{
70 /* setup fifo + format */
71 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH02],
72 buf->vb.width, buf->risc.dma);
73
74 /* reset counter */
75 q->count = 1;
76
77 /* enable irqs */
78 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | 0x01);
79 cx_set(VID_A_INT_MSK, 0x000022);
80
81 /* start dma */
82 cx_set(DEV_CNTRL2, (1<<5));
83 cx_set(VID_A_DMA_CTL, 0x00000022);
84
85 return 0;
86}
87
88int cx23885_stop_vbi_dma(struct cx23885_dev *dev)
89{
90 /* stop dma */
91 cx_clear(VID_A_DMA_CTL, 0x00000022);
92
93 /* disable irqs */
94 cx_clear(PCI_INT_MSK, 0x000001);
95 cx_clear(VID_A_INT_MSK, 0x00000022);
96 return 0;
97}
98
99int cx23885_restart_vbi_queue(struct cx23885_dev *dev,
100 struct cx23885_dmaqueue *q)
101{
102 struct cx23885_buffer *buf;
103 struct list_head *item;
104
105 if (list_empty(&q->active))
106 return 0;
107
108 buf = list_entry(q->active.next, struct cx23885_buffer, vb.queue);
109 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
110 buf, buf->vb.i);
111 cx23885_start_vbi_dma(dev, q, buf);
112 list_for_each(item, &q->active) {
113 buf = list_entry(item, struct cx23885_buffer, vb.queue);
114 buf->count = q->count++;
115 }
116 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
117 return 0;
118}
119
120void cx23885_vbi_timeout(unsigned long data)
121{
122 struct cx23885_dev *dev = (struct cx23885_dev *)data;
123 struct cx23885_dmaqueue *q = &dev->vbiq;
124 struct cx23885_buffer *buf;
125 unsigned long flags;
126
127 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH02]);
128
129 cx_clear(VID_A_DMA_CTL, 0x22);
130
131 spin_lock_irqsave(&dev->slock, flags);
132 while (!list_empty(&q->active)) {
133 buf = list_entry(q->active.next, struct cx23885_buffer,
134 vb.queue);
135 list_del(&buf->vb.queue);
136 buf->vb.state = VIDEOBUF_ERROR;
137 wake_up(&buf->vb.done);
138 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev->name,
139 buf, buf->vb.i, (unsigned long)buf->risc.dma);
140 }
141 cx23885_restart_vbi_queue(dev, q);
142 spin_unlock_irqrestore(&dev->slock, flags);
143}
144
145/* ------------------------------------------------------------------ */
146#define VBI_LINE_LENGTH 2048
147#define VBI_LINE_COUNT 17
148
149static int
150vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
151{
152 *size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
153 if (0 == *count)
154 *count = vbibufs;
155 if (*count < 2)
156 *count = 2;
157 if (*count > 32)
158 *count = 32;
159 return 0;
160}
161
162static int
163vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
164 enum v4l2_field field)
165{
166 struct cx23885_fh *fh = q->priv_data;
167 struct cx23885_dev *dev = fh->dev;
168 struct cx23885_buffer *buf = container_of(vb,
169 struct cx23885_buffer, vb);
170 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
171 unsigned int size;
172 int rc;
173
174 size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
175 if (0 != buf->vb.baddr && buf->vb.bsize < size)
176 return -EINVAL;
177
178 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
179 buf->vb.width = VBI_LINE_LENGTH;
180 buf->vb.height = VBI_LINE_COUNT;
181 buf->vb.size = size;
182 buf->vb.field = V4L2_FIELD_SEQ_TB;
183
184 rc = videobuf_iolock(q, &buf->vb, NULL);
185 if (0 != rc)
186 goto fail;
187 cx23885_risc_buffer(dev->pci, &buf->risc,
188 dma->sglist,
189 0, buf->vb.width * buf->vb.height,
190 buf->vb.width, 0,
191 buf->vb.height);
192 }
193 buf->vb.state = VIDEOBUF_PREPARED;
194 return 0;
195
196 fail:
197 cx23885_free_buffer(q, buf);
198 return rc;
199}
200
201static void
202vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
203{
204 struct cx23885_buffer *buf =
205 container_of(vb, struct cx23885_buffer, vb);
206 struct cx23885_buffer *prev;
207 struct cx23885_fh *fh = vq->priv_data;
208 struct cx23885_dev *dev = fh->dev;
209 struct cx23885_dmaqueue *q = &dev->vbiq;
210
211 /* add jump to stopper */
212 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
213 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
214 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
215
216 if (list_empty(&q->active)) {
217 list_add_tail(&buf->vb.queue, &q->active);
218 cx23885_start_vbi_dma(dev, q, buf);
219 buf->vb.state = VIDEOBUF_ACTIVE;
220 buf->count = q->count++;
221 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
222 dprintk(2, "[%p/%d] vbi_queue - first active\n",
223 buf, buf->vb.i);
224
225 } else {
226 prev = list_entry(q->active.prev, struct cx23885_buffer,
227 vb.queue);
228 list_add_tail(&buf->vb.queue, &q->active);
229 buf->vb.state = VIDEOBUF_ACTIVE;
230 buf->count = q->count++;
231 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
232 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63-32 */
233 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
234 buf, buf->vb.i);
235 }
236}
237
238static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
239{
240 struct cx23885_buffer *buf =
241 container_of(vb, struct cx23885_buffer, vb);
242
243 cx23885_free_buffer(q, buf);
244}
245
246struct videobuf_queue_ops cx23885_vbi_qops = {
247 .buf_setup = vbi_setup,
248 .buf_prepare = vbi_prepare,
249 .buf_queue = vbi_queue,
250 .buf_release = vbi_release,
251};
252
253/* ------------------------------------------------------------------ */
254/*
255 * Local variables:
256 * c-basic-offset: 8
257 * End:
258 */
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
new file mode 100644
index 000000000000..d3c4d2c5cbe0
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -0,0 +1,1557 @@
1/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
4 * Copyright (c) 2007 Steven Toth <stoth@hauppauge.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 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/init.h>
23#include <linux/list.h>
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/kmod.h>
27#include <linux/kernel.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h>
30#include <linux/delay.h>
31#include <linux/kthread.h>
32#include <asm/div64.h>
33
34#include "cx23885.h"
35#include <media/v4l2-common.h>
36
37#ifdef CONFIG_VIDEO_V4L1_COMPAT
38/* Include V4L1 specific functions. Should be removed soon */
39#include <linux/videodev.h>
40#endif
41
42MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
43MODULE_AUTHOR("Steven Toth <stoth@hauppauge.com>");
44MODULE_LICENSE("GPL");
45
46/* ------------------------------------------------------------------ */
47
48static unsigned int video_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
49static unsigned int vbi_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
50static unsigned int radio_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
51
52module_param_array(video_nr, int, NULL, 0444);
53module_param_array(vbi_nr, int, NULL, 0444);
54module_param_array(radio_nr, int, NULL, 0444);
55
56MODULE_PARM_DESC(video_nr, "video device numbers");
57MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
58MODULE_PARM_DESC(radio_nr, "radio device numbers");
59
60static unsigned int video_debug;
61module_param(video_debug, int, 0644);
62MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
63
64static unsigned int irq_debug;
65module_param(irq_debug, int, 0644);
66MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
67
68static unsigned int vid_limit = 16;
69module_param(vid_limit, int, 0644);
70MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
71
72#define dprintk(level, fmt, arg...)\
73 do { if (video_debug >= level)\
74 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
75 } while (0)
76
77/* ------------------------------------------------------------------- */
78/* static data */
79
80#define FORMAT_FLAGS_PACKED 0x01
81
82static struct cx23885_fmt formats[] = {
83 {
84 .name = "8 bpp, gray",
85 .fourcc = V4L2_PIX_FMT_GREY,
86 .depth = 8,
87 .flags = FORMAT_FLAGS_PACKED,
88 }, {
89 .name = "15 bpp RGB, le",
90 .fourcc = V4L2_PIX_FMT_RGB555,
91 .depth = 16,
92 .flags = FORMAT_FLAGS_PACKED,
93 }, {
94 .name = "15 bpp RGB, be",
95 .fourcc = V4L2_PIX_FMT_RGB555X,
96 .depth = 16,
97 .flags = FORMAT_FLAGS_PACKED,
98 }, {
99 .name = "16 bpp RGB, le",
100 .fourcc = V4L2_PIX_FMT_RGB565,
101 .depth = 16,
102 .flags = FORMAT_FLAGS_PACKED,
103 }, {
104 .name = "16 bpp RGB, be",
105 .fourcc = V4L2_PIX_FMT_RGB565X,
106 .depth = 16,
107 .flags = FORMAT_FLAGS_PACKED,
108 }, {
109 .name = "24 bpp RGB, le",
110 .fourcc = V4L2_PIX_FMT_BGR24,
111 .depth = 24,
112 .flags = FORMAT_FLAGS_PACKED,
113 }, {
114 .name = "32 bpp RGB, le",
115 .fourcc = V4L2_PIX_FMT_BGR32,
116 .depth = 32,
117 .flags = FORMAT_FLAGS_PACKED,
118 }, {
119 .name = "32 bpp RGB, be",
120 .fourcc = V4L2_PIX_FMT_RGB32,
121 .depth = 32,
122 .flags = FORMAT_FLAGS_PACKED,
123 }, {
124 .name = "4:2:2, packed, YUYV",
125 .fourcc = V4L2_PIX_FMT_YUYV,
126 .depth = 16,
127 .flags = FORMAT_FLAGS_PACKED,
128 }, {
129 .name = "4:2:2, packed, UYVY",
130 .fourcc = V4L2_PIX_FMT_UYVY,
131 .depth = 16,
132 .flags = FORMAT_FLAGS_PACKED,
133 },
134};
135
136static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc)
137{
138 unsigned int i;
139
140 for (i = 0; i < ARRAY_SIZE(formats); i++)
141 if (formats[i].fourcc == fourcc)
142 return formats+i;
143
144 printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __FUNCTION__, fourcc);
145 return NULL;
146}
147
148/* ------------------------------------------------------------------- */
149
150static const struct v4l2_queryctrl no_ctl = {
151 .name = "42",
152 .flags = V4L2_CTRL_FLAG_DISABLED,
153};
154
155static struct cx23885_ctrl cx23885_ctls[] = {
156 /* --- video --- */
157 {
158 .v = {
159 .id = V4L2_CID_BRIGHTNESS,
160 .name = "Brightness",
161 .minimum = 0x00,
162 .maximum = 0xff,
163 .step = 1,
164 .default_value = 0x7f,
165 .type = V4L2_CTRL_TYPE_INTEGER,
166 },
167 .off = 128,
168 .reg = LUMA_CTRL,
169 .mask = 0x00ff,
170 .shift = 0,
171 }, {
172 .v = {
173 .id = V4L2_CID_CONTRAST,
174 .name = "Contrast",
175 .minimum = 0,
176 .maximum = 0xff,
177 .step = 1,
178 .default_value = 0x3f,
179 .type = V4L2_CTRL_TYPE_INTEGER,
180 },
181 .off = 0,
182 .reg = LUMA_CTRL,
183 .mask = 0xff00,
184 .shift = 8,
185 }, {
186 .v = {
187 .id = V4L2_CID_HUE,
188 .name = "Hue",
189 .minimum = 0,
190 .maximum = 0xff,
191 .step = 1,
192 .default_value = 0x7f,
193 .type = V4L2_CTRL_TYPE_INTEGER,
194 },
195 .off = 128,
196 .reg = CHROMA_CTRL,
197 .mask = 0xff0000,
198 .shift = 16,
199 }, {
200 /* strictly, this only describes only U saturation.
201 * V saturation is handled specially through code.
202 */
203 .v = {
204 .id = V4L2_CID_SATURATION,
205 .name = "Saturation",
206 .minimum = 0,
207 .maximum = 0xff,
208 .step = 1,
209 .default_value = 0x7f,
210 .type = V4L2_CTRL_TYPE_INTEGER,
211 },
212 .off = 0,
213 .reg = CHROMA_CTRL,
214 .mask = 0x00ff,
215 .shift = 0,
216 }, {
217 /* --- audio --- */
218 .v = {
219 .id = V4L2_CID_AUDIO_MUTE,
220 .name = "Mute",
221 .minimum = 0,
222 .maximum = 1,
223 .default_value = 1,
224 .type = V4L2_CTRL_TYPE_BOOLEAN,
225 },
226 .reg = PATH1_CTL1,
227 .mask = (0x1f << 24),
228 .shift = 24,
229 }, {
230 .v = {
231 .id = V4L2_CID_AUDIO_VOLUME,
232 .name = "Volume",
233 .minimum = 0,
234 .maximum = 0x3f,
235 .step = 1,
236 .default_value = 0x3f,
237 .type = V4L2_CTRL_TYPE_INTEGER,
238 },
239 .reg = PATH1_VOL_CTL,
240 .mask = 0xff,
241 .shift = 0,
242 }
243};
244static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls);
245
246const u32 cx23885_user_ctrls[] = {
247 V4L2_CID_USER_CLASS,
248 V4L2_CID_BRIGHTNESS,
249 V4L2_CID_CONTRAST,
250 V4L2_CID_SATURATION,
251 V4L2_CID_HUE,
252 V4L2_CID_AUDIO_VOLUME,
253 V4L2_CID_AUDIO_MUTE,
254 0
255};
256EXPORT_SYMBOL(cx23885_user_ctrls);
257
258static const u32 *ctrl_classes[] = {
259 cx23885_user_ctrls,
260 NULL
261};
262
263void cx23885_video_wakeup(struct cx23885_dev *dev,
264 struct cx23885_dmaqueue *q, u32 count)
265{
266 struct cx23885_buffer *buf;
267 int bc;
268
269 for (bc = 0;; bc++) {
270 if (list_empty(&q->active))
271 break;
272 buf = list_entry(q->active.next,
273 struct cx23885_buffer, vb.queue);
274
275 /* count comes from the hw and is is 16bit wide --
276 * this trick handles wrap-arounds correctly for
277 * up to 32767 buffers in flight... */
278 if ((s16) (count - buf->count) < 0)
279 break;
280
281 do_gettimeofday(&buf->vb.ts);
282 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
283 count, buf->count);
284 buf->vb.state = VIDEOBUF_DONE;
285 list_del(&buf->vb.queue);
286 wake_up(&buf->vb.done);
287 }
288 if (list_empty(&q->active)) {
289 del_timer(&q->timeout);
290 } else {
291 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
292 }
293 if (bc != 1)
294 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n",
295 __FUNCTION__, bc);
296}
297
298int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
299{
300 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
301 __FUNCTION__,
302 (unsigned int)norm,
303 v4l2_norm_to_name(norm));
304
305 dev->tvnorm = norm;
306
307 /* Tell the analog tuner/demods */
308 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_S_STD, &norm);
309
310 /* Tell the internal A/V decoder */
311 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_STD, &norm);
312
313 return 0;
314}
315
316struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
317 struct pci_dev *pci,
318 struct video_device *template,
319 char *type)
320{
321 struct video_device *vfd;
322 dprintk(1, "%s()\n", __FUNCTION__);
323
324 vfd = video_device_alloc();
325 if (NULL == vfd)
326 return NULL;
327 *vfd = *template;
328 vfd->minor = -1;
329 vfd->dev = &pci->dev;
330 vfd->release = video_device_release;
331 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
332 dev->name, type, cx23885_boards[dev->board].name);
333 return vfd;
334}
335
336int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
337{
338 int i;
339
340 if (qctrl->id < V4L2_CID_BASE ||
341 qctrl->id >= V4L2_CID_LASTP1)
342 return -EINVAL;
343 for (i = 0; i < CX23885_CTLS; i++)
344 if (cx23885_ctls[i].v.id == qctrl->id)
345 break;
346 if (i == CX23885_CTLS) {
347 *qctrl = no_ctl;
348 return 0;
349 }
350 *qctrl = cx23885_ctls[i].v;
351 return 0;
352}
353EXPORT_SYMBOL(cx23885_ctrl_query);
354
355/* ------------------------------------------------------------------- */
356/* resource management */
357
358static int res_get(struct cx23885_dev *dev, struct cx23885_fh *fh,
359 unsigned int bit)
360{
361 dprintk(1, "%s()\n", __FUNCTION__);
362 if (fh->resources & bit)
363 /* have it already allocated */
364 return 1;
365
366 /* is it free? */
367 mutex_lock(&dev->lock);
368 if (dev->resources & bit) {
369 /* no, someone else uses it */
370 mutex_unlock(&dev->lock);
371 return 0;
372 }
373 /* it's free, grab it */
374 fh->resources |= bit;
375 dev->resources |= bit;
376 dprintk(1, "res: get %d\n", bit);
377 mutex_unlock(&dev->lock);
378 return 1;
379}
380
381static int res_check(struct cx23885_fh *fh, unsigned int bit)
382{
383 return (fh->resources & bit);
384}
385
386static int res_locked(struct cx23885_dev *dev, unsigned int bit)
387{
388 return (dev->resources & bit);
389}
390
391static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
392 unsigned int bits)
393{
394 BUG_ON((fh->resources & bits) != bits);
395 dprintk(1, "%s()\n", __FUNCTION__);
396
397 mutex_lock(&dev->lock);
398 fh->resources &= ~bits;
399 dev->resources &= ~bits;
400 dprintk(1, "res: put %d\n", bits);
401 mutex_unlock(&dev->lock);
402}
403
404int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
405{
406 struct v4l2_routing route;
407 memset(&route, 0, sizeof(route));
408
409 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
410 __FUNCTION__,
411 input, INPUT(input)->vmux,
412 INPUT(input)->gpio0, INPUT(input)->gpio1,
413 INPUT(input)->gpio2, INPUT(input)->gpio3);
414 dev->input = input;
415
416 route.input = INPUT(input)->vmux;
417
418 /* Tell the internal A/V decoder */
419 cx23885_call_i2c_clients(&dev->i2c_bus[2],
420 VIDIOC_INT_S_VIDEO_ROUTING, &route);
421
422 return 0;
423}
424EXPORT_SYMBOL(cx23885_video_mux);
425
426/* ------------------------------------------------------------------ */
427int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width,
428 unsigned int height, enum v4l2_field field)
429{
430 dprintk(1, "%s()\n", __FUNCTION__);
431 return 0;
432}
433
434static int cx23885_start_video_dma(struct cx23885_dev *dev,
435 struct cx23885_dmaqueue *q,
436 struct cx23885_buffer *buf)
437{
438 dprintk(1, "%s()\n", __FUNCTION__);
439
440 /* setup fifo + format */
441 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01],
442 buf->bpl, buf->risc.dma);
443 cx23885_set_scale(dev, buf->vb.width, buf->vb.height, buf->vb.field);
444
445 /* reset counter */
446 cx_write(VID_A_GPCNT_CTL, 3);
447 q->count = 1;
448
449 /* enable irq */
450 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | 0x01);
451 cx_set(VID_A_INT_MSK, 0x000011);
452
453 /* start dma */
454 cx_set(DEV_CNTRL2, (1<<5));
455 cx_set(VID_A_DMA_CTL, 0x11); /* FIFO and RISC enable */
456
457 return 0;
458}
459
460
461static int cx23885_restart_video_queue(struct cx23885_dev *dev,
462 struct cx23885_dmaqueue *q)
463{
464 struct cx23885_buffer *buf, *prev;
465 struct list_head *item;
466 dprintk(1, "%s()\n", __FUNCTION__);
467
468 if (!list_empty(&q->active)) {
469 buf = list_entry(q->active.next, struct cx23885_buffer,
470 vb.queue);
471 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
472 buf, buf->vb.i);
473 cx23885_start_video_dma(dev, q, buf);
474 list_for_each(item, &q->active) {
475 buf = list_entry(item, struct cx23885_buffer,
476 vb.queue);
477 buf->count = q->count++;
478 }
479 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
480 return 0;
481 }
482
483 prev = NULL;
484 for (;;) {
485 if (list_empty(&q->queued))
486 return 0;
487 buf = list_entry(q->queued.next, struct cx23885_buffer,
488 vb.queue);
489 if (NULL == prev) {
490 list_move_tail(&buf->vb.queue, &q->active);
491 cx23885_start_video_dma(dev, q, buf);
492 buf->vb.state = VIDEOBUF_ACTIVE;
493 buf->count = q->count++;
494 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
495 dprintk(2, "[%p/%d] restart_queue - first active\n",
496 buf, buf->vb.i);
497
498 } else if (prev->vb.width == buf->vb.width &&
499 prev->vb.height == buf->vb.height &&
500 prev->fmt == buf->fmt) {
501 list_move_tail(&buf->vb.queue, &q->active);
502 buf->vb.state = VIDEOBUF_ACTIVE;
503 buf->count = q->count++;
504 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
505 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */
506 dprintk(2, "[%p/%d] restart_queue - move to active\n",
507 buf, buf->vb.i);
508 } else {
509 return 0;
510 }
511 prev = buf;
512 }
513}
514
515static int buffer_setup(struct videobuf_queue *q, unsigned int *count,
516 unsigned int *size)
517{
518 struct cx23885_fh *fh = q->priv_data;
519
520 *size = fh->fmt->depth*fh->width*fh->height >> 3;
521 if (0 == *count)
522 *count = 32;
523 while (*size * *count > vid_limit * 1024 * 1024)
524 (*count)--;
525 return 0;
526}
527
528static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
529 enum v4l2_field field)
530{
531 struct cx23885_fh *fh = q->priv_data;
532 struct cx23885_dev *dev = fh->dev;
533 struct cx23885_buffer *buf =
534 container_of(vb, struct cx23885_buffer, vb);
535 int rc, init_buffer = 0;
536 u32 line0_offset, line1_offset;
537 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
538
539 BUG_ON(NULL == fh->fmt);
540 if (fh->width < 48 || fh->width > norm_maxw(dev->tvnorm) ||
541 fh->height < 32 || fh->height > norm_maxh(dev->tvnorm))
542 return -EINVAL;
543 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
544 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
545 return -EINVAL;
546
547 if (buf->fmt != fh->fmt ||
548 buf->vb.width != fh->width ||
549 buf->vb.height != fh->height ||
550 buf->vb.field != field) {
551 buf->fmt = fh->fmt;
552 buf->vb.width = fh->width;
553 buf->vb.height = fh->height;
554 buf->vb.field = field;
555 init_buffer = 1;
556 }
557
558 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
559 init_buffer = 1;
560 rc = videobuf_iolock(q, &buf->vb, NULL);
561 if (0 != rc)
562 goto fail;
563 }
564
565 if (init_buffer) {
566 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
567 switch (buf->vb.field) {
568 case V4L2_FIELD_TOP:
569 cx23885_risc_buffer(dev->pci, &buf->risc,
570 dma->sglist, 0, UNSET,
571 buf->bpl, 0, buf->vb.height);
572 break;
573 case V4L2_FIELD_BOTTOM:
574 cx23885_risc_buffer(dev->pci, &buf->risc,
575 dma->sglist, UNSET, 0,
576 buf->bpl, 0, buf->vb.height);
577 break;
578 case V4L2_FIELD_INTERLACED:
579 if (dev->tvnorm & V4L2_STD_NTSC) {
580 /* cx25840 transmits NTSC bottom field first */
581 dprintk(1, "%s() Creating NTSC risc\n",
582 __FUNCTION__);
583 line0_offset = buf->bpl;
584 line1_offset = 0;
585 } else {
586 /* All other formats are top field first */
587 dprintk(1, "%s() Creating PAL/SECAM risc\n",
588 __FUNCTION__);
589 line0_offset = 0;
590 line1_offset = buf->bpl;
591 }
592 cx23885_risc_buffer(dev->pci, &buf->risc,
593 dma->sglist, line0_offset,
594 line1_offset,
595 buf->bpl, buf->bpl,
596 buf->vb.height >> 1);
597 break;
598 case V4L2_FIELD_SEQ_TB:
599 cx23885_risc_buffer(dev->pci, &buf->risc,
600 dma->sglist,
601 0, buf->bpl * (buf->vb.height >> 1),
602 buf->bpl, 0,
603 buf->vb.height >> 1);
604 break;
605 case V4L2_FIELD_SEQ_BT:
606 cx23885_risc_buffer(dev->pci, &buf->risc,
607 dma->sglist,
608 buf->bpl * (buf->vb.height >> 1), 0,
609 buf->bpl, 0,
610 buf->vb.height >> 1);
611 break;
612 default:
613 BUG();
614 }
615 }
616 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
617 buf, buf->vb.i,
618 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
619 (unsigned long)buf->risc.dma);
620
621 buf->vb.state = VIDEOBUF_PREPARED;
622 return 0;
623
624 fail:
625 cx23885_free_buffer(q, buf);
626 return rc;
627}
628
629static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
630{
631 struct cx23885_buffer *buf = container_of(vb,
632 struct cx23885_buffer, vb);
633 struct cx23885_buffer *prev;
634 struct cx23885_fh *fh = vq->priv_data;
635 struct cx23885_dev *dev = fh->dev;
636 struct cx23885_dmaqueue *q = &dev->vidq;
637
638 /* add jump to stopper */
639 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
640 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
641 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
642
643 if (!list_empty(&q->queued)) {
644 list_add_tail(&buf->vb.queue, &q->queued);
645 buf->vb.state = VIDEOBUF_QUEUED;
646 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
647 buf, buf->vb.i);
648
649 } else if (list_empty(&q->active)) {
650 list_add_tail(&buf->vb.queue, &q->active);
651 cx23885_start_video_dma(dev, q, buf);
652 buf->vb.state = VIDEOBUF_ACTIVE;
653 buf->count = q->count++;
654 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
655 dprintk(2, "[%p/%d] buffer_queue - first active\n",
656 buf, buf->vb.i);
657
658 } else {
659 prev = list_entry(q->active.prev, struct cx23885_buffer,
660 vb.queue);
661 if (prev->vb.width == buf->vb.width &&
662 prev->vb.height == buf->vb.height &&
663 prev->fmt == buf->fmt) {
664 list_add_tail(&buf->vb.queue, &q->active);
665 buf->vb.state = VIDEOBUF_ACTIVE;
666 buf->count = q->count++;
667 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
668 /* 64 bit bits 63-32 */
669 prev->risc.jmp[2] = cpu_to_le32(0);
670 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
671 buf, buf->vb.i);
672
673 } else {
674 list_add_tail(&buf->vb.queue, &q->queued);
675 buf->vb.state = VIDEOBUF_QUEUED;
676 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
677 buf, buf->vb.i);
678 }
679 }
680}
681
682static void buffer_release(struct videobuf_queue *q,
683 struct videobuf_buffer *vb)
684{
685 struct cx23885_buffer *buf = container_of(vb,
686 struct cx23885_buffer, vb);
687
688 cx23885_free_buffer(q, buf);
689}
690
691static struct videobuf_queue_ops cx23885_video_qops = {
692 .buf_setup = buffer_setup,
693 .buf_prepare = buffer_prepare,
694 .buf_queue = buffer_queue,
695 .buf_release = buffer_release,
696};
697
698static struct videobuf_queue *get_queue(struct cx23885_fh *fh)
699{
700 switch (fh->type) {
701 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
702 return &fh->vidq;
703 case V4L2_BUF_TYPE_VBI_CAPTURE:
704 return &fh->vbiq;
705 default:
706 BUG();
707 return NULL;
708 }
709}
710
711static int get_resource(struct cx23885_fh *fh)
712{
713 switch (fh->type) {
714 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
715 return RESOURCE_VIDEO;
716 case V4L2_BUF_TYPE_VBI_CAPTURE:
717 return RESOURCE_VBI;
718 default:
719 BUG();
720 return 0;
721 }
722}
723
724static int video_open(struct inode *inode, struct file *file)
725{
726 int minor = iminor(inode);
727 struct cx23885_dev *h, *dev = NULL;
728 struct cx23885_fh *fh;
729 struct list_head *list;
730 enum v4l2_buf_type type = 0;
731 int radio = 0;
732
733 list_for_each(list, &cx23885_devlist) {
734 h = list_entry(list, struct cx23885_dev, devlist);
735 if (h->video_dev->minor == minor) {
736 dev = h;
737 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
738 }
739 if (h->vbi_dev &&
740 h->vbi_dev->minor == minor) {
741 dev = h;
742 type = V4L2_BUF_TYPE_VBI_CAPTURE;
743 }
744 if (h->radio_dev &&
745 h->radio_dev->minor == minor) {
746 radio = 1;
747 dev = h;
748 }
749 }
750 if (NULL == dev)
751 return -ENODEV;
752
753 dprintk(1, "open minor=%d radio=%d type=%s\n",
754 minor, radio, v4l2_type_names[type]);
755
756 /* allocate + initialize per filehandle data */
757 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
758 if (NULL == fh)
759 return -ENOMEM;
760 file->private_data = fh;
761 fh->dev = dev;
762 fh->radio = radio;
763 fh->type = type;
764 fh->width = 320;
765 fh->height = 240;
766 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
767
768 videobuf_queue_pci_init(&fh->vidq, &cx23885_video_qops,
769 dev->pci, &dev->slock,
770 V4L2_BUF_TYPE_VIDEO_CAPTURE,
771 V4L2_FIELD_INTERLACED,
772 sizeof(struct cx23885_buffer),
773 fh);
774
775 dprintk(1, "post videobuf_queue_init()\n");
776
777
778 return 0;
779}
780
781static ssize_t video_read(struct file *file, char __user *data,
782 size_t count, loff_t *ppos)
783{
784 struct cx23885_fh *fh = file->private_data;
785
786 switch (fh->type) {
787 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
788 if (res_locked(fh->dev, RESOURCE_VIDEO))
789 return -EBUSY;
790 return videobuf_read_one(&fh->vidq, data, count, ppos,
791 file->f_flags & O_NONBLOCK);
792 case V4L2_BUF_TYPE_VBI_CAPTURE:
793 if (!res_get(fh->dev, fh, RESOURCE_VBI))
794 return -EBUSY;
795 return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
796 file->f_flags & O_NONBLOCK);
797 default:
798 BUG();
799 return 0;
800 }
801}
802
803static unsigned int video_poll(struct file *file,
804 struct poll_table_struct *wait)
805{
806 struct cx23885_fh *fh = file->private_data;
807 struct cx23885_buffer *buf;
808
809 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
810 if (!res_get(fh->dev, fh, RESOURCE_VBI))
811 return POLLERR;
812 return videobuf_poll_stream(file, &fh->vbiq, wait);
813 }
814
815 if (res_check(fh, RESOURCE_VIDEO)) {
816 /* streaming capture */
817 if (list_empty(&fh->vidq.stream))
818 return POLLERR;
819 buf = list_entry(fh->vidq.stream.next,
820 struct cx23885_buffer, vb.stream);
821 } else {
822 /* read() capture */
823 buf = (struct cx23885_buffer *)fh->vidq.read_buf;
824 if (NULL == buf)
825 return POLLERR;
826 }
827 poll_wait(file, &buf->vb.done, wait);
828 if (buf->vb.state == VIDEOBUF_DONE ||
829 buf->vb.state == VIDEOBUF_ERROR)
830 return POLLIN|POLLRDNORM;
831 return 0;
832}
833
834static int video_release(struct inode *inode, struct file *file)
835{
836 struct cx23885_fh *fh = file->private_data;
837 struct cx23885_dev *dev = fh->dev;
838
839 /* turn off overlay */
840 if (res_check(fh, RESOURCE_OVERLAY)) {
841 /* FIXME */
842 res_free(dev, fh, RESOURCE_OVERLAY);
843 }
844
845 /* stop video capture */
846 if (res_check(fh, RESOURCE_VIDEO)) {
847 videobuf_queue_cancel(&fh->vidq);
848 res_free(dev, fh, RESOURCE_VIDEO);
849 }
850 if (fh->vidq.read_buf) {
851 buffer_release(&fh->vidq, fh->vidq.read_buf);
852 kfree(fh->vidq.read_buf);
853 }
854
855 /* stop vbi capture */
856 if (res_check(fh, RESOURCE_VBI)) {
857 if (fh->vbiq.streaming)
858 videobuf_streamoff(&fh->vbiq);
859 if (fh->vbiq.reading)
860 videobuf_read_stop(&fh->vbiq);
861 res_free(dev, fh, RESOURCE_VBI);
862 }
863
864 videobuf_mmap_free(&fh->vidq);
865 file->private_data = NULL;
866 kfree(fh);
867
868 /* We are not putting the tuner to sleep here on exit, because
869 * we want to use the mpeg encoder in another session to capture
870 * tuner video. Closing this will result in no video to the encoder.
871 */
872
873 return 0;
874}
875
876static int video_mmap(struct file *file, struct vm_area_struct *vma)
877{
878 struct cx23885_fh *fh = file->private_data;
879
880 return videobuf_mmap_mapper(get_queue(fh), vma);
881}
882
883/* ------------------------------------------------------------------ */
884/* VIDEO CTRL IOCTLS */
885
886int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
887{
888 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __FUNCTION__);
889 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_CTRL, ctl);
890 return 0;
891}
892EXPORT_SYMBOL(cx23885_get_control);
893
894int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
895{
896 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
897 " (disabled - no action)\n", __FUNCTION__);
898 return 0;
899}
900EXPORT_SYMBOL(cx23885_set_control);
901
902static void init_controls(struct cx23885_dev *dev)
903{
904 struct v4l2_control ctrl;
905 int i;
906
907 for (i = 0; i < CX23885_CTLS; i++) {
908 ctrl.id = cx23885_ctls[i].v.id;
909 ctrl.value = cx23885_ctls[i].v.default_value;
910
911 cx23885_set_control(dev, &ctrl);
912 }
913}
914
915/* ------------------------------------------------------------------ */
916/* VIDEO IOCTLS */
917
918static int vidioc_g_fmt_cap(struct file *file, void *priv,
919 struct v4l2_format *f)
920{
921 struct cx23885_fh *fh = priv;
922
923 f->fmt.pix.width = fh->width;
924 f->fmt.pix.height = fh->height;
925 f->fmt.pix.field = fh->vidq.field;
926 f->fmt.pix.pixelformat = fh->fmt->fourcc;
927 f->fmt.pix.bytesperline =
928 (f->fmt.pix.width * fh->fmt->depth) >> 3;
929 f->fmt.pix.sizeimage =
930 f->fmt.pix.height * f->fmt.pix.bytesperline;
931
932 return 0;
933}
934
935static int vidioc_try_fmt_cap(struct file *file, void *priv,
936 struct v4l2_format *f)
937{
938 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
939 struct cx23885_fmt *fmt;
940 enum v4l2_field field;
941 unsigned int maxw, maxh;
942
943 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
944 if (NULL == fmt)
945 return -EINVAL;
946
947 field = f->fmt.pix.field;
948 maxw = norm_maxw(dev->tvnorm);
949 maxh = norm_maxh(dev->tvnorm);
950
951 if (V4L2_FIELD_ANY == field) {
952 field = (f->fmt.pix.height > maxh/2)
953 ? V4L2_FIELD_INTERLACED
954 : V4L2_FIELD_BOTTOM;
955 }
956
957 switch (field) {
958 case V4L2_FIELD_TOP:
959 case V4L2_FIELD_BOTTOM:
960 maxh = maxh / 2;
961 break;
962 case V4L2_FIELD_INTERLACED:
963 break;
964 default:
965 return -EINVAL;
966 }
967
968 f->fmt.pix.field = field;
969 if (f->fmt.pix.height < 32)
970 f->fmt.pix.height = 32;
971 if (f->fmt.pix.height > maxh)
972 f->fmt.pix.height = maxh;
973 if (f->fmt.pix.width < 48)
974 f->fmt.pix.width = 48;
975 if (f->fmt.pix.width > maxw)
976 f->fmt.pix.width = maxw;
977 f->fmt.pix.width &= ~0x03;
978 f->fmt.pix.bytesperline =
979 (f->fmt.pix.width * fmt->depth) >> 3;
980 f->fmt.pix.sizeimage =
981 f->fmt.pix.height * f->fmt.pix.bytesperline;
982
983 return 0;
984}
985
986static int vidioc_s_fmt_cap(struct file *file, void *priv,
987 struct v4l2_format *f)
988{
989 struct cx23885_fh *fh = priv;
990 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
991 int err;
992
993 dprintk(2, "%s()\n", __FUNCTION__);
994 err = vidioc_try_fmt_cap(file, priv, f);
995
996 if (0 != err)
997 return err;
998 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
999 fh->width = f->fmt.pix.width;
1000 fh->height = f->fmt.pix.height;
1001 fh->vidq.field = f->fmt.pix.field;
1002 dprintk(2, "%s() width=%d height=%d field=%d\n", __FUNCTION__,
1003 fh->width, fh->height, fh->vidq.field);
1004 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_FMT, f);
1005 return 0;
1006}
1007
1008static int vidioc_querycap(struct file *file, void *priv,
1009 struct v4l2_capability *cap)
1010{
1011 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1012
1013 strcpy(cap->driver, "cx23885");
1014 strlcpy(cap->card, cx23885_boards[dev->board].name,
1015 sizeof(cap->card));
1016 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
1017 cap->version = CX23885_VERSION_CODE;
1018 cap->capabilities =
1019 V4L2_CAP_VIDEO_CAPTURE |
1020 V4L2_CAP_READWRITE |
1021 V4L2_CAP_STREAMING |
1022 V4L2_CAP_VBI_CAPTURE;
1023 if (UNSET != dev->tuner_type)
1024 cap->capabilities |= V4L2_CAP_TUNER;
1025 return 0;
1026}
1027
1028static int vidioc_enum_fmt_cap(struct file *file, void *priv,
1029 struct v4l2_fmtdesc *f)
1030{
1031 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1032 return -EINVAL;
1033
1034 strlcpy(f->description, formats[f->index].name,
1035 sizeof(f->description));
1036 f->pixelformat = formats[f->index].fourcc;
1037
1038 return 0;
1039}
1040
1041#ifdef CONFIG_VIDEO_V4L1_COMPAT
1042static int vidiocgmbuf(struct file *file, void *priv,
1043 struct video_mbuf *mbuf)
1044{
1045 struct cx23885_fh *fh = priv;
1046 struct videobuf_queue *q;
1047 struct v4l2_requestbuffers req;
1048 unsigned int i;
1049 int err;
1050
1051 q = get_queue(fh);
1052 memset(&req, 0, sizeof(req));
1053 req.type = q->type;
1054 req.count = 8;
1055 req.memory = V4L2_MEMORY_MMAP;
1056 err = videobuf_reqbufs(q, &req);
1057 if (err < 0)
1058 return err;
1059
1060 mbuf->frames = req.count;
1061 mbuf->size = 0;
1062 for (i = 0; i < mbuf->frames; i++) {
1063 mbuf->offsets[i] = q->bufs[i]->boff;
1064 mbuf->size += q->bufs[i]->bsize;
1065 }
1066 return 0;
1067}
1068#endif
1069
1070static int vidioc_reqbufs(struct file *file, void *priv,
1071 struct v4l2_requestbuffers *p)
1072{
1073 struct cx23885_fh *fh = priv;
1074 return (videobuf_reqbufs(get_queue(fh), p));
1075}
1076
1077static int vidioc_querybuf(struct file *file, void *priv,
1078 struct v4l2_buffer *p)
1079{
1080 struct cx23885_fh *fh = priv;
1081 return (videobuf_querybuf(get_queue(fh), p));
1082}
1083
1084static int vidioc_qbuf(struct file *file, void *priv,
1085 struct v4l2_buffer *p)
1086{
1087 struct cx23885_fh *fh = priv;
1088 return (videobuf_qbuf(get_queue(fh), p));
1089}
1090
1091static int vidioc_dqbuf(struct file *file, void *priv,
1092 struct v4l2_buffer *p)
1093{
1094 struct cx23885_fh *fh = priv;
1095 return (videobuf_dqbuf(get_queue(fh), p,
1096 file->f_flags & O_NONBLOCK));
1097}
1098
1099static int vidioc_streamon(struct file *file, void *priv,
1100 enum v4l2_buf_type i)
1101{
1102 struct cx23885_fh *fh = priv;
1103 struct cx23885_dev *dev = fh->dev;
1104 dprintk(1, "%s()\n", __FUNCTION__);
1105
1106 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
1107 return -EINVAL;
1108 if (unlikely(i != fh->type))
1109 return -EINVAL;
1110
1111 if (unlikely(!res_get(dev, fh, get_resource(fh))))
1112 return -EBUSY;
1113 return videobuf_streamon(get_queue(fh));
1114}
1115
1116static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1117{
1118 struct cx23885_fh *fh = priv;
1119 struct cx23885_dev *dev = fh->dev;
1120 int err, res;
1121 dprintk(1, "%s()\n", __FUNCTION__);
1122
1123 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1124 return -EINVAL;
1125 if (i != fh->type)
1126 return -EINVAL;
1127
1128 res = get_resource(fh);
1129 err = videobuf_streamoff(get_queue(fh));
1130 if (err < 0)
1131 return err;
1132 res_free(dev, fh, res);
1133 return 0;
1134}
1135
1136static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
1137{
1138 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1139 dprintk(1, "%s()\n", __FUNCTION__);
1140
1141 mutex_lock(&dev->lock);
1142 cx23885_set_tvnorm(dev, *tvnorms);
1143 mutex_unlock(&dev->lock);
1144
1145 return 0;
1146}
1147
1148int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
1149{
1150 static const char *iname[] = {
1151 [CX23885_VMUX_COMPOSITE1] = "Composite1",
1152 [CX23885_VMUX_COMPOSITE2] = "Composite2",
1153 [CX23885_VMUX_COMPOSITE3] = "Composite3",
1154 [CX23885_VMUX_COMPOSITE4] = "Composite4",
1155 [CX23885_VMUX_SVIDEO] = "S-Video",
1156 [CX23885_VMUX_TELEVISION] = "Television",
1157 [CX23885_VMUX_CABLE] = "Cable TV",
1158 [CX23885_VMUX_DVB] = "DVB",
1159 [CX23885_VMUX_DEBUG] = "for debug only",
1160 };
1161 unsigned int n;
1162 dprintk(1, "%s()\n", __FUNCTION__);
1163
1164 n = i->index;
1165 if (n >= 4)
1166 return -EINVAL;
1167
1168 if (0 == INPUT(n)->type)
1169 return -EINVAL;
1170
1171 memset(i, 0, sizeof(*i));
1172 i->index = n;
1173 i->type = V4L2_INPUT_TYPE_CAMERA;
1174 strcpy(i->name, iname[INPUT(n)->type]);
1175 if ((CX23885_VMUX_TELEVISION == INPUT(n)->type) ||
1176 (CX23885_VMUX_CABLE == INPUT(n)->type))
1177 i->type = V4L2_INPUT_TYPE_TUNER;
1178 i->std = CX23885_NORMS;
1179 return 0;
1180}
1181EXPORT_SYMBOL(cx23885_enum_input);
1182
1183static int vidioc_enum_input(struct file *file, void *priv,
1184 struct v4l2_input *i)
1185{
1186 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1187 dprintk(1, "%s()\n", __FUNCTION__);
1188 return cx23885_enum_input(dev, i);
1189}
1190
1191static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1192{
1193 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1194
1195 *i = dev->input;
1196 dprintk(1, "%s() returns %d\n", __FUNCTION__, *i);
1197 return 0;
1198}
1199
1200static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1201{
1202 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1203
1204 dprintk(1, "%s(%d)\n", __FUNCTION__, i);
1205
1206 if (i >= 4) {
1207 dprintk(1, "%s() -EINVAL\n", __FUNCTION__);
1208 return -EINVAL;
1209 }
1210
1211 mutex_lock(&dev->lock);
1212 cx23885_video_mux(dev, i);
1213 mutex_unlock(&dev->lock);
1214 return 0;
1215}
1216
1217static int vidioc_queryctrl(struct file *file, void *priv,
1218 struct v4l2_queryctrl *qctrl)
1219{
1220 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1221 if (unlikely(qctrl->id == 0))
1222 return -EINVAL;
1223 return cx23885_ctrl_query(qctrl);
1224}
1225
1226static int vidioc_g_ctrl(struct file *file, void *priv,
1227 struct v4l2_control *ctl)
1228{
1229 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1230
1231 return cx23885_get_control(dev, ctl);
1232}
1233
1234static int vidioc_s_ctrl(struct file *file, void *priv,
1235 struct v4l2_control *ctl)
1236{
1237 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1238
1239 return cx23885_set_control(dev, ctl);
1240}
1241
1242static int vidioc_g_tuner(struct file *file, void *priv,
1243 struct v4l2_tuner *t)
1244{
1245 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1246
1247 if (unlikely(UNSET == dev->tuner_type))
1248 return -EINVAL;
1249 if (0 != t->index)
1250 return -EINVAL;
1251
1252 strcpy(t->name, "Television");
1253 t->type = V4L2_TUNER_ANALOG_TV;
1254 t->capability = V4L2_TUNER_CAP_NORM;
1255 t->rangehigh = 0xffffffffUL;
1256 t->signal = 0xffff ; /* LOCKED */
1257 return 0;
1258}
1259
1260static int vidioc_s_tuner(struct file *file, void *priv,
1261 struct v4l2_tuner *t)
1262{
1263 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1264
1265 if (UNSET == dev->tuner_type)
1266 return -EINVAL;
1267 if (0 != t->index)
1268 return -EINVAL;
1269 return 0;
1270}
1271
1272static int vidioc_g_frequency(struct file *file, void *priv,
1273 struct v4l2_frequency *f)
1274{
1275 struct cx23885_fh *fh = priv;
1276 struct cx23885_dev *dev = fh->dev;
1277
1278 if (unlikely(UNSET == dev->tuner_type))
1279 return -EINVAL;
1280
1281 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1282 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1283 f->frequency = dev->freq;
1284
1285 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_G_FREQUENCY, f);
1286
1287 return 0;
1288}
1289
1290int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
1291{
1292 if (unlikely(UNSET == dev->tuner_type))
1293 return -EINVAL;
1294 if (unlikely(f->tuner != 0))
1295 return -EINVAL;
1296
1297 mutex_lock(&dev->lock);
1298 dev->freq = f->frequency;
1299
1300 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, f);
1301
1302 /* When changing channels it is required to reset TVAUDIO */
1303 msleep(10);
1304
1305 mutex_unlock(&dev->lock);
1306
1307 return 0;
1308}
1309EXPORT_SYMBOL(cx23885_set_freq);
1310
1311static int vidioc_s_frequency(struct file *file, void *priv,
1312 struct v4l2_frequency *f)
1313{
1314 struct cx23885_fh *fh = priv;
1315 struct cx23885_dev *dev = fh->dev;
1316
1317 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1318 return -EINVAL;
1319 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1320 return -EINVAL;
1321
1322 return
1323 cx23885_set_freq(dev, f);
1324}
1325
1326#ifdef CONFIG_VIDEO_ADV_DEBUG
1327static int vidioc_g_register(struct file *file, void *fh,
1328 struct v4l2_register *reg)
1329{
1330 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
1331
1332 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
1333 return -EINVAL;
1334
1335 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_DBG_G_REGISTER, reg);
1336
1337 return 0;
1338}
1339
1340static int vidioc_s_register(struct file *file, void *fh,
1341 struct v4l2_register *reg)
1342{
1343 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
1344
1345 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
1346 return -EINVAL;
1347
1348 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_DBG_S_REGISTER, reg);
1349
1350 return 0;
1351}
1352#endif
1353
1354/* ----------------------------------------------------------- */
1355
1356static void cx23885_vid_timeout(unsigned long data)
1357{
1358 struct cx23885_dev *dev = (struct cx23885_dev *)data;
1359 struct cx23885_dmaqueue *q = &dev->vidq;
1360 struct cx23885_buffer *buf;
1361 unsigned long flags;
1362
1363 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
1364
1365 cx_clear(VID_A_DMA_CTL, 0x11);
1366
1367 spin_lock_irqsave(&dev->slock, flags);
1368 while (!list_empty(&q->active)) {
1369 buf = list_entry(q->active.next,
1370 struct cx23885_buffer, vb.queue);
1371 list_del(&buf->vb.queue);
1372 buf->vb.state = VIDEOBUF_ERROR;
1373 wake_up(&buf->vb.done);
1374 printk(KERN_ERR "%s/0: [%p/%d] timeout - dma=0x%08lx\n",
1375 dev->name, buf, buf->vb.i,
1376 (unsigned long)buf->risc.dma);
1377 }
1378 cx23885_restart_video_queue(dev, q);
1379 spin_unlock_irqrestore(&dev->slock, flags);
1380}
1381
1382int cx23885_video_irq(struct cx23885_dev *dev, u32 status)
1383{
1384 u32 mask, count;
1385 int handled = 0;
1386
1387 mask = cx_read(VID_A_INT_MSK);
1388 if (0 == (status & mask))
1389 return handled;
1390 cx_write(VID_A_INT_STAT, status);
1391
1392 dprintk(2, "%s() status = 0x%08x\n", __FUNCTION__, status);
1393 /* risc op code error */
1394 if (status & (1 << 16)) {
1395 printk(KERN_WARNING "%s/0: video risc op code error\n",
1396 dev->name);
1397 cx_clear(VID_A_DMA_CTL, 0x11);
1398 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
1399 }
1400
1401 /* risc1 y */
1402 if (status & 0x01) {
1403 spin_lock(&dev->slock);
1404 count = cx_read(VID_A_GPCNT);
1405 cx23885_video_wakeup(dev, &dev->vidq, count);
1406 spin_unlock(&dev->slock);
1407 handled++;
1408 }
1409 /* risc2 y */
1410 if (status & 0x10) {
1411 dprintk(2, "stopper video\n");
1412 spin_lock(&dev->slock);
1413 cx23885_restart_video_queue(dev, &dev->vidq);
1414 spin_unlock(&dev->slock);
1415 handled++;
1416 }
1417
1418 return handled;
1419}
1420
1421/* ----------------------------------------------------------- */
1422/* exported stuff */
1423
1424static const struct file_operations video_fops = {
1425 .owner = THIS_MODULE,
1426 .open = video_open,
1427 .release = video_release,
1428 .read = video_read,
1429 .poll = video_poll,
1430 .mmap = video_mmap,
1431 .ioctl = video_ioctl2,
1432 .compat_ioctl = v4l_compat_ioctl32,
1433 .llseek = no_llseek,
1434};
1435
1436static struct video_device cx23885_vbi_template;
1437static struct video_device cx23885_video_template = {
1438 .name = "cx23885-video",
1439 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,
1440 .fops = &video_fops,
1441 .minor = -1,
1442 .vidioc_querycap = vidioc_querycap,
1443 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
1444 .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
1445 .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
1446 .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
1447 .vidioc_g_fmt_vbi = cx23885_vbi_fmt,
1448 .vidioc_try_fmt_vbi = cx23885_vbi_fmt,
1449 .vidioc_s_fmt_vbi = cx23885_vbi_fmt,
1450 .vidioc_reqbufs = vidioc_reqbufs,
1451 .vidioc_querybuf = vidioc_querybuf,
1452 .vidioc_qbuf = vidioc_qbuf,
1453 .vidioc_dqbuf = vidioc_dqbuf,
1454 .vidioc_s_std = vidioc_s_std,
1455 .vidioc_enum_input = vidioc_enum_input,
1456 .vidioc_g_input = vidioc_g_input,
1457 .vidioc_s_input = vidioc_s_input,
1458 .vidioc_queryctrl = vidioc_queryctrl,
1459 .vidioc_g_ctrl = vidioc_g_ctrl,
1460 .vidioc_s_ctrl = vidioc_s_ctrl,
1461 .vidioc_streamon = vidioc_streamon,
1462 .vidioc_streamoff = vidioc_streamoff,
1463#ifdef CONFIG_VIDEO_V4L1_COMPAT
1464 .vidiocgmbuf = vidiocgmbuf,
1465#endif
1466 .vidioc_g_tuner = vidioc_g_tuner,
1467 .vidioc_s_tuner = vidioc_s_tuner,
1468 .vidioc_g_frequency = vidioc_g_frequency,
1469 .vidioc_s_frequency = vidioc_s_frequency,
1470#ifdef CONFIG_VIDEO_ADV_DEBUG
1471 .vidioc_g_register = vidioc_g_register,
1472 .vidioc_s_register = vidioc_s_register,
1473#endif
1474 .tvnorms = CX23885_NORMS,
1475 .current_norm = V4L2_STD_NTSC_M,
1476};
1477
1478static const struct file_operations radio_fops = {
1479 .owner = THIS_MODULE,
1480 .open = video_open,
1481 .release = video_release,
1482 .ioctl = video_ioctl2,
1483 .compat_ioctl = v4l_compat_ioctl32,
1484 .llseek = no_llseek,
1485};
1486
1487
1488void cx23885_video_unregister(struct cx23885_dev *dev)
1489{
1490 dprintk(1, "%s()\n", __FUNCTION__);
1491 cx_clear(PCI_INT_MSK, 1);
1492
1493 if (dev->video_dev) {
1494 if (-1 != dev->video_dev->minor)
1495 video_unregister_device(dev->video_dev);
1496 else
1497 video_device_release(dev->video_dev);
1498 dev->video_dev = NULL;
1499
1500 btcx_riscmem_free(dev->pci, &dev->vidq.stopper);
1501 }
1502}
1503
1504int cx23885_video_register(struct cx23885_dev *dev)
1505{
1506 int err;
1507
1508 dprintk(1, "%s()\n", __FUNCTION__);
1509 spin_lock_init(&dev->slock);
1510
1511 /* Initialize VBI template */
1512 memcpy(&cx23885_vbi_template, &cx23885_video_template,
1513 sizeof(cx23885_vbi_template));
1514 strcpy(cx23885_vbi_template.name, "cx23885-vbi");
1515 cx23885_vbi_template.type = VID_TYPE_TELETEXT|VID_TYPE_TUNER;
1516
1517 dev->tvnorm = cx23885_video_template.current_norm;
1518
1519 /* init video dma queues */
1520 INIT_LIST_HEAD(&dev->vidq.active);
1521 INIT_LIST_HEAD(&dev->vidq.queued);
1522 dev->vidq.timeout.function = cx23885_vid_timeout;
1523 dev->vidq.timeout.data = (unsigned long)dev;
1524 init_timer(&dev->vidq.timeout);
1525 cx23885_risc_stopper(dev->pci, &dev->vidq.stopper,
1526 VID_A_DMA_CTL, 0x11, 0x00);
1527
1528 /* Don't enable VBI yet */
1529 cx_set(PCI_INT_MSK, 1);
1530
1531
1532 /* register v4l devices */
1533 dev->video_dev = cx23885_vdev_init(dev, dev->pci,
1534 &cx23885_video_template, "video");
1535 err = video_register_device(dev->video_dev, VFL_TYPE_GRABBER,
1536 video_nr[dev->nr]);
1537 if (err < 0) {
1538 printk(KERN_INFO "%s: can't register video device\n",
1539 dev->name);
1540 goto fail_unreg;
1541 }
1542 printk(KERN_INFO "%s/0: registered device video%d [v4l2]\n",
1543 dev->name, dev->video_dev->minor & 0x1f);
1544 /* initial device configuration */
1545 mutex_lock(&dev->lock);
1546 cx23885_set_tvnorm(dev, dev->tvnorm);
1547 init_controls(dev);
1548 cx23885_video_mux(dev, 0);
1549 mutex_unlock(&dev->lock);
1550
1551 return 0;
1552
1553fail_unreg:
1554 cx23885_video_unregister(dev);
1555 return err;
1556}
1557
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index dec4dc2fcbb4..7cb2179f2622 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -44,6 +44,10 @@
44 44
45/* Max number of inputs by card */ 45/* Max number of inputs by card */
46#define MAX_CX23885_INPUT 8 46#define MAX_CX23885_INPUT 8
47#define INPUT(nr) (&cx23885_boards[dev->board].input[nr])
48#define RESOURCE_OVERLAY 1
49#define RESOURCE_VIDEO 2
50#define RESOURCE_VBI 4
47 51
48#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */ 52#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
49 53
@@ -53,6 +57,62 @@
53#define CX23885_BOARD_HAUPPAUGE_HVR1800 2 57#define CX23885_BOARD_HAUPPAUGE_HVR1800 2
54#define CX23885_BOARD_HAUPPAUGE_HVR1250 3 58#define CX23885_BOARD_HAUPPAUGE_HVR1250 3
55#define CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP 4 59#define CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP 4
60#define CX23885_BOARD_HAUPPAUGE_HVR1500Q 5
61#define CX23885_BOARD_HAUPPAUGE_HVR1500 6
62
63/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */
64#define CX23885_NORMS (\
65 V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 | \
66 V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \
67 V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc | \
68 V4L2_STD_PAL_60 | V4L2_STD_SECAM_L | V4L2_STD_SECAM_DK)
69
70struct cx23885_fmt {
71 char *name;
72 u32 fourcc; /* v4l2 format id */
73 int depth;
74 int flags;
75 u32 cxformat;
76};
77
78struct cx23885_ctrl {
79 struct v4l2_queryctrl v;
80 u32 off;
81 u32 reg;
82 u32 mask;
83 u32 shift;
84};
85
86struct cx23885_tvnorm {
87 char *name;
88 v4l2_std_id id;
89 u32 cxiformat;
90 u32 cxoformat;
91};
92
93struct cx23885_fh {
94 struct cx23885_dev *dev;
95 enum v4l2_buf_type type;
96 int radio;
97 u32 resources;
98
99 /* video overlay */
100 struct v4l2_window win;
101 struct v4l2_clip *clips;
102 unsigned int nclips;
103
104 /* video capture */
105 struct cx23885_fmt *fmt;
106 unsigned int width, height;
107
108 /* vbi capture */
109 struct videobuf_queue vidq;
110 struct videobuf_queue vbiq;
111
112 /* MPEG Encoder specifics ONLY */
113 struct videobuf_queue mpegq;
114 atomic_t v4l_reading;
115};
56 116
57enum cx23885_itype { 117enum cx23885_itype {
58 CX23885_VMUX_COMPOSITE1 = 1, 118 CX23885_VMUX_COMPOSITE1 = 1,
@@ -92,12 +152,28 @@ struct cx23885_input {
92 152
93typedef enum { 153typedef enum {
94 CX23885_MPEG_UNDEFINED = 0, 154 CX23885_MPEG_UNDEFINED = 0,
95 CX23885_MPEG_DVB 155 CX23885_MPEG_DVB,
156 CX23885_ANALOG_VIDEO,
96} port_t; 157} port_t;
97 158
98struct cx23885_board { 159struct cx23885_board {
99 char *name; 160 char *name;
100 port_t portb, portc; 161 port_t porta, portb, portc;
162 unsigned int tuner_type;
163 unsigned int radio_type;
164 unsigned char tuner_addr;
165 unsigned char radio_addr;
166
167 /* Vendors can and do run the PCIe bridge at different
168 * clock rates, driven physically by crystals on the PCBs.
169 * The core has to accomodate this. This allows the user
170 * to add new boards with new frequencys. The value is
171 * expressed in Hz.
172 *
173 * The core framework will default this value based on
174 * current designs, but it can vary.
175 */
176 u32 clk_freq;
101 struct cx23885_input input[MAX_CX23885_INPUT]; 177 struct cx23885_input input[MAX_CX23885_INPUT];
102}; 178};
103 179
@@ -189,6 +265,11 @@ struct cx23885_dev {
189 u32 __iomem *lmmio; 265 u32 __iomem *lmmio;
190 u8 __iomem *bmmio; 266 u8 __iomem *bmmio;
191 int pci_irqmask; 267 int pci_irqmask;
268 int hwrevision;
269
270 /* This valud is board specific and is used to configure the
271 * AV core so we see nice clean and stable video and audio. */
272 u32 clk_freq;
192 273
193 /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */ 274 /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
194 struct cx23885_i2c i2c_bus[3]; 275 struct cx23885_i2c i2c_bus[3];
@@ -210,8 +291,31 @@ struct cx23885_dev {
210 CX23885_BRIDGE_885 = 885, 291 CX23885_BRIDGE_885 = 885,
211 CX23885_BRIDGE_887 = 887, 292 CX23885_BRIDGE_887 = 887,
212 } bridge; 293 } bridge;
294
295 /* Analog video */
296 u32 resources;
297 unsigned int input;
298 u32 tvaudio;
299 v4l2_std_id tvnorm;
300 unsigned int tuner_type;
301 unsigned char tuner_addr;
302 unsigned int radio_type;
303 unsigned char radio_addr;
304 unsigned int has_radio;
305
306 /* V4l */
307 u32 freq;
308 struct video_device *video_dev;
309 struct video_device *vbi_dev;
310 struct video_device *radio_dev;
311
312 struct cx23885_dmaqueue vidq;
313 struct cx23885_dmaqueue vbiq;
314 spinlock_t slock;
213}; 315};
214 316
317extern struct list_head cx23885_devlist;
318
215#define SRAM_CH01 0 /* Video A */ 319#define SRAM_CH01 0 /* Video A */
216#define SRAM_CH02 1 /* VBI A */ 320#define SRAM_CH02 1 /* VBI A */
217#define SRAM_CH03 2 /* Video B */ 321#define SRAM_CH03 2 /* Video B */
@@ -254,19 +358,42 @@ struct sram_channel {
254#define cx_set(reg,bit) cx_andor((reg),(bit),(bit)) 358#define cx_set(reg,bit) cx_andor((reg),(bit),(bit))
255#define cx_clear(reg,bit) cx_andor((reg),(bit),0) 359#define cx_clear(reg,bit) cx_andor((reg),(bit),0)
256 360
361/* ----------------------------------------------------------- */
362/* cx23885-core.c */
363
257extern int cx23885_sram_channel_setup(struct cx23885_dev *dev, 364extern int cx23885_sram_channel_setup(struct cx23885_dev *dev,
258 struct sram_channel *ch, 365 struct sram_channel *ch,
259 unsigned int bpl, u32 risc); 366 unsigned int bpl, u32 risc);
260 367
261/* ----------------------------------------------------------- */ 368extern void cx23885_sram_channel_dump(struct cx23885_dev *dev,
262/* cx23885-cards.c */ 369 struct sram_channel *ch);
263 370
371extern int cx23885_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
372 u32 reg, u32 mask, u32 value);
373
374extern int cx23885_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
375 struct scatterlist *sglist,
376 unsigned int top_offset, unsigned int bottom_offset,
377 unsigned int bpl, unsigned int padding, unsigned int lines);
378
379void cx23885_cancel_buffers(struct cx23885_tsport *port);
380
381extern int cx23885_restart_queue(struct cx23885_tsport *port,
382 struct cx23885_dmaqueue *q);
383
384extern void cx23885_wakeup(struct cx23885_tsport *port,
385 struct cx23885_dmaqueue *q, u32 count);
386
387
388/* ----------------------------------------------------------- */
389/* cx23885-cards.c */
264extern struct cx23885_board cx23885_boards[]; 390extern struct cx23885_board cx23885_boards[];
265extern const unsigned int cx23885_bcount; 391extern const unsigned int cx23885_bcount;
266 392
267extern struct cx23885_subid cx23885_subids[]; 393extern struct cx23885_subid cx23885_subids[];
268extern const unsigned int cx23885_idcount; 394extern const unsigned int cx23885_idcount;
269 395
396extern int cx23885_tuner_callback(void *priv, int command, int arg);
270extern void cx23885_card_list(struct cx23885_dev *dev); 397extern void cx23885_card_list(struct cx23885_dev *dev);
271extern int cx23885_ir_init(struct cx23885_dev *dev); 398extern int cx23885_ir_init(struct cx23885_dev *dev);
272extern void cx23885_gpio_setup(struct cx23885_dev *dev); 399extern void cx23885_gpio_setup(struct cx23885_dev *dev);
@@ -280,19 +407,50 @@ extern int cx23885_buf_prepare(struct videobuf_queue *q,
280 struct cx23885_tsport *port, 407 struct cx23885_tsport *port,
281 struct cx23885_buffer *buf, 408 struct cx23885_buffer *buf,
282 enum v4l2_field field); 409 enum v4l2_field field);
283
284extern void cx23885_buf_queue(struct cx23885_tsport *port, 410extern void cx23885_buf_queue(struct cx23885_tsport *port,
285 struct cx23885_buffer *buf); 411 struct cx23885_buffer *buf);
286extern void cx23885_free_buffer(struct videobuf_queue *q, 412extern void cx23885_free_buffer(struct videobuf_queue *q,
287 struct cx23885_buffer *buf); 413 struct cx23885_buffer *buf);
288 414
289/* ----------------------------------------------------------- */ 415/* ----------------------------------------------------------- */
416/* cx23885-video.c */
417/* Video */
418extern int cx23885_video_register(struct cx23885_dev *dev);
419extern void cx23885_video_unregister(struct cx23885_dev *dev);
420extern int cx23885_video_irq(struct cx23885_dev *dev, u32 status);
421
422/* ----------------------------------------------------------- */
423/* cx23885-vbi.c */
424extern int cx23885_vbi_fmt(struct file *file, void *priv,
425 struct v4l2_format *f);
426extern void cx23885_vbi_timeout(unsigned long data);
427extern struct videobuf_queue_ops cx23885_vbi_qops;
428
290/* cx23885-i2c.c */ 429/* cx23885-i2c.c */
291extern int cx23885_i2c_register(struct cx23885_i2c *bus); 430extern int cx23885_i2c_register(struct cx23885_i2c *bus);
292extern int cx23885_i2c_unregister(struct cx23885_i2c *bus); 431extern int cx23885_i2c_unregister(struct cx23885_i2c *bus);
293extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd, 432extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd,
294 void *arg); 433 void *arg);
295 434
435/* ----------------------------------------------------------- */
436/* tv norms */
437
438static inline unsigned int norm_maxw(v4l2_std_id norm)
439{
440 return (norm & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 720 : 768;
441}
442
443static inline unsigned int norm_maxh(v4l2_std_id norm)
444{
445 return (norm & V4L2_STD_625_50) ? 576 : 480;
446}
447
448static inline unsigned int norm_swidth(v4l2_std_id norm)
449{
450 return (norm & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 754 : 922;
451}
452
453
296/* 454/*
297 * Local variables: 455 * Local variables:
298 * c-basic-offset: 8 456 * c-basic-offset: 8
diff --git a/drivers/media/video/cx25840/cx25840-audio.c b/drivers/media/video/cx25840/cx25840-audio.c
index 3d46a776df36..d6421e1e8f6a 100644
--- a/drivers/media/video/cx25840/cx25840-audio.c
+++ b/drivers/media/video/cx25840/cx25840-audio.c
@@ -32,118 +32,156 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
32 32
33 /* common for all inputs and rates */ 33 /* common for all inputs and rates */
34 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x10 */ 34 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x10 */
35 cx25840_write(client, 0x127, 0x50); 35 if (!state->is_cx23885)
36 cx25840_write(client, 0x127, 0x50);
36 37
37 if (state->aud_input != CX25840_AUDIO_SERIAL) { 38 if (state->aud_input != CX25840_AUDIO_SERIAL) {
38 switch (freq) { 39 switch (freq) {
39 case 32000: 40 case 32000:
41 if (state->is_cx23885) {
42 /* We don't have register values
43 * so avoid destroying registers. */
44 break;
45 }
40 /* VID_PLL and AUX_PLL */ 46 /* VID_PLL and AUX_PLL */
41 cx25840_write4(client, 0x108, 0x0f040610); 47 cx25840_write4(client, 0x108, 0x1006040f);
42 48
43 /* AUX_PLL_FRAC */ 49 /* AUX_PLL_FRAC */
44 cx25840_write4(client, 0x110, 0xee39bb01); 50 cx25840_write4(client, 0x110, 0x01bb39ee);
45 51
46 if (state->is_cx25836) 52 if (state->is_cx25836)
47 break; 53 break;
48 54
49 /* src3/4/6_ctl = 0x0801f77f */ 55 /* src3/4/6_ctl = 0x0801f77f */
50 cx25840_write4(client, 0x900, 0x7ff70108); 56 cx25840_write4(client, 0x900, 0x0801f77f);
51 cx25840_write4(client, 0x904, 0x7ff70108); 57 cx25840_write4(client, 0x904, 0x0801f77f);
52 cx25840_write4(client, 0x90c, 0x7ff70108); 58 cx25840_write4(client, 0x90c, 0x0801f77f);
53 break; 59 break;
54 60
55 case 44100: 61 case 44100:
62 if (state->is_cx23885) {
63 /* We don't have register values
64 * so avoid destroying registers. */
65 break;
66 }
56 /* VID_PLL and AUX_PLL */ 67 /* VID_PLL and AUX_PLL */
57 cx25840_write4(client, 0x108, 0x0f040910); 68 cx25840_write4(client, 0x108, 0x1009040f);
58 69
59 /* AUX_PLL_FRAC */ 70 /* AUX_PLL_FRAC */
60 cx25840_write4(client, 0x110, 0xd66bec00); 71 cx25840_write4(client, 0x110, 0x00ec6bd6);
61 72
62 if (state->is_cx25836) 73 if (state->is_cx25836)
63 break; 74 break;
64 75
65 /* src3/4/6_ctl = 0x08016d59 */ 76 /* src3/4/6_ctl = 0x08016d59 */
66 cx25840_write4(client, 0x900, 0x596d0108); 77 cx25840_write4(client, 0x900, 0x08016d59);
67 cx25840_write4(client, 0x904, 0x596d0108); 78 cx25840_write4(client, 0x904, 0x08016d59);
68 cx25840_write4(client, 0x90c, 0x596d0108); 79 cx25840_write4(client, 0x90c, 0x08016d59);
69 break; 80 break;
70 81
71 case 48000: 82 case 48000:
83 if (state->is_cx23885) {
84 /* We don't have register values
85 * so avoid destroying registers. */
86 break;
87 }
72 /* VID_PLL and AUX_PLL */ 88 /* VID_PLL and AUX_PLL */
73 cx25840_write4(client, 0x108, 0x0f040a10); 89 cx25840_write4(client, 0x108, 0x100a040f);
74 90
75 /* AUX_PLL_FRAC */ 91 /* AUX_PLL_FRAC */
76 cx25840_write4(client, 0x110, 0xe5d69800); 92 cx25840_write4(client, 0x110, 0x0098d6e5);
77 93
78 if (state->is_cx25836) 94 if (state->is_cx25836)
79 break; 95 break;
80 96
81 /* src3/4/6_ctl = 0x08014faa */ 97 /* src3/4/6_ctl = 0x08014faa */
82 cx25840_write4(client, 0x900, 0xaa4f0108); 98 cx25840_write4(client, 0x900, 0x08014faa);
83 cx25840_write4(client, 0x904, 0xaa4f0108); 99 cx25840_write4(client, 0x904, 0x08014faa);
84 cx25840_write4(client, 0x90c, 0xaa4f0108); 100 cx25840_write4(client, 0x90c, 0x08014faa);
85 break; 101 break;
86 } 102 }
87 } else { 103 } else {
88 switch (freq) { 104 switch (freq) {
89 case 32000: 105 case 32000:
106 if (state->is_cx23885) {
107 /* We don't have register values
108 * so avoid destroying registers. */
109 break;
110 }
90 /* VID_PLL and AUX_PLL */ 111 /* VID_PLL and AUX_PLL */
91 cx25840_write4(client, 0x108, 0x0f04081e); 112 cx25840_write4(client, 0x108, 0x1e08040f);
92 113
93 /* AUX_PLL_FRAC */ 114 /* AUX_PLL_FRAC */
94 cx25840_write4(client, 0x110, 0x69082a01); 115 cx25840_write4(client, 0x110, 0x012a0869);
95 116
96 if (state->is_cx25836) 117 if (state->is_cx25836)
97 break; 118 break;
98 119
99 /* src1_ctl = 0x08010000 */ 120 /* src1_ctl = 0x08010000 */
100 cx25840_write4(client, 0x8f8, 0x00000108); 121 cx25840_write4(client, 0x8f8, 0x08010000);
101 122
102 /* src3/4/6_ctl = 0x08020000 */ 123 /* src3/4/6_ctl = 0x08020000 */
103 cx25840_write4(client, 0x900, 0x00000208); 124 cx25840_write4(client, 0x900, 0x08020000);
104 cx25840_write4(client, 0x904, 0x00000208); 125 cx25840_write4(client, 0x904, 0x08020000);
105 cx25840_write4(client, 0x90c, 0x00000208); 126 cx25840_write4(client, 0x90c, 0x08020000);
106 127
107 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x14 */ 128 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x14 */
108 cx25840_write(client, 0x127, 0x54); 129 cx25840_write(client, 0x127, 0x54);
109 break; 130 break;
110 131
111 case 44100: 132 case 44100:
133 if (state->is_cx23885) {
134 /* We don't have register values
135 * so avoid destroying registers. */
136 break;
137 }
138
112 /* VID_PLL and AUX_PLL */ 139 /* VID_PLL and AUX_PLL */
113 cx25840_write4(client, 0x108, 0x0f040918); 140 cx25840_write4(client, 0x108, 0x1809040f);
114 141
115 /* AUX_PLL_FRAC */ 142 /* AUX_PLL_FRAC */
116 cx25840_write4(client, 0x110, 0xd66bec00); 143 cx25840_write4(client, 0x110, 0x00ec6bd6);
117 144
118 if (state->is_cx25836) 145 if (state->is_cx25836)
119 break; 146 break;
120 147
121 /* src1_ctl = 0x08010000 */ 148 /* src1_ctl = 0x08010000 */
122 cx25840_write4(client, 0x8f8, 0xcd600108); 149 cx25840_write4(client, 0x8f8, 0x080160cd);
123 150
124 /* src3/4/6_ctl = 0x08020000 */ 151 /* src3/4/6_ctl = 0x08020000 */
125 cx25840_write4(client, 0x900, 0x85730108); 152 cx25840_write4(client, 0x900, 0x08017385);
126 cx25840_write4(client, 0x904, 0x85730108); 153 cx25840_write4(client, 0x904, 0x08017385);
127 cx25840_write4(client, 0x90c, 0x85730108); 154 cx25840_write4(client, 0x90c, 0x08017385);
128 break; 155 break;
129 156
130 case 48000: 157 case 48000:
131 /* VID_PLL and AUX_PLL */ 158 if (!state->is_cx23885) {
132 cx25840_write4(client, 0x108, 0x0f040a18); 159 /* VID_PLL and AUX_PLL */
160 cx25840_write4(client, 0x108, 0x180a040f);
133 161
134 /* AUX_PLL_FRAC */ 162 /* AUX_PLL_FRAC */
135 cx25840_write4(client, 0x110, 0xe5d69800); 163 cx25840_write4(client, 0x110, 0x0098d6e5);
164 }
136 165
137 if (state->is_cx25836) 166 if (state->is_cx25836)
138 break; 167 break;
139 168
140 /* src1_ctl = 0x08010000 */ 169 if (!state->is_cx23885) {
141 cx25840_write4(client, 0x8f8, 0x00800108); 170 /* src1_ctl */
171 cx25840_write4(client, 0x8f8, 0x08018000);
142 172
143 /* src3/4/6_ctl = 0x08020000 */ 173 /* src3/4/6_ctl */
144 cx25840_write4(client, 0x900, 0x55550108); 174 cx25840_write4(client, 0x900, 0x08015555);
145 cx25840_write4(client, 0x904, 0x55550108); 175 cx25840_write4(client, 0x904, 0x08015555);
146 cx25840_write4(client, 0x90c, 0x55550108); 176 cx25840_write4(client, 0x90c, 0x08015555);
177 } else {
178
179 cx25840_write4(client, 0x8f8, 0x0801867c);
180
181 cx25840_write4(client, 0x900, 0x08014faa);
182 cx25840_write4(client, 0x904, 0x08014faa);
183 cx25840_write4(client, 0x90c, 0x08014faa);
184 }
147 break; 185 break;
148 } 186 }
149 } 187 }
@@ -168,14 +206,14 @@ void cx25840_audio_set_path(struct i2c_client *client)
168 206
169 if (state->aud_input == CX25840_AUDIO_SERIAL) { 207 if (state->aud_input == CX25840_AUDIO_SERIAL) {
170 /* Set Path1 to Serial Audio Input */ 208 /* Set Path1 to Serial Audio Input */
171 cx25840_write4(client, 0x8d0, 0x12100101); 209 cx25840_write4(client, 0x8d0, 0x01011012);
172 210
173 /* The microcontroller should not be started for the 211 /* The microcontroller should not be started for the
174 * non-tuner inputs: autodetection is specific for 212 * non-tuner inputs: autodetection is specific for
175 * TV audio. */ 213 * TV audio. */
176 } else { 214 } else {
177 /* Set Path1 to Analog Demod Main Channel */ 215 /* Set Path1 to Analog Demod Main Channel */
178 cx25840_write4(client, 0x8d0, 0x7038061f); 216 cx25840_write4(client, 0x8d0, 0x1f063870);
179 } 217 }
180 218
181 set_audclk_freq(client, state->audclk_freq); 219 set_audclk_freq(client, state->audclk_freq);
@@ -188,6 +226,11 @@ void cx25840_audio_set_path(struct i2c_client *client)
188 226
189 /* deassert soft reset */ 227 /* deassert soft reset */
190 cx25840_and_or(client, 0x810, ~0x1, 0x00); 228 cx25840_and_or(client, 0x810, ~0x1, 0x00);
229
230 if (state->is_cx23885) {
231 /* Ensure the controller is running when we exit */
232 cx25840_and_or(client, 0x803, ~0x10, 0x10);
233 }
191} 234}
192 235
193static int get_volume(struct i2c_client *client) 236static int get_volume(struct i2c_client *client)
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 15f191e170d2..756a1eeb274e 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -13,6 +13,8 @@
13 * NTSC sliced VBI support by Christopher Neufeld <television@cneufeld.ca> 13 * NTSC sliced VBI support by Christopher Neufeld <television@cneufeld.ca>
14 * with additional fixes by Hans Verkuil <hverkuil@xs4all.nl>. 14 * with additional fixes by Hans Verkuil <hverkuil@xs4all.nl>.
15 * 15 *
16 * CX23885 support by Steven Toth <stoth@hauppauge.com>.
17 *
16 * This program is free software; you can redistribute it and/or 18 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License 19 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2 20 * as published by the Free Software Foundation; either version 2
@@ -37,6 +39,7 @@
37#include <linux/delay.h> 39#include <linux/delay.h>
38#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
39#include <media/v4l2-chip-ident.h> 41#include <media/v4l2-chip-ident.h>
42#include <media/v4l2-i2c-drv-legacy.h>
40#include <media/cx25840.h> 43#include <media/cx25840.h>
41 44
42#include "cx25840-core.h" 45#include "cx25840-core.h"
@@ -72,10 +75,10 @@ int cx25840_write4(struct i2c_client *client, u16 addr, u32 value)
72 u8 buffer[6]; 75 u8 buffer[6];
73 buffer[0] = addr >> 8; 76 buffer[0] = addr >> 8;
74 buffer[1] = addr & 0xff; 77 buffer[1] = addr & 0xff;
75 buffer[2] = value >> 24; 78 buffer[2] = value & 0xff;
76 buffer[3] = (value >> 16) & 0xff; 79 buffer[3] = (value >> 8) & 0xff;
77 buffer[4] = (value >> 8) & 0xff; 80 buffer[4] = (value >> 16) & 0xff;
78 buffer[5] = value & 0xff; 81 buffer[5] = value >> 24;
79 return i2c_master_send(client, buffer, 6); 82 return i2c_master_send(client, buffer, 6);
80} 83}
81 84
@@ -122,8 +125,6 @@ int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask,
122 125
123static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input, 126static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
124 enum cx25840_audio_input aud_input); 127 enum cx25840_audio_input aud_input);
125static void log_audio_status(struct i2c_client *client);
126static void log_video_status(struct i2c_client *client);
127 128
128/* ----------------------------------------------------------------------- */ 129/* ----------------------------------------------------------------------- */
129 130
@@ -256,6 +257,96 @@ static void cx25840_initialize(struct i2c_client *client)
256 cx25840_and_or(client, 0x803, ~0x10, 0x10); 257 cx25840_and_or(client, 0x803, ~0x10, 0x10);
257} 258}
258 259
260static void cx23885_initialize(struct i2c_client *client)
261{
262 DEFINE_WAIT(wait);
263 struct cx25840_state *state = i2c_get_clientdata(client);
264 struct workqueue_struct *q;
265
266 /* Internal Reset */
267 cx25840_and_or(client, 0x102, ~0x01, 0x01);
268 cx25840_and_or(client, 0x102, ~0x01, 0x00);
269
270 /* Stop microcontroller */
271 cx25840_and_or(client, 0x803, ~0x10, 0x00);
272
273 /* DIF in reset? */
274 cx25840_write(client, 0x398, 0);
275
276 /* Trust the default xtal, no division */
277 /* This changes for the cx23888 products */
278 cx25840_write(client, 0x2, 0x76);
279
280 /* Bring down the regulator for AUX clk */
281 cx25840_write(client, 0x1, 0x40);
282
283 /* Sys PLL frac */
284 cx25840_write4(client, 0x11c, 0x01d1744c);
285
286 /* Sys PLL int */
287 cx25840_write4(client, 0x118, 0x00000416);
288
289 /* Disable DIF bypass */
290 cx25840_write4(client, 0x33c, 0x00000001);
291
292 /* DIF Src phase inc */
293 cx25840_write4(client, 0x340, 0x0df7df83);
294
295 /* Vid PLL frac */
296 cx25840_write4(client, 0x10c, 0x01b6db7b);
297
298 /* Vid PLL int */
299 cx25840_write4(client, 0x108, 0x00000512);
300
301 /* Luma */
302 cx25840_write4(client, 0x414, 0x00107d12);
303
304 /* Chroma */
305 cx25840_write4(client, 0x420, 0x3d008282);
306
307 /* Aux PLL frac */
308 cx25840_write4(client, 0x114, 0x017dbf48);
309
310 /* Aux PLL int */
311 cx25840_write4(client, 0x110, 0x000a030e);
312
313 /* ADC2 input select */
314 cx25840_write(client, 0x102, 0x10);
315
316 /* VIN1 & VIN5 */
317 cx25840_write(client, 0x103, 0x11);
318
319 /* Enable format auto detect */
320 cx25840_write(client, 0x400, 0);
321 /* Fast subchroma lock */
322 /* White crush, Chroma AGC & Chroma Killer enabled */
323 cx25840_write(client, 0x401, 0xe8);
324
325 /* Select AFE clock pad output source */
326 cx25840_write(client, 0x144, 0x05);
327
328 /* Do the firmware load in a work handler to prevent.
329 Otherwise the kernel is blocked waiting for the
330 bit-banging i2c interface to finish uploading the
331 firmware. */
332 INIT_WORK(&state->fw_work, cx25840_work_handler);
333 init_waitqueue_head(&state->fw_wait);
334 q = create_singlethread_workqueue("cx25840_fw");
335 prepare_to_wait(&state->fw_wait, &wait, TASK_UNINTERRUPTIBLE);
336 queue_work(q, &state->fw_work);
337 schedule();
338 finish_wait(&state->fw_wait, &wait);
339 destroy_workqueue(q);
340
341 cx25840_vbi_setup(client);
342
343 /* (re)set input */
344 set_input(client, state->vid_input, state->aud_input);
345
346 /* start microcontroller */
347 cx25840_and_or(client, 0x803, ~0x10, 0x10);
348}
349
259/* ----------------------------------------------------------------------- */ 350/* ----------------------------------------------------------------------- */
260 351
261static void input_change(struct i2c_client *client) 352static void input_change(struct i2c_client *client)
@@ -319,9 +410,22 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
319 vid_input <= CX25840_COMPOSITE8); 410 vid_input <= CX25840_COMPOSITE8);
320 u8 reg; 411 u8 reg;
321 412
322 v4l_dbg(1, cx25840_debug, client, "decoder set video input %d, audio input %d\n", 413 v4l_dbg(1, cx25840_debug, client,
323 vid_input, aud_input); 414 "decoder set video input %d, audio input %d\n",
415 vid_input, aud_input);
416
417 if (vid_input >= CX25840_VIN1_CH1) {
418 v4l_dbg(1, cx25840_debug, client, "vid_input 0x%x\n",
419 vid_input);
420 reg = vid_input & 0xff;
421 if ((vid_input & CX25840_SVIDEO_ON) == CX25840_SVIDEO_ON)
422 is_composite = 0;
423 else
424 is_composite = 1;
324 425
426 v4l_dbg(1, cx25840_debug, client, "mux cfg 0x%x comp=%d\n",
427 reg, is_composite);
428 } else
325 if (is_composite) { 429 if (is_composite) {
326 reg = 0xf0 + (vid_input - CX25840_COMPOSITE1); 430 reg = 0xf0 + (vid_input - CX25840_COMPOSITE1);
327 } else { 431 } else {
@@ -331,7 +435,8 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
331 if ((vid_input & ~0xff0) || 435 if ((vid_input & ~0xff0) ||
332 luma < CX25840_SVIDEO_LUMA1 || luma > CX25840_SVIDEO_LUMA4 || 436 luma < CX25840_SVIDEO_LUMA1 || luma > CX25840_SVIDEO_LUMA4 ||
333 chroma < CX25840_SVIDEO_CHROMA4 || chroma > CX25840_SVIDEO_CHROMA8) { 437 chroma < CX25840_SVIDEO_CHROMA4 || chroma > CX25840_SVIDEO_CHROMA8) {
334 v4l_err(client, "0x%04x is not a valid video input!\n", vid_input); 438 v4l_err(client, "0x%04x is not a valid video input!\n",
439 vid_input);
335 return -EINVAL; 440 return -EINVAL;
336 } 441 }
337 reg = 0xf0 + ((luma - CX25840_SVIDEO_LUMA1) >> 4); 442 reg = 0xf0 + ((luma - CX25840_SVIDEO_LUMA1) >> 4);
@@ -344,31 +449,49 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
344 } 449 }
345 } 450 }
346 451
347 switch (aud_input) { 452 /* The caller has previously prepared the correct routing
348 case CX25840_AUDIO_SERIAL: 453 * configuration in reg (for the cx23885) so we have no
349 /* do nothing, use serial audio input */ 454 * need to attempt to flip bits for earlier av decoders.
350 break; 455 */
351 case CX25840_AUDIO4: reg &= ~0x30; break; 456 if (!state->is_cx23885) {
352 case CX25840_AUDIO5: reg &= ~0x30; reg |= 0x10; break; 457 switch (aud_input) {
353 case CX25840_AUDIO6: reg &= ~0x30; reg |= 0x20; break; 458 case CX25840_AUDIO_SERIAL:
354 case CX25840_AUDIO7: reg &= ~0xc0; break; 459 /* do nothing, use serial audio input */
355 case CX25840_AUDIO8: reg &= ~0xc0; reg |= 0x40; break; 460 break;
461 case CX25840_AUDIO4: reg &= ~0x30; break;
462 case CX25840_AUDIO5: reg &= ~0x30; reg |= 0x10; break;
463 case CX25840_AUDIO6: reg &= ~0x30; reg |= 0x20; break;
464 case CX25840_AUDIO7: reg &= ~0xc0; break;
465 case CX25840_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
356 466
357 default: 467 default:
358 v4l_err(client, "0x%04x is not a valid audio input!\n", aud_input); 468 v4l_err(client, "0x%04x is not a valid audio input!\n",
359 return -EINVAL; 469 aud_input);
470 return -EINVAL;
471 }
360 } 472 }
361 473
362 cx25840_write(client, 0x103, reg); 474 cx25840_write(client, 0x103, reg);
475
363 /* Set INPUT_MODE to Composite (0) or S-Video (1) */ 476 /* Set INPUT_MODE to Composite (0) or S-Video (1) */
364 cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02); 477 cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02);
365 /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */ 478
366 cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0); 479 if (!state->is_cx23885) {
367 /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */ 480 /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
368 if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30) 481 cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
369 cx25840_and_or(client, 0x102, ~0x4, 4); 482 /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2&CH3 */
370 else 483 if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30)
371 cx25840_and_or(client, 0x102, ~0x4, 0); 484 cx25840_and_or(client, 0x102, ~0x4, 4);
485 else
486 cx25840_and_or(client, 0x102, ~0x4, 0);
487 } else {
488 if (is_composite)
489 /* ADC2 input select channel 2 */
490 cx25840_and_or(client, 0x102, ~0x2, 0);
491 else
492 /* ADC2 input select channel 3 */
493 cx25840_and_or(client, 0x102, ~0x2, 2);
494 }
372 495
373 state->vid_input = vid_input; 496 state->vid_input = vid_input;
374 state->aud_input = aud_input; 497 state->aud_input = aud_input;
@@ -376,6 +499,25 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
376 cx25840_audio_set_path(client); 499 cx25840_audio_set_path(client);
377 input_change(client); 500 input_change(client);
378 } 501 }
502
503 if (state->is_cx23885) {
504 /* Audio channel 1 src : Parallel 1 */
505 cx25840_write(client, 0x124, 0x03);
506
507 /* Select AFE clock pad output source */
508 cx25840_write(client, 0x144, 0x05);
509
510 /* I2S_IN_CTL: I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1 */
511 cx25840_write(client, 0x914, 0xa0);
512
513 /* I2S_OUT_CTL:
514 * I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1
515 * I2S_OUT_MASTER_MODE = Master
516 */
517 cx25840_write(client, 0x918, 0xa0);
518 cx25840_write(client, 0x919, 0x01);
519 }
520
379 return 0; 521 return 0;
380} 522}
381 523
@@ -641,6 +783,200 @@ static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
641 783
642/* ----------------------------------------------------------------------- */ 784/* ----------------------------------------------------------------------- */
643 785
786static void log_video_status(struct i2c_client *client)
787{
788 static const char *const fmt_strs[] = {
789 "0x0",
790 "NTSC-M", "NTSC-J", "NTSC-4.43",
791 "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
792 "0x9", "0xA", "0xB",
793 "SECAM",
794 "0xD", "0xE", "0xF"
795 };
796
797 struct cx25840_state *state = i2c_get_clientdata(client);
798 u8 vidfmt_sel = cx25840_read(client, 0x400) & 0xf;
799 u8 gen_stat1 = cx25840_read(client, 0x40d);
800 u8 gen_stat2 = cx25840_read(client, 0x40e);
801 int vid_input = state->vid_input;
802
803 v4l_info(client, "Video signal: %spresent\n",
804 (gen_stat2 & 0x20) ? "" : "not ");
805 v4l_info(client, "Detected format: %s\n",
806 fmt_strs[gen_stat1 & 0xf]);
807
808 v4l_info(client, "Specified standard: %s\n",
809 vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
810
811 if (vid_input >= CX25840_COMPOSITE1 &&
812 vid_input <= CX25840_COMPOSITE8) {
813 v4l_info(client, "Specified video input: Composite %d\n",
814 vid_input - CX25840_COMPOSITE1 + 1);
815 } else {
816 v4l_info(client, "Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
817 (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
818 }
819
820 v4l_info(client, "Specified audioclock freq: %d Hz\n", state->audclk_freq);
821}
822
823/* ----------------------------------------------------------------------- */
824
825static void log_audio_status(struct i2c_client *client)
826{
827 struct cx25840_state *state = i2c_get_clientdata(client);
828 u8 download_ctl = cx25840_read(client, 0x803);
829 u8 mod_det_stat0 = cx25840_read(client, 0x804);
830 u8 mod_det_stat1 = cx25840_read(client, 0x805);
831 u8 audio_config = cx25840_read(client, 0x808);
832 u8 pref_mode = cx25840_read(client, 0x809);
833 u8 afc0 = cx25840_read(client, 0x80b);
834 u8 mute_ctl = cx25840_read(client, 0x8d3);
835 int aud_input = state->aud_input;
836 char *p;
837
838 switch (mod_det_stat0) {
839 case 0x00: p = "mono"; break;
840 case 0x01: p = "stereo"; break;
841 case 0x02: p = "dual"; break;
842 case 0x04: p = "tri"; break;
843 case 0x10: p = "mono with SAP"; break;
844 case 0x11: p = "stereo with SAP"; break;
845 case 0x12: p = "dual with SAP"; break;
846 case 0x14: p = "tri with SAP"; break;
847 case 0xfe: p = "forced mode"; break;
848 default: p = "not defined";
849 }
850 v4l_info(client, "Detected audio mode: %s\n", p);
851
852 switch (mod_det_stat1) {
853 case 0x00: p = "not defined"; break;
854 case 0x01: p = "EIAJ"; break;
855 case 0x02: p = "A2-M"; break;
856 case 0x03: p = "A2-BG"; break;
857 case 0x04: p = "A2-DK1"; break;
858 case 0x05: p = "A2-DK2"; break;
859 case 0x06: p = "A2-DK3"; break;
860 case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
861 case 0x08: p = "AM-L"; break;
862 case 0x09: p = "NICAM-BG"; break;
863 case 0x0a: p = "NICAM-DK"; break;
864 case 0x0b: p = "NICAM-I"; break;
865 case 0x0c: p = "NICAM-L"; break;
866 case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
867 case 0x0e: p = "IF FM Radio"; break;
868 case 0x0f: p = "BTSC"; break;
869 case 0x10: p = "high-deviation FM"; break;
870 case 0x11: p = "very high-deviation FM"; break;
871 case 0xfd: p = "unknown audio standard"; break;
872 case 0xfe: p = "forced audio standard"; break;
873 case 0xff: p = "no detected audio standard"; break;
874 default: p = "not defined";
875 }
876 v4l_info(client, "Detected audio standard: %s\n", p);
877 v4l_info(client, "Audio muted: %s\n",
878 (state->unmute_volume >= 0) ? "yes" : "no");
879 v4l_info(client, "Audio microcontroller: %s\n",
880 (download_ctl & 0x10) ?
881 ((mute_ctl & 0x2) ? "detecting" : "running") : "stopped");
882
883 switch (audio_config >> 4) {
884 case 0x00: p = "undefined"; break;
885 case 0x01: p = "BTSC"; break;
886 case 0x02: p = "EIAJ"; break;
887 case 0x03: p = "A2-M"; break;
888 case 0x04: p = "A2-BG"; break;
889 case 0x05: p = "A2-DK1"; break;
890 case 0x06: p = "A2-DK2"; break;
891 case 0x07: p = "A2-DK3"; break;
892 case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
893 case 0x09: p = "AM-L"; break;
894 case 0x0a: p = "NICAM-BG"; break;
895 case 0x0b: p = "NICAM-DK"; break;
896 case 0x0c: p = "NICAM-I"; break;
897 case 0x0d: p = "NICAM-L"; break;
898 case 0x0e: p = "FM radio"; break;
899 case 0x0f: p = "automatic detection"; break;
900 default: p = "undefined";
901 }
902 v4l_info(client, "Configured audio standard: %s\n", p);
903
904 if ((audio_config >> 4) < 0xF) {
905 switch (audio_config & 0xF) {
906 case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
907 case 0x01: p = "MONO2 (LANGUAGE B)"; break;
908 case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
909 case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
910 case 0x04: p = "STEREO"; break;
911 case 0x05: p = "DUAL1 (AB)"; break;
912 case 0x06: p = "DUAL2 (AC) (FM)"; break;
913 case 0x07: p = "DUAL3 (BC) (FM)"; break;
914 case 0x08: p = "DUAL4 (AC) (AM)"; break;
915 case 0x09: p = "DUAL5 (BC) (AM)"; break;
916 case 0x0a: p = "SAP"; break;
917 default: p = "undefined";
918 }
919 v4l_info(client, "Configured audio mode: %s\n", p);
920 } else {
921 switch (audio_config & 0xF) {
922 case 0x00: p = "BG"; break;
923 case 0x01: p = "DK1"; break;
924 case 0x02: p = "DK2"; break;
925 case 0x03: p = "DK3"; break;
926 case 0x04: p = "I"; break;
927 case 0x05: p = "L"; break;
928 case 0x06: p = "BTSC"; break;
929 case 0x07: p = "EIAJ"; break;
930 case 0x08: p = "A2-M"; break;
931 case 0x09: p = "FM Radio"; break;
932 case 0x0f: p = "automatic standard and mode detection"; break;
933 default: p = "undefined";
934 }
935 v4l_info(client, "Configured audio system: %s\n", p);
936 }
937
938 if (aud_input) {
939 v4l_info(client, "Specified audio input: Tuner (In%d)\n", aud_input);
940 } else {
941 v4l_info(client, "Specified audio input: External\n");
942 }
943
944 switch (pref_mode & 0xf) {
945 case 0: p = "mono/language A"; break;
946 case 1: p = "language B"; break;
947 case 2: p = "language C"; break;
948 case 3: p = "analog fallback"; break;
949 case 4: p = "stereo"; break;
950 case 5: p = "language AC"; break;
951 case 6: p = "language BC"; break;
952 case 7: p = "language AB"; break;
953 default: p = "undefined";
954 }
955 v4l_info(client, "Preferred audio mode: %s\n", p);
956
957 if ((audio_config & 0xf) == 0xf) {
958 switch ((afc0 >> 3) & 0x3) {
959 case 0: p = "system DK"; break;
960 case 1: p = "system L"; break;
961 case 2: p = "autodetect"; break;
962 default: p = "undefined";
963 }
964 v4l_info(client, "Selected 65 MHz format: %s\n", p);
965
966 switch (afc0 & 0x7) {
967 case 0: p = "chroma"; break;
968 case 1: p = "BTSC"; break;
969 case 2: p = "EIAJ"; break;
970 case 3: p = "A2-M"; break;
971 case 4: p = "autodetect"; break;
972 default: p = "undefined";
973 }
974 v4l_info(client, "Selected 45 MHz format: %s\n", p);
975 }
976}
977
978/* ----------------------------------------------------------------------- */
979
644static int cx25840_command(struct i2c_client *client, unsigned int cmd, 980static int cx25840_command(struct i2c_client *client, unsigned int cmd,
645 void *arg) 981 void *arg)
646{ 982{
@@ -660,6 +996,8 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
660 state->is_initialized = 1; 996 state->is_initialized = 1;
661 if (state->is_cx25836) 997 if (state->is_cx25836)
662 cx25836_initialize(client); 998 cx25836_initialize(client);
999 else if (state->is_cx23885)
1000 cx23885_initialize(client);
663 else 1001 else
664 cx25840_initialize(client); 1002 cx25840_initialize(client);
665 } 1003 }
@@ -677,6 +1015,7 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
677 return -EINVAL; 1015 return -EINVAL;
678 if (!capable(CAP_SYS_ADMIN)) 1016 if (!capable(CAP_SYS_ADMIN))
679 return -EPERM; 1017 return -EPERM;
1018
680 if (cmd == VIDIOC_DBG_G_REGISTER) 1019 if (cmd == VIDIOC_DBG_G_REGISTER)
681 reg->val = cx25840_read(client, reg->reg & 0x0fff); 1020 reg->val = cx25840_read(client, reg->reg & 0x0fff);
682 else 1021 else
@@ -693,14 +1032,26 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
693 1032
694 case VIDIOC_STREAMON: 1033 case VIDIOC_STREAMON:
695 v4l_dbg(1, cx25840_debug, client, "enable output\n"); 1034 v4l_dbg(1, cx25840_debug, client, "enable output\n");
696 cx25840_write(client, 0x115, state->is_cx25836 ? 0x0c : 0x8c); 1035 if (state->is_cx23885) {
697 cx25840_write(client, 0x116, state->is_cx25836 ? 0x04 : 0x07); 1036 u8 v = (cx25840_read(client, 0x421) | 0x0b);
1037 cx25840_write(client, 0x421, v);
1038 } else {
1039 cx25840_write(client, 0x115,
1040 state->is_cx25836 ? 0x0c : 0x8c);
1041 cx25840_write(client, 0x116,
1042 state->is_cx25836 ? 0x04 : 0x07);
1043 }
698 break; 1044 break;
699 1045
700 case VIDIOC_STREAMOFF: 1046 case VIDIOC_STREAMOFF:
701 v4l_dbg(1, cx25840_debug, client, "disable output\n"); 1047 v4l_dbg(1, cx25840_debug, client, "disable output\n");
702 cx25840_write(client, 0x115, 0x00); 1048 if (state->is_cx23885) {
703 cx25840_write(client, 0x116, 0x00); 1049 u8 v = cx25840_read(client, 0x421) & ~(0x0b);
1050 cx25840_write(client, 0x421, v);
1051 } else {
1052 cx25840_write(client, 0x115, 0x00);
1053 cx25840_write(client, 0x116, 0x00);
1054 }
704 break; 1055 break;
705 1056
706 case VIDIOC_LOG_STATUS: 1057 case VIDIOC_LOG_STATUS:
@@ -863,6 +1214,8 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
863 case VIDIOC_INT_RESET: 1214 case VIDIOC_INT_RESET:
864 if (state->is_cx25836) 1215 if (state->is_cx25836)
865 cx25836_initialize(client); 1216 cx25836_initialize(client);
1217 else if (state->is_cx23885)
1218 cx23885_initialize(client);
866 else 1219 else
867 cx25840_initialize(client); 1220 cx25840_initialize(client);
868 break; 1221 break;
@@ -879,35 +1232,21 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
879 1232
880/* ----------------------------------------------------------------------- */ 1233/* ----------------------------------------------------------------------- */
881 1234
882static struct i2c_driver i2c_driver_cx25840; 1235static int cx25840_probe(struct i2c_client *client)
883
884static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
885 int kind)
886{ 1236{
887 struct i2c_client *client;
888 struct cx25840_state *state; 1237 struct cx25840_state *state;
889 u32 id; 1238 u32 id;
890 u16 device_id; 1239 u16 device_id;
891 1240
892 /* Check if the adapter supports the needed features 1241 /* Check if the adapter supports the needed features */
893 * Not until kernel version 2.6.11 did the bit-algo 1242 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
894 * correctly report that it would do an I2C-level xfer */ 1243 return -EIO;
895 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
896 return 0;
897
898 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
899 if (client == 0)
900 return -ENOMEM;
901
902 client->addr = address;
903 client->adapter = adapter;
904 client->driver = &i2c_driver_cx25840;
905 snprintf(client->name, sizeof(client->name) - 1, "cx25840");
906 1244
907 v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", client->addr << 1); 1245 v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", client->addr << 1);
908 1246
909 device_id = cx25840_read(client, 0x101) << 8; 1247 device_id = cx25840_read(client, 0x101) << 8;
910 device_id |= cx25840_read(client, 0x100); 1248 device_id |= cx25840_read(client, 0x100);
1249 v4l_dbg(1, cx25840_debug, client, "device_id = 0x%04x\n", device_id);
911 1250
912 /* The high byte of the device ID should be 1251 /* The high byte of the device ID should be
913 * 0x83 for the cx2583x and 0x84 for the cx2584x */ 1252 * 0x83 for the cx2583x and 0x84 for the cx2584x */
@@ -916,16 +1255,18 @@ static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
916 } 1255 }
917 else if ((device_id & 0xff00) == 0x8400) { 1256 else if ((device_id & 0xff00) == 0x8400) {
918 id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf); 1257 id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf);
1258 } else if (device_id == 0x0000) {
1259 id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6;
1260 } else if (device_id == 0x1313) {
1261 id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6;
919 } 1262 }
920 else { 1263 else {
921 v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n"); 1264 v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
922 kfree(client); 1265 return -ENODEV;
923 return 0;
924 } 1266 }
925 1267
926 state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL); 1268 state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL);
927 if (state == NULL) { 1269 if (state == NULL) {
928 kfree(client);
929 return -ENOMEM; 1270 return -ENOMEM;
930 } 1271 }
931 1272
@@ -939,6 +1280,7 @@ static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
939 i2c_set_clientdata(client, state); 1280 i2c_set_clientdata(client, state);
940 state->c = client; 1281 state->c = client;
941 state->is_cx25836 = ((device_id & 0xff00) == 0x8300); 1282 state->is_cx25836 = ((device_id & 0xff00) == 0x8300);
1283 state->is_cx23885 = (device_id == 0x0000) || (device_id == 0x1313);
942 state->vid_input = CX25840_COMPOSITE7; 1284 state->vid_input = CX25840_COMPOSITE7;
943 state->aud_input = CX25840_AUDIO8; 1285 state->aud_input = CX25840_AUDIO8;
944 state->audclk_freq = 48000; 1286 state->audclk_freq = 48000;
@@ -949,250 +1291,19 @@ static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
949 state->id = id; 1291 state->id = id;
950 state->rev = device_id; 1292 state->rev = device_id;
951 1293
952 i2c_attach_client(client);
953
954 return 0;
955}
956
957static int cx25840_attach_adapter(struct i2c_adapter *adapter)
958{
959 if (adapter->class & I2C_CLASS_TV_ANALOG)
960 return i2c_probe(adapter, &addr_data, &cx25840_detect_client);
961 return 0; 1294 return 0;
962} 1295}
963 1296
964static int cx25840_detach_client(struct i2c_client *client) 1297static int cx25840_remove(struct i2c_client *client)
965{ 1298{
966 struct cx25840_state *state = i2c_get_clientdata(client); 1299 kfree(i2c_get_clientdata(client));
967 int err;
968
969 err = i2c_detach_client(client);
970 if (err) {
971 return err;
972 }
973
974 kfree(state);
975 kfree(client);
976
977 return 0; 1300 return 0;
978} 1301}
979 1302
980/* ----------------------------------------------------------------------- */ 1303static struct v4l2_i2c_driver_data v4l2_i2c_data = {
981 1304 .name = "cx25840",
982static struct i2c_driver i2c_driver_cx25840 = { 1305 .driverid = I2C_DRIVERID_CX25840,
983 .driver = {
984 .name = "cx25840",
985 },
986 .id = I2C_DRIVERID_CX25840,
987 .attach_adapter = cx25840_attach_adapter,
988 .detach_client = cx25840_detach_client,
989 .command = cx25840_command, 1306 .command = cx25840_command,
1307 .probe = cx25840_probe,
1308 .remove = cx25840_remove,
990}; 1309};
991
992
993static int __init m__init(void)
994{
995 return i2c_add_driver(&i2c_driver_cx25840);
996}
997
998static void __exit m__exit(void)
999{
1000 i2c_del_driver(&i2c_driver_cx25840);
1001}
1002
1003module_init(m__init);
1004module_exit(m__exit);
1005
1006/* ----------------------------------------------------------------------- */
1007
1008static void log_video_status(struct i2c_client *client)
1009{
1010 static const char *const fmt_strs[] = {
1011 "0x0",
1012 "NTSC-M", "NTSC-J", "NTSC-4.43",
1013 "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
1014 "0x9", "0xA", "0xB",
1015 "SECAM",
1016 "0xD", "0xE", "0xF"
1017 };
1018
1019 struct cx25840_state *state = i2c_get_clientdata(client);
1020 u8 vidfmt_sel = cx25840_read(client, 0x400) & 0xf;
1021 u8 gen_stat1 = cx25840_read(client, 0x40d);
1022 u8 gen_stat2 = cx25840_read(client, 0x40e);
1023 int vid_input = state->vid_input;
1024
1025 v4l_info(client, "Video signal: %spresent\n",
1026 (gen_stat2 & 0x20) ? "" : "not ");
1027 v4l_info(client, "Detected format: %s\n",
1028 fmt_strs[gen_stat1 & 0xf]);
1029
1030 v4l_info(client, "Specified standard: %s\n",
1031 vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
1032
1033 if (vid_input >= CX25840_COMPOSITE1 &&
1034 vid_input <= CX25840_COMPOSITE8) {
1035 v4l_info(client, "Specified video input: Composite %d\n",
1036 vid_input - CX25840_COMPOSITE1 + 1);
1037 } else {
1038 v4l_info(client, "Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
1039 (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
1040 }
1041
1042 v4l_info(client, "Specified audioclock freq: %d Hz\n", state->audclk_freq);
1043}
1044
1045/* ----------------------------------------------------------------------- */
1046
1047static void log_audio_status(struct i2c_client *client)
1048{
1049 struct cx25840_state *state = i2c_get_clientdata(client);
1050 u8 download_ctl = cx25840_read(client, 0x803);
1051 u8 mod_det_stat0 = cx25840_read(client, 0x804);
1052 u8 mod_det_stat1 = cx25840_read(client, 0x805);
1053 u8 audio_config = cx25840_read(client, 0x808);
1054 u8 pref_mode = cx25840_read(client, 0x809);
1055 u8 afc0 = cx25840_read(client, 0x80b);
1056 u8 mute_ctl = cx25840_read(client, 0x8d3);
1057 int aud_input = state->aud_input;
1058 char *p;
1059
1060 switch (mod_det_stat0) {
1061 case 0x00: p = "mono"; break;
1062 case 0x01: p = "stereo"; break;
1063 case 0x02: p = "dual"; break;
1064 case 0x04: p = "tri"; break;
1065 case 0x10: p = "mono with SAP"; break;
1066 case 0x11: p = "stereo with SAP"; break;
1067 case 0x12: p = "dual with SAP"; break;
1068 case 0x14: p = "tri with SAP"; break;
1069 case 0xfe: p = "forced mode"; break;
1070 default: p = "not defined";
1071 }
1072 v4l_info(client, "Detected audio mode: %s\n", p);
1073
1074 switch (mod_det_stat1) {
1075 case 0x00: p = "not defined"; break;
1076 case 0x01: p = "EIAJ"; break;
1077 case 0x02: p = "A2-M"; break;
1078 case 0x03: p = "A2-BG"; break;
1079 case 0x04: p = "A2-DK1"; break;
1080 case 0x05: p = "A2-DK2"; break;
1081 case 0x06: p = "A2-DK3"; break;
1082 case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
1083 case 0x08: p = "AM-L"; break;
1084 case 0x09: p = "NICAM-BG"; break;
1085 case 0x0a: p = "NICAM-DK"; break;
1086 case 0x0b: p = "NICAM-I"; break;
1087 case 0x0c: p = "NICAM-L"; break;
1088 case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
1089 case 0x0e: p = "IF FM Radio"; break;
1090 case 0x0f: p = "BTSC"; break;
1091 case 0x10: p = "high-deviation FM"; break;
1092 case 0x11: p = "very high-deviation FM"; break;
1093 case 0xfd: p = "unknown audio standard"; break;
1094 case 0xfe: p = "forced audio standard"; break;
1095 case 0xff: p = "no detected audio standard"; break;
1096 default: p = "not defined";
1097 }
1098 v4l_info(client, "Detected audio standard: %s\n", p);
1099 v4l_info(client, "Audio muted: %s\n",
1100 (state->unmute_volume >= 0) ? "yes" : "no");
1101 v4l_info(client, "Audio microcontroller: %s\n",
1102 (download_ctl & 0x10) ?
1103 ((mute_ctl & 0x2) ? "detecting" : "running") : "stopped");
1104
1105 switch (audio_config >> 4) {
1106 case 0x00: p = "undefined"; break;
1107 case 0x01: p = "BTSC"; break;
1108 case 0x02: p = "EIAJ"; break;
1109 case 0x03: p = "A2-M"; break;
1110 case 0x04: p = "A2-BG"; break;
1111 case 0x05: p = "A2-DK1"; break;
1112 case 0x06: p = "A2-DK2"; break;
1113 case 0x07: p = "A2-DK3"; break;
1114 case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
1115 case 0x09: p = "AM-L"; break;
1116 case 0x0a: p = "NICAM-BG"; break;
1117 case 0x0b: p = "NICAM-DK"; break;
1118 case 0x0c: p = "NICAM-I"; break;
1119 case 0x0d: p = "NICAM-L"; break;
1120 case 0x0e: p = "FM radio"; break;
1121 case 0x0f: p = "automatic detection"; break;
1122 default: p = "undefined";
1123 }
1124 v4l_info(client, "Configured audio standard: %s\n", p);
1125
1126 if ((audio_config >> 4) < 0xF) {
1127 switch (audio_config & 0xF) {
1128 case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
1129 case 0x01: p = "MONO2 (LANGUAGE B)"; break;
1130 case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
1131 case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
1132 case 0x04: p = "STEREO"; break;
1133 case 0x05: p = "DUAL1 (AB)"; break;
1134 case 0x06: p = "DUAL2 (AC) (FM)"; break;
1135 case 0x07: p = "DUAL3 (BC) (FM)"; break;
1136 case 0x08: p = "DUAL4 (AC) (AM)"; break;
1137 case 0x09: p = "DUAL5 (BC) (AM)"; break;
1138 case 0x0a: p = "SAP"; break;
1139 default: p = "undefined";
1140 }
1141 v4l_info(client, "Configured audio mode: %s\n", p);
1142 } else {
1143 switch (audio_config & 0xF) {
1144 case 0x00: p = "BG"; break;
1145 case 0x01: p = "DK1"; break;
1146 case 0x02: p = "DK2"; break;
1147 case 0x03: p = "DK3"; break;
1148 case 0x04: p = "I"; break;
1149 case 0x05: p = "L"; break;
1150 case 0x06: p = "BTSC"; break;
1151 case 0x07: p = "EIAJ"; break;
1152 case 0x08: p = "A2-M"; break;
1153 case 0x09: p = "FM Radio"; break;
1154 case 0x0f: p = "automatic standard and mode detection"; break;
1155 default: p = "undefined";
1156 }
1157 v4l_info(client, "Configured audio system: %s\n", p);
1158 }
1159
1160 if (aud_input) {
1161 v4l_info(client, "Specified audio input: Tuner (In%d)\n", aud_input);
1162 } else {
1163 v4l_info(client, "Specified audio input: External\n");
1164 }
1165
1166 switch (pref_mode & 0xf) {
1167 case 0: p = "mono/language A"; break;
1168 case 1: p = "language B"; break;
1169 case 2: p = "language C"; break;
1170 case 3: p = "analog fallback"; break;
1171 case 4: p = "stereo"; break;
1172 case 5: p = "language AC"; break;
1173 case 6: p = "language BC"; break;
1174 case 7: p = "language AB"; break;
1175 default: p = "undefined";
1176 }
1177 v4l_info(client, "Preferred audio mode: %s\n", p);
1178
1179 if ((audio_config & 0xf) == 0xf) {
1180 switch ((afc0 >> 3) & 0x3) {
1181 case 0: p = "system DK"; break;
1182 case 1: p = "system L"; break;
1183 case 2: p = "autodetect"; break;
1184 default: p = "undefined";
1185 }
1186 v4l_info(client, "Selected 65 MHz format: %s\n", p);
1187
1188 switch (afc0 & 0x7) {
1189 case 0: p = "chroma"; break;
1190 case 1: p = "BTSC"; break;
1191 case 2: p = "EIAJ"; break;
1192 case 3: p = "A2-M"; break;
1193 case 4: p = "autodetect"; break;
1194 default: p = "undefined";
1195 }
1196 v4l_info(client, "Selected 45 MHz format: %s\n", p);
1197 }
1198}
diff --git a/drivers/media/video/cx25840/cx25840-core.h b/drivers/media/video/cx25840/cx25840-core.h
index ea669b1f084d..95093edc9186 100644
--- a/drivers/media/video/cx25840/cx25840-core.h
+++ b/drivers/media/video/cx25840/cx25840-core.h
@@ -47,6 +47,7 @@ struct cx25840_state {
47 u32 id; 47 u32 id;
48 u32 rev; 48 u32 rev;
49 int is_cx25836; 49 int is_cx25836;
50 int is_cx23885;
50 int is_initialized; 51 int is_initialized;
51 wait_queue_head_t fw_wait; /* wake up when the fw load is finished */ 52 wait_queue_head_t fw_wait; /* wake up when the fw load is finished */
52 struct work_struct fw_work; /* work entry for fw load */ 53 struct work_struct fw_work; /* work entry for fw load */
diff --git a/drivers/media/video/cx25840/cx25840-firmware.c b/drivers/media/video/cx25840/cx25840-firmware.c
index e852024a5ea3..1ddf724a2c74 100644
--- a/drivers/media/video/cx25840/cx25840-firmware.c
+++ b/drivers/media/video/cx25840/cx25840-firmware.c
@@ -24,6 +24,7 @@
24#include "cx25840-core.h" 24#include "cx25840-core.h"
25 25
26#define FWFILE "v4l-cx25840.fw" 26#define FWFILE "v4l-cx25840.fw"
27#define FWFILE_CX23885 "v4l-cx23885-avcore-01.fw"
27 28
28/* 29/*
29 * Mike Isely <isely@pobox.com> - The FWSEND parameter controls the 30 * Mike Isely <isely@pobox.com> - The FWSEND parameter controls the
@@ -92,10 +93,14 @@ static int fw_write(struct i2c_client *client, u8 * data, int size)
92 93
93int cx25840_loadfw(struct i2c_client *client) 94int cx25840_loadfw(struct i2c_client *client)
94{ 95{
96 struct cx25840_state *state = i2c_get_clientdata(client);
95 const struct firmware *fw = NULL; 97 const struct firmware *fw = NULL;
96 u8 buffer[4], *ptr; 98 u8 buffer[4], *ptr;
97 int size, send, retval; 99 int size, send, retval;
98 100
101 if (state->is_cx23885)
102 firmware = FWFILE_CX23885;
103
99 if (request_firmware(&fw, firmware, FWDEV(client)) != 0) { 104 if (request_firmware(&fw, firmware, FWDEV(client)) != 0) {
100 v4l_err(client, "unable to open firmware %s\n", firmware); 105 v4l_err(client, "unable to open firmware %s\n", firmware);
101 return -EINVAL; 106 return -EINVAL;
diff --git a/drivers/media/video/cx25840/cx25840-vbi.c b/drivers/media/video/cx25840/cx25840-vbi.c
index ced13febed89..6828f59b9d83 100644
--- a/drivers/media/video/cx25840/cx25840-vbi.c
+++ b/drivers/media/video/cx25840/cx25840-vbi.c
@@ -180,7 +180,7 @@ void cx25840_vbi_setup(struct i2c_client *client)
180 fsc/1000000,fsc%1000000); 180 fsc/1000000,fsc%1000000);
181 181
182 v4l_dbg(1, cx25840_debug, client, "hblank %i, hactive %i, " 182 v4l_dbg(1, cx25840_debug, client, "hblank %i, hactive %i, "
183 "vblank %i , vactive %i, vblank656 %i, src_dec %i," 183 "vblank %i, vactive %i, vblank656 %i, src_dec %i, "
184 "burst 0x%02x, luma_lpf %i, uv_lpf %i, comb 0x%02x," 184 "burst 0x%02x, luma_lpf %i, uv_lpf %i, comb 0x%02x,"
185 " sc 0x%06x\n", 185 " sc 0x%06x\n",
186 hblank, hactive, vblank, vactive, vblank656, 186 hblank, hactive, vblank, vactive, vblank656,
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index ceb31d4a2512..49d3813a9b48 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -8,6 +8,7 @@ config VIDEO_CX88
8 select VIDEO_TUNER 8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 9 select VIDEO_TVEEPROM
10 select VIDEO_IR 10 select VIDEO_IR
11 select VIDEO_WM8775 if VIDEO_HELPER_CHIPS_AUTO
11 ---help--- 12 ---help---
12 This is a video4linux driver for Conexant 2388x based 13 This is a video4linux driver for Conexant 2388x based
13 TV cards. 14 TV cards.
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index 40ffd7a5579a..8735227f7e47 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -417,7 +417,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
417 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC); 417 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC);
418 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 418 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
419 419
420 buf->vb.state = STATE_PREPARED; 420 buf->vb.state = VIDEOBUF_PREPARED;
421 421
422 chip->buf = buf; 422 chip->buf = buf;
423 chip->dma_risc = dma; 423 chip->dma_risc = dma;
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index f802b5653569..a99e9d5950aa 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -307,7 +307,7 @@ static int register_read(struct cx88_core *core, u32 address, u32 *value)
307 307
308/* ------------------------------------------------------------------ */ 308/* ------------------------------------------------------------------ */
309 309
310static int blackbird_mbox_func(void *priv, int command, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]) 310static int blackbird_mbox_func(void *priv, u32 command, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA])
311{ 311{
312 struct cx8802_dev *dev = priv; 312 struct cx8802_dev *dev = priv;
313 unsigned long timeout; 313 unsigned long timeout;
@@ -536,11 +536,12 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
536 dprintk(1,"Initialize codec\n"); 536 dprintk(1,"Initialize codec\n");
537 retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */ 537 retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */
538 if (retval < 0) { 538 if (retval < 0) {
539
540 dev->mpeg_active = 0;
541
539 /* ping was not successful, reset and upload firmware */ 542 /* ping was not successful, reset and upload firmware */
540 cx_write(MO_SRST_IO, 0); /* SYS_RSTO=0 */ 543 cx_write(MO_SRST_IO, 0); /* SYS_RSTO=0 */
541 msleep(1);
542 cx_write(MO_SRST_IO, 1); /* SYS_RSTO=1 */ 544 cx_write(MO_SRST_IO, 1); /* SYS_RSTO=1 */
543 msleep(1);
544 retval = blackbird_load_firmware(dev); 545 retval = blackbird_load_firmware(dev);
545 if (retval < 0) 546 if (retval < 0)
546 return retval; 547 return retval;
@@ -562,7 +563,6 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
562 } 563 }
563 dprintk(0, "Firmware version is 0x%08x\n", version); 564 dprintk(0, "Firmware version is 0x%08x\n", version);
564 } 565 }
565 msleep(1);
566 566
567 cx_write(MO_PINMUX_IO, 0x88); /* 656-8bit IO and enable MPEG parallel IO */ 567 cx_write(MO_PINMUX_IO, 0x88); /* 656-8bit IO and enable MPEG parallel IO */
568 cx_clear(MO_INPUT_FORMAT, 0x100); /* chroma subcarrier lock to normal? */ 568 cx_clear(MO_INPUT_FORMAT, 0x100); /* chroma subcarrier lock to normal? */
@@ -570,40 +570,68 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
570 cx_clear(MO_OUTPUT_FORMAT, 0x0008); /* Normal Y-limits to let the mpeg encoder sync */ 570 cx_clear(MO_OUTPUT_FORMAT, 0x0008); /* Normal Y-limits to let the mpeg encoder sync */
571 571
572 blackbird_codec_settings(dev); 572 blackbird_codec_settings(dev);
573 msleep(1);
574 573
575 /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xef, 0xef);
576 blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xf0, 0xf0);
577 blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0x180, 0x180); */
578 blackbird_api_cmd(dev, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 0, 574 blackbird_api_cmd(dev, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 0,
579 BLACKBIRD_FIELD1_SAA7115, 575 BLACKBIRD_FIELD1_SAA7115,
580 BLACKBIRD_FIELD2_SAA7115 576 BLACKBIRD_FIELD2_SAA7115
581 ); 577 );
582 578
583 /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_PLACEHOLDER, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); */
584 blackbird_api_cmd(dev, CX2341X_ENC_SET_PLACEHOLDER, 12, 0, 579 blackbird_api_cmd(dev, CX2341X_ENC_SET_PLACEHOLDER, 12, 0,
585 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA, 580 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
586 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 581 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
587 582
588 /* initialize the video input */ 583 return 0;
589 blackbird_api_cmd(dev, CX2341X_ENC_INITIALIZE_INPUT, 0, 0); 584}
590 585
591 msleep(1); 586static int blackbird_start_codec(struct file *file, void *priv)
587{
588 struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev;
589 struct cx88_core *core = dev->core;
590 /* start capturing to the host interface */
591 u32 reg;
592 592
593 blackbird_api_cmd(dev, CX2341X_ENC_MUTE_VIDEO, 1, 0, BLACKBIRD_UNMUTE); 593 int i;
594 msleep(1); 594 int lastchange = -1;
595 blackbird_api_cmd(dev, CX2341X_ENC_MUTE_AUDIO, 1, 0, BLACKBIRD_UNMUTE); 595 int lastval = 0;
596 msleep(1); 596
597 for (i = 0; (i < 10) && (i < (lastchange + 4)); i++) {
598 reg = cx_read(AUD_STATUS);
599
600 dprintk(1, "AUD_STATUS:%dL: 0x%x\n", i, reg);
601 if ((reg & 0x0F) != lastval) {
602 lastval = reg & 0x0F;
603 lastchange = i;
604 }
605 msleep(100);
606 }
607
608 /* unmute audio source */
609 cx_clear(AUD_VOL_CTL, (1 << 6));
610
611 blackbird_api_cmd(dev, CX2341X_ENC_REFRESH_INPUT, 0, 0);
612
613 /* initialize the video input */
614 blackbird_api_cmd(dev, CX2341X_ENC_INITIALIZE_INPUT, 0, 0);
597 615
598 /* start capturing to the host interface */ 616 /* start capturing to the host interface */
599 /* blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0, 0, 0x13); */
600 blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0, 617 blackbird_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0,
601 BLACKBIRD_MPEG_CAPTURE, 618 BLACKBIRD_MPEG_CAPTURE,
602 BLACKBIRD_RAW_BITS_NONE 619 BLACKBIRD_RAW_BITS_NONE
603 ); 620 );
604 msleep(10);
605 621
606 blackbird_api_cmd(dev, CX2341X_ENC_REFRESH_INPUT, 0,0); 622 dev->mpeg_active = 1;
623 return 0;
624}
625
626static int blackbird_stop_codec(struct cx8802_dev *dev)
627{
628 blackbird_api_cmd(dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
629 BLACKBIRD_END_NOW,
630 BLACKBIRD_MPEG_CAPTURE,
631 BLACKBIRD_RAW_BITS_NONE
632 );
633
634 dev->mpeg_active = 0;
607 return 0; 635 return 0;
608} 636}
609 637
@@ -833,6 +861,10 @@ static int vidioc_s_ext_ctrls (struct file *file, void *priv,
833 861
834 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) 862 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
835 return -EINVAL; 863 return -EINVAL;
864
865 if (dev->mpeg_active)
866 blackbird_stop_codec(dev);
867
836 p = dev->params; 868 p = dev->params;
837 err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_S_EXT_CTRLS); 869 err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_S_EXT_CTRLS);
838 if (!err) { 870 if (!err) {
@@ -864,10 +896,9 @@ static int vidioc_s_frequency (struct file *file, void *priv,
864 struct cx8802_dev *dev = fh->dev; 896 struct cx8802_dev *dev = fh->dev;
865 struct cx88_core *core = dev->core; 897 struct cx88_core *core = dev->core;
866 898
867 blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, 899 if (dev->mpeg_active)
868 BLACKBIRD_END_NOW, 900 blackbird_stop_codec(dev);
869 BLACKBIRD_MPEG_CAPTURE, 901
870 BLACKBIRD_RAW_BITS_NONE);
871 cx88_set_freq (core,f); 902 cx88_set_freq (core,f);
872 blackbird_initialize_codec(dev); 903 blackbird_initialize_codec(dev);
873 cx88_set_scale(dev->core, dev->width, dev->height, 904 cx88_set_scale(dev->core, dev->width, dev->height,
@@ -1073,15 +1104,11 @@ static int mpeg_open(struct inode *inode, struct file *file)
1073static int mpeg_release(struct inode *inode, struct file *file) 1104static int mpeg_release(struct inode *inode, struct file *file)
1074{ 1105{
1075 struct cx8802_fh *fh = file->private_data; 1106 struct cx8802_fh *fh = file->private_data;
1076 struct cx8802_dev *dev = NULL; 1107 struct cx8802_dev *dev = fh->dev;
1077 struct cx8802_driver *drv = NULL; 1108 struct cx8802_driver *drv = NULL;
1078 1109
1079 /* blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, BLACKBIRD_END_NOW, 0, 0x13); */ 1110 if (dev->mpeg_active)
1080 blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, 1111 blackbird_stop_codec(dev);
1081 BLACKBIRD_END_NOW,
1082 BLACKBIRD_MPEG_CAPTURE,
1083 BLACKBIRD_RAW_BITS_NONE
1084 );
1085 1112
1086 cx8802_cancel_buffers(fh->dev); 1113 cx8802_cancel_buffers(fh->dev);
1087 /* stop mpeg capture */ 1114 /* stop mpeg capture */
@@ -1107,6 +1134,10 @@ static ssize_t
1107mpeg_read(struct file *file, char __user *data, size_t count, loff_t *ppos) 1134mpeg_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1108{ 1135{
1109 struct cx8802_fh *fh = file->private_data; 1136 struct cx8802_fh *fh = file->private_data;
1137 struct cx8802_dev *dev = fh->dev;
1138
1139 if (!dev->mpeg_active)
1140 blackbird_start_codec(file, fh);
1110 1141
1111 return videobuf_read_stream(&fh->mpegq, data, count, ppos, 0, 1142 return videobuf_read_stream(&fh->mpegq, data, count, ppos, 0,
1112 file->f_flags & O_NONBLOCK); 1143 file->f_flags & O_NONBLOCK);
@@ -1282,6 +1313,7 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)
1282 core->name); 1313 core->name);
1283 host_setup(dev->core); 1314 host_setup(dev->core);
1284 1315
1316 blackbird_initialize_codec(dev);
1285 blackbird_register_video(dev); 1317 blackbird_register_video(dev);
1286 1318
1287 /* initial device configuration: needed ? */ 1319 /* initial device configuration: needed ? */
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index a4eb6a87a761..e6b7f518c56e 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -26,6 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27 27
28#include "cx88.h" 28#include "cx88.h"
29#include "tea5767.h"
29 30
30static unsigned int tuner[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; 31static unsigned int tuner[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
31static unsigned int radio[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; 32static unsigned int radio[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
@@ -245,6 +246,10 @@ static const struct cx88_board cx88_boards[] = {
245 }}, 246 }},
246 .radio = { 247 .radio = {
247 .type = CX88_RADIO, 248 .type = CX88_RADIO,
249 .vmux = 3,
250 .gpio0 = 0x000040bf,
251 .gpio1 = 0x000080c0,
252 .gpio2 = 0x0000ff20,
248 }, 253 },
249 }, 254 },
250 [CX88_BOARD_WINFAST_DV2000] = { 255 [CX88_BOARD_WINFAST_DV2000] = {
@@ -297,22 +302,22 @@ static const struct cx88_board cx88_boards[] = {
297 .type = CX88_VMUX_TELEVISION, 302 .type = CX88_VMUX_TELEVISION,
298 .vmux = 0, 303 .vmux = 0,
299 .gpio0 = 0x0000bde2, 304 .gpio0 = 0x0000bde2,
300 .extadc = 1, 305 .audioroute = 1,
301 },{ 306 },{
302 .type = CX88_VMUX_COMPOSITE1, 307 .type = CX88_VMUX_COMPOSITE1,
303 .vmux = 1, 308 .vmux = 1,
304 .gpio0 = 0x0000bde6, 309 .gpio0 = 0x0000bde6,
305 .extadc = 1, 310 .audioroute = 1,
306 },{ 311 },{
307 .type = CX88_VMUX_SVIDEO, 312 .type = CX88_VMUX_SVIDEO,
308 .vmux = 2, 313 .vmux = 2,
309 .gpio0 = 0x0000bde6, 314 .gpio0 = 0x0000bde6,
310 .extadc = 1, 315 .audioroute = 1,
311 }}, 316 }},
312 .radio = { 317 .radio = {
313 .type = CX88_RADIO, 318 .type = CX88_RADIO,
314 .gpio0 = 0x0000bd62, 319 .gpio0 = 0x0000bd62,
315 .extadc = 1, 320 .audioroute = 1,
316 }, 321 },
317 .mpeg = CX88_MPEG_BLACKBIRD, 322 .mpeg = CX88_MPEG_BLACKBIRD,
318 }, 323 },
@@ -373,7 +378,7 @@ static const struct cx88_board cx88_boards[] = {
373 .type = CX88_VMUX_SVIDEO, 378 .type = CX88_VMUX_SVIDEO,
374 .vmux = 2, 379 .vmux = 2,
375 .gpio0 = 0x0000fde6, // 0x0000fda6 L,R RCA audio in? 380 .gpio0 = 0x0000fde6, // 0x0000fda6 L,R RCA audio in?
376 .extadc = 1, 381 .audioroute = 1,
377 }}, 382 }},
378 .radio = { 383 .radio = {
379 .type = CX88_RADIO, 384 .type = CX88_RADIO,
@@ -544,7 +549,7 @@ static const struct cx88_board cx88_boards[] = {
544 .input = {{ 549 .input = {{
545 .type = CX88_VMUX_TELEVISION, 550 .type = CX88_VMUX_TELEVISION,
546 .vmux = 0, 551 .vmux = 0,
547 .extadc = 1, 552 .audioroute = 1,
548 }}, 553 }},
549 .mpeg = CX88_MPEG_BLACKBIRD, 554 .mpeg = CX88_MPEG_BLACKBIRD,
550 }, 555 },
@@ -667,22 +672,22 @@ static const struct cx88_board cx88_boards[] = {
667 .type = CX88_VMUX_TELEVISION, 672 .type = CX88_VMUX_TELEVISION,
668 .vmux = 0, 673 .vmux = 0,
669 .gpio0 = 0x00009d80, 674 .gpio0 = 0x00009d80,
670 .extadc = 1, 675 .audioroute = 1,
671 },{ 676 },{
672 .type = CX88_VMUX_COMPOSITE1, 677 .type = CX88_VMUX_COMPOSITE1,
673 .vmux = 1, 678 .vmux = 1,
674 .gpio0 = 0x00009d76, 679 .gpio0 = 0x00009d76,
675 .extadc = 1, 680 .audioroute = 1,
676 },{ 681 },{
677 .type = CX88_VMUX_SVIDEO, 682 .type = CX88_VMUX_SVIDEO,
678 .vmux = 2, 683 .vmux = 2,
679 .gpio0 = 0x00009d76, 684 .gpio0 = 0x00009d76,
680 .extadc = 1, 685 .audioroute = 1,
681 }}, 686 }},
682 .radio = { 687 .radio = {
683 .type = CX88_RADIO, 688 .type = CX88_RADIO,
684 .gpio0 = 0x00009d00, 689 .gpio0 = 0x00009d00,
685 .extadc = 1, 690 .audioroute = 1,
686 }, 691 },
687 .mpeg = CX88_MPEG_BLACKBIRD, 692 .mpeg = CX88_MPEG_BLACKBIRD,
688 }, 693 },
@@ -821,23 +826,23 @@ static const struct cx88_board cx88_boards[] = {
821 .type = CX88_VMUX_COMPOSITE1, 826 .type = CX88_VMUX_COMPOSITE1,
822 .vmux = 0, 827 .vmux = 0,
823 .gpio0 = 0x0000cd73, 828 .gpio0 = 0x0000cd73,
824 .extadc = 1, 829 .audioroute = 1,
825 },{ 830 },{
826 .type = CX88_VMUX_SVIDEO, 831 .type = CX88_VMUX_SVIDEO,
827 .vmux = 1, 832 .vmux = 1,
828 .gpio0 = 0x0000cd73, 833 .gpio0 = 0x0000cd73,
829 .extadc = 1, 834 .audioroute = 1,
830 },{ 835 },{
831 .type = CX88_VMUX_TELEVISION, 836 .type = CX88_VMUX_TELEVISION,
832 .vmux = 3, 837 .vmux = 3,
833 .gpio0 = 0x0000cdb3, 838 .gpio0 = 0x0000cdb3,
834 .extadc = 1, 839 .audioroute = 1,
835 }}, 840 }},
836 .radio = { 841 .radio = {
837 .type = CX88_RADIO, 842 .type = CX88_RADIO,
838 .vmux = 2, 843 .vmux = 2,
839 .gpio0 = 0x0000cdf3, 844 .gpio0 = 0x0000cdf3,
840 .extadc = 1, 845 .audioroute = 1,
841 }, 846 },
842 .mpeg = CX88_MPEG_BLACKBIRD, 847 .mpeg = CX88_MPEG_BLACKBIRD,
843 }, 848 },
@@ -1105,12 +1110,12 @@ static const struct cx88_board cx88_boards[] = {
1105 .type = CX88_VMUX_COMPOSITE1, 1110 .type = CX88_VMUX_COMPOSITE1,
1106 .vmux = 1, 1111 .vmux = 1,
1107 .gpio0 = 0x3de6, 1112 .gpio0 = 0x3de6,
1108 .extadc = 1, 1113 .audioroute = 1,
1109 },{ 1114 },{
1110 .type = CX88_VMUX_SVIDEO, 1115 .type = CX88_VMUX_SVIDEO,
1111 .vmux = 2, 1116 .vmux = 2,
1112 .gpio0 = 0x3de6, 1117 .gpio0 = 0x3de6,
1113 .extadc = 1, 1118 .audioroute = 1,
1114 }}, 1119 }},
1115 .radio = { 1120 .radio = {
1116 .type = CX88_RADIO, 1121 .type = CX88_RADIO,
@@ -1335,17 +1340,17 @@ static const struct cx88_board cx88_boards[] = {
1335 .type = CX88_VMUX_TELEVISION, 1340 .type = CX88_VMUX_TELEVISION,
1336 .vmux = 0, 1341 .vmux = 0,
1337 .gpio0 = 0xe780, 1342 .gpio0 = 0xe780,
1338 .extadc = 1, 1343 .audioroute = 1,
1339 },{ 1344 },{
1340 .type = CX88_VMUX_COMPOSITE1, 1345 .type = CX88_VMUX_COMPOSITE1,
1341 .vmux = 1, 1346 .vmux = 1,
1342 .gpio0 = 0xe780, 1347 .gpio0 = 0xe780,
1343 .extadc = 1, 1348 .audioroute = 2,
1344 },{ 1349 },{
1345 .type = CX88_VMUX_SVIDEO, 1350 .type = CX88_VMUX_SVIDEO,
1346 .vmux = 2, 1351 .vmux = 2,
1347 .gpio0 = 0xe780, 1352 .gpio0 = 0xe780,
1348 .extadc = 1, 1353 .audioroute = 2,
1349 }}, 1354 }},
1350 /* fixme: Add radio support */ 1355 /* fixme: Add radio support */
1351 .mpeg = CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD, 1356 .mpeg = CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD,
@@ -1370,6 +1375,32 @@ static const struct cx88_board cx88_boards[] = {
1370 .gpio0 = 0x07fa, 1375 .gpio0 = 0x07fa,
1371 }}, 1376 }},
1372 }, 1377 },
1378 [CX88_BOARD_PINNACLE_PCTV_HD_800i] = {
1379 .name = "Pinnacle PCTV HD 800i",
1380 .tuner_type = TUNER_XC5000,
1381 .radio_type = UNSET,
1382 .tuner_addr = ADDR_UNSET,
1383 .radio_addr = ADDR_UNSET,
1384 .input = {{
1385 .type = CX88_VMUX_TELEVISION,
1386 .vmux = 0,
1387 .gpio0 = 0x04fb,
1388 .gpio1 = 0x10ff,
1389 },{
1390 .type = CX88_VMUX_COMPOSITE1,
1391 .vmux = 1,
1392 .gpio0 = 0x04fb,
1393 .gpio1 = 0x10ef,
1394 .audioroute = 1,
1395 },{
1396 .type = CX88_VMUX_SVIDEO,
1397 .vmux = 2,
1398 .gpio0 = 0x04fb,
1399 .gpio1 = 0x10ef,
1400 .audioroute = 1,
1401 }},
1402 .mpeg = CX88_MPEG_DVB,
1403 },
1373}; 1404};
1374 1405
1375/* ------------------------------------------------------------------ */ 1406/* ------------------------------------------------------------------ */
@@ -1679,6 +1710,10 @@ static const struct cx88_subid cx88_subids[] = {
1679 .subvendor = 0x1421, 1710 .subvendor = 0x1421,
1680 .subdevice = 0x0390, 1711 .subdevice = 0x0390,
1681 .card = CX88_BOARD_ADSTECH_PTV_390, 1712 .card = CX88_BOARD_ADSTECH_PTV_390,
1713 },{
1714 .subvendor = 0x11bd,
1715 .subdevice = 0x0051,
1716 .card = CX88_BOARD_PINNACLE_PCTV_HD_800i,
1682 }, 1717 },
1683}; 1718};
1684 1719
@@ -1846,6 +1881,36 @@ static void dvico_fusionhdtv_hybrid_init(struct cx88_core *core)
1846} 1881}
1847 1882
1848/* ----------------------------------------------------------------------- */ 1883/* ----------------------------------------------------------------------- */
1884/* Tuner callback function. Currently only needed for the Pinnacle *
1885 * PCTV HD 800i with an xc5000 sillicon tuner. This is used for both *
1886 * analog tuner attach (tuner-core.c) and dvb tuner attach (cx88-dvb.c) */
1887
1888int cx88_tuner_callback(void *priv, int command, int arg)
1889{
1890 struct i2c_algo_bit_data *i2c_algo = priv;
1891 struct cx88_core *core = i2c_algo->data;
1892
1893 switch(core->boardnr) {
1894 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
1895 if(command == 0) { /* This is the reset command from xc5000 */
1896 /* Reset XC5000 tuner via SYS_RSTO_pin */
1897 cx_write(MO_SRST_IO, 0);
1898 msleep(10);
1899 cx_write(MO_SRST_IO, 1);
1900 return 0;
1901 }
1902 else {
1903 printk(KERN_ERR
1904 "xc5000: unknown tuner callback command.\n");
1905 return -EINVAL;
1906 }
1907 break;
1908 }
1909 return 0; /* Should never be here */
1910}
1911EXPORT_SYMBOL(cx88_tuner_callback);
1912
1913/* ----------------------------------------------------------------------- */
1849 1914
1850static void cx88_card_list(struct cx88_core *core, struct pci_dev *pci) 1915static void cx88_card_list(struct cx88_core *core, struct pci_dev *pci)
1851{ 1916{
@@ -1979,6 +2044,23 @@ static void cx88_card_setup(struct cx88_core *core)
1979 core->name, i); 2044 core->name, i);
1980 } 2045 }
1981 break; 2046 break;
2047 case CX88_BOARD_MSI_TVANYWHERE_MASTER:
2048 {
2049 struct v4l2_priv_tun_config tea5767_cfg;
2050 struct tea5767_ctrl ctl;
2051
2052 memset(&ctl, 0, sizeof(ctl));
2053
2054 ctl.high_cut = 1;
2055 ctl.st_noise = 1;
2056 ctl.deemph_75 = 1;
2057 ctl.xtal_freq = TEA5767_HIGH_LO_13MHz;
2058
2059 tea5767_cfg.tuner = TUNER_TEA5767;
2060 tea5767_cfg.priv = &ctl;
2061
2062 cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &tea5767_cfg);
2063 }
1982 } 2064 }
1983} 2065}
1984 2066
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 62e8dd24c5f5..01e2ac98970b 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -220,7 +220,7 @@ cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf)
220 videobuf_dma_unmap(q, dma); 220 videobuf_dma_unmap(q, dma);
221 videobuf_dma_free(dma); 221 videobuf_dma_free(dma);
222 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc); 222 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc);
223 buf->vb.state = STATE_NEEDS_INIT; 223 buf->vb.state = VIDEOBUF_NEEDS_INIT;
224} 224}
225 225
226/* ------------------------------------------------------------------ */ 226/* ------------------------------------------------------------------ */
@@ -538,7 +538,7 @@ void cx88_wakeup(struct cx88_core *core,
538 do_gettimeofday(&buf->vb.ts); 538 do_gettimeofday(&buf->vb.ts);
539 dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i, 539 dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i,
540 count, buf->count); 540 count, buf->count);
541 buf->vb.state = STATE_DONE; 541 buf->vb.state = VIDEOBUF_DONE;
542 list_del(&buf->vb.queue); 542 list_del(&buf->vb.queue);
543 wake_up(&buf->vb.done); 543 wake_up(&buf->vb.done);
544 } 544 }
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index fce19caf9d04..f7b41eb1bb5a 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -40,6 +40,8 @@
40#include "cx22702.h" 40#include "cx22702.h"
41#include "or51132.h" 41#include "or51132.h"
42#include "lgdt330x.h" 42#include "lgdt330x.h"
43#include "s5h1409.h"
44#include "xc5000.h"
43#include "nxt200x.h" 45#include "nxt200x.h"
44#include "cx24123.h" 46#include "cx24123.h"
45#include "isl6421.h" 47#include "isl6421.h"
@@ -371,6 +373,22 @@ static struct cx24123_config kworld_dvbs_100_config = {
371 .lnb_polarity = 1, 373 .lnb_polarity = 1,
372}; 374};
373 375
376static struct s5h1409_config pinnacle_pctv_hd_800i_config = {
377 .demod_address = 0x32 >> 1,
378 .output_mode = S5H1409_PARALLEL_OUTPUT,
379 .gpio = S5H1409_GPIO_ON,
380 .qam_if = 44000,
381 .inversion = S5H1409_INVERSION_OFF,
382 .status_mode = S5H1409_DEMODLOCKING,
383 .mpeg_timing = S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
384};
385
386static struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = {
387 .i2c_address = 0x64,
388 .if_khz = 5380,
389 .tuner_callback = cx88_tuner_callback,
390};
391
374static int dvb_register(struct cx8802_dev *dev) 392static int dvb_register(struct cx8802_dev *dev)
375{ 393{
376 /* init struct videobuf_dvb */ 394 /* init struct videobuf_dvb */
@@ -625,6 +643,21 @@ static int dvb_register(struct cx8802_dev *dev)
625 dev->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage; 643 dev->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;
626 } 644 }
627 break; 645 break;
646 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
647 dev->dvb.frontend = dvb_attach(s5h1409_attach,
648 &pinnacle_pctv_hd_800i_config,
649 &dev->core->i2c_adap);
650 if (dev->dvb.frontend != NULL) {
651 /* tuner_config.video_dev must point to
652 * i2c_adap.algo_data
653 */
654 pinnacle_pctv_hd_800i_tuner_config.priv =
655 dev->core->i2c_adap.algo_data;
656 dvb_attach(xc5000_attach, dev->dvb.frontend,
657 &dev->core->i2c_adap,
658 &pinnacle_pctv_hd_800i_tuner_config);
659 }
660 break;
628 default: 661 default:
629 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n", 662 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
630 dev->core->name); 663 dev->core->name);
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index c8b1c50625f4..566b26af523e 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -109,26 +109,32 @@ static int attach_inform(struct i2c_client *client)
109 109
110 if (core->board.radio_type != UNSET) { 110 if (core->board.radio_type != UNSET) {
111 if ((core->board.radio_addr==ADDR_UNSET)||(core->board.radio_addr==client->addr)) { 111 if ((core->board.radio_addr==ADDR_UNSET)||(core->board.radio_addr==client->addr)) {
112 tun_setup.mode_mask = T_RADIO; 112 tun_setup.mode_mask = T_RADIO;
113 tun_setup.type = core->board.radio_type; 113 tun_setup.type = core->board.radio_type;
114 tun_setup.addr = core->board.radio_addr; 114 tun_setup.addr = core->board.radio_addr;
115 115 tun_setup.tuner_callback = cx88_tuner_callback;
116 client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup); 116 client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
117 } 117 }
118 } 118 }
119 if (core->board.tuner_type != UNSET) { 119 if (core->board.tuner_type != UNSET) {
120 if ((core->board.tuner_addr==ADDR_UNSET)||(core->board.tuner_addr==client->addr)) { 120 if ((core->board.tuner_addr==ADDR_UNSET)||(core->board.tuner_addr==client->addr)) {
121 121
122 tun_setup.mode_mask = T_ANALOG_TV; 122 tun_setup.mode_mask = T_ANALOG_TV;
123 tun_setup.type = core->board.tuner_type; 123 tun_setup.type = core->board.tuner_type;
124 tun_setup.addr = core->board.tuner_addr; 124 tun_setup.addr = core->board.tuner_addr;
125 125 tun_setup.tuner_callback = cx88_tuner_callback;
126 client->driver->command (client,TUNER_SET_TYPE_ADDR, &tun_setup); 126 client->driver->command (client,TUNER_SET_TYPE_ADDR, &tun_setup);
127 } 127 }
128 } 128 }
129 129
130 if (core->board.tda9887_conf) 130 if (core->board.tda9887_conf) {
131 client->driver->command(client, TDA9887_SET_CONFIG, &core->board.tda9887_conf); 131 struct v4l2_priv_tun_config tda9887_cfg;
132
133 tda9887_cfg.tuner = TUNER_TDA9887;
134 tda9887_cfg.priv = &core->board.tda9887_conf;
135
136 client->driver->command(client, TUNER_SET_CONFIG, &tda9887_cfg);
137 }
132 return 0; 138 return 0;
133} 139}
134 140
@@ -176,6 +182,7 @@ static char *i2c_devs[128] = {
176 [ 0xa0 >> 1 ] = "eeprom", 182 [ 0xa0 >> 1 ] = "eeprom",
177 [ 0xc0 >> 1 ] = "tuner (analog)", 183 [ 0xc0 >> 1 ] = "tuner (analog)",
178 [ 0xc2 >> 1 ] = "tuner (analog/dvb)", 184 [ 0xc2 >> 1 ] = "tuner (analog/dvb)",
185 [ 0xc8 >> 1 ] = "xc5000",
179}; 186};
180 187
181static void do_i2c_scan(char *name, struct i2c_client *c) 188static void do_i2c_scan(char *name, struct i2c_client *c)
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index e52de3968c63..bb0911b4d2f6 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -305,6 +305,11 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
305 ir->mask_keycode = 0xfa; 305 ir->mask_keycode = 0xfa;
306 ir->polling = 50; /* ms */ 306 ir->polling = 50; /* ms */
307 break; 307 break;
308 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
309 ir_codes = ir_codes_pinnacle_pctv_hd;
310 ir_type = IR_TYPE_RC5;
311 ir->sampling = 1;
312 break;
308 } 313 }
309 314
310 if (NULL == ir_codes) { 315 if (NULL == ir_codes) {
@@ -443,6 +448,7 @@ void cx88_ir_irq(struct cx88_core *core)
443 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 448 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
444 case CX88_BOARD_HAUPPAUGE_HVR1100: 449 case CX88_BOARD_HAUPPAUGE_HVR1100:
445 case CX88_BOARD_HAUPPAUGE_HVR3000: 450 case CX88_BOARD_HAUPPAUGE_HVR3000:
451 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
446 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7); 452 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
447 ir_dprintk("biphase decoded: %x\n", ircode); 453 ir_dprintk("biphase decoded: %x\n", ircode);
448 if ((ircode & 0xfffff000) != 0x3000) 454 if ((ircode & 0xfffff000) != 0x3000)
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index 448c67380945..0aedbeaf94cd 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -102,7 +102,7 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
102 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl); 102 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl);
103 udelay(100); 103 udelay(100);
104 cx_write(MO_PINMUX_IO, 0x00); 104 cx_write(MO_PINMUX_IO, 0x00);
105 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01); 105 cx_write(TS_HW_SOP_CNTRL, 0x47<<16|188<<4|0x01);
106 switch (core->boardnr) { 106 switch (core->boardnr) {
107 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q: 107 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
108 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T: 108 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
@@ -117,6 +117,15 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
117 break; 117 break;
118 case CX88_BOARD_HAUPPAUGE_HVR1300: 118 case CX88_BOARD_HAUPPAUGE_HVR1300:
119 break; 119 break;
120 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
121 /* Enable MPEG parallel IO and video signal pins */
122 cx_write(MO_PINMUX_IO, 0x88);
123 cx_write(TS_HW_SOP_CNTRL, (0x47 << 16) | (188 << 4));
124 dev->ts_gen_cntrl = 5;
125 cx_write(TS_SOP_STAT, 0);
126 cx_write(TS_VALERR_CNTRL, 0);
127 udelay(100);
128 break;
120 default: 129 default:
121 cx_write(TS_SOP_STAT, 0x00); 130 cx_write(TS_SOP_STAT, 0x00);
122 break; 131 break;
@@ -195,7 +204,7 @@ static int cx8802_restart_queue(struct cx8802_dev *dev,
195 list_del(&buf->vb.queue); 204 list_del(&buf->vb.queue);
196 list_add_tail(&buf->vb.queue,&q->active); 205 list_add_tail(&buf->vb.queue,&q->active);
197 cx8802_start_dma(dev, q, buf); 206 cx8802_start_dma(dev, q, buf);
198 buf->vb.state = STATE_ACTIVE; 207 buf->vb.state = VIDEOBUF_ACTIVE;
199 buf->count = q->count++; 208 buf->count = q->count++;
200 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 209 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
201 dprintk(1,"[%p/%d] restart_queue - first active\n", 210 dprintk(1,"[%p/%d] restart_queue - first active\n",
@@ -206,7 +215,7 @@ static int cx8802_restart_queue(struct cx8802_dev *dev,
206 prev->fmt == buf->fmt) { 215 prev->fmt == buf->fmt) {
207 list_del(&buf->vb.queue); 216 list_del(&buf->vb.queue);
208 list_add_tail(&buf->vb.queue,&q->active); 217 list_add_tail(&buf->vb.queue,&q->active);
209 buf->vb.state = STATE_ACTIVE; 218 buf->vb.state = VIDEOBUF_ACTIVE;
210 buf->count = q->count++; 219 buf->count = q->count++;
211 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 220 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
212 dprintk(1,"[%p/%d] restart_queue - move to active\n", 221 dprintk(1,"[%p/%d] restart_queue - move to active\n",
@@ -242,7 +251,7 @@ int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev,
242 if (0 != buf->vb.baddr && buf->vb.bsize < size) 251 if (0 != buf->vb.baddr && buf->vb.bsize < size)
243 return -EINVAL; 252 return -EINVAL;
244 253
245 if (STATE_NEEDS_INIT == buf->vb.state) { 254 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
246 buf->vb.width = dev->ts_packet_size; 255 buf->vb.width = dev->ts_packet_size;
247 buf->vb.height = dev->ts_packet_count; 256 buf->vb.height = dev->ts_packet_count;
248 buf->vb.size = size; 257 buf->vb.size = size;
@@ -254,7 +263,7 @@ int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev,
254 dma->sglist, 263 dma->sglist,
255 buf->vb.width, buf->vb.height, 0); 264 buf->vb.width, buf->vb.height, 0);
256 } 265 }
257 buf->vb.state = STATE_PREPARED; 266 buf->vb.state = VIDEOBUF_PREPARED;
258 return 0; 267 return 0;
259 268
260 fail: 269 fail:
@@ -276,7 +285,7 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
276 dprintk( 1, "queue is empty - first active\n" ); 285 dprintk( 1, "queue is empty - first active\n" );
277 list_add_tail(&buf->vb.queue,&cx88q->active); 286 list_add_tail(&buf->vb.queue,&cx88q->active);
278 cx8802_start_dma(dev, cx88q, buf); 287 cx8802_start_dma(dev, cx88q, buf);
279 buf->vb.state = STATE_ACTIVE; 288 buf->vb.state = VIDEOBUF_ACTIVE;
280 buf->count = cx88q->count++; 289 buf->count = cx88q->count++;
281 mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT); 290 mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT);
282 dprintk(1,"[%p/%d] %s - first active\n", 291 dprintk(1,"[%p/%d] %s - first active\n",
@@ -286,7 +295,7 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
286 dprintk( 1, "queue is not empty - append to active\n" ); 295 dprintk( 1, "queue is not empty - append to active\n" );
287 prev = list_entry(cx88q->active.prev, struct cx88_buffer, vb.queue); 296 prev = list_entry(cx88q->active.prev, struct cx88_buffer, vb.queue);
288 list_add_tail(&buf->vb.queue,&cx88q->active); 297 list_add_tail(&buf->vb.queue,&cx88q->active);
289 buf->vb.state = STATE_ACTIVE; 298 buf->vb.state = VIDEOBUF_ACTIVE;
290 buf->count = cx88q->count++; 299 buf->count = cx88q->count++;
291 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 300 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
292 dprintk( 1, "[%p/%d] %s - append to active\n", 301 dprintk( 1, "[%p/%d] %s - append to active\n",
@@ -306,7 +315,7 @@ static void do_cancel_buffers(struct cx8802_dev *dev, char *reason, int restart)
306 while (!list_empty(&q->active)) { 315 while (!list_empty(&q->active)) {
307 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); 316 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
308 list_del(&buf->vb.queue); 317 list_del(&buf->vb.queue);
309 buf->vb.state = STATE_ERROR; 318 buf->vb.state = VIDEOBUF_ERROR;
310 wake_up(&buf->vb.done); 319 wake_up(&buf->vb.done);
311 dprintk(1,"[%p/%d] %s - dma=0x%08lx\n", 320 dprintk(1,"[%p/%d] %s - dma=0x%08lx\n",
312 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma); 321 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma);
@@ -437,10 +446,7 @@ static irqreturn_t cx8802_irq(int irq, void *dev_id)
437 return IRQ_RETVAL(handled); 446 return IRQ_RETVAL(handled);
438} 447}
439 448
440/* ----------------------------------------------------------- */ 449static int cx8802_init_common(struct cx8802_dev *dev)
441/* exported stuff */
442
443int cx8802_init_common(struct cx8802_dev *dev)
444{ 450{
445 struct cx88_core *core = dev->core; 451 struct cx88_core *core = dev->core;
446 int err; 452 int err;
@@ -488,7 +494,7 @@ int cx8802_init_common(struct cx8802_dev *dev)
488 return 0; 494 return 0;
489} 495}
490 496
491void cx8802_fini_common(struct cx8802_dev *dev) 497static void cx8802_fini_common(struct cx8802_dev *dev)
492{ 498{
493 dprintk( 2, "cx8802_fini_common\n" ); 499 dprintk( 2, "cx8802_fini_common\n" );
494 cx8802_stop_dma(dev); 500 cx8802_stop_dma(dev);
@@ -504,7 +510,7 @@ void cx8802_fini_common(struct cx8802_dev *dev)
504 510
505/* ----------------------------------------------------------- */ 511/* ----------------------------------------------------------- */
506 512
507int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state) 513static int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
508{ 514{
509 struct cx8802_dev *dev = pci_get_drvdata(pci_dev); 515 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
510 struct cx88_core *core = dev->core; 516 struct cx88_core *core = dev->core;
@@ -530,7 +536,7 @@ int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
530 return 0; 536 return 0;
531} 537}
532 538
533int cx8802_resume_common(struct pci_dev *pci_dev) 539static int cx8802_resume_common(struct pci_dev *pci_dev)
534{ 540{
535 struct cx8802_dev *dev = pci_get_drvdata(pci_dev); 541 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
536 struct cx88_core *core = dev->core; 542 struct cx88_core *core = dev->core;
@@ -874,9 +880,6 @@ EXPORT_SYMBOL(cx8802_buf_prepare);
874EXPORT_SYMBOL(cx8802_buf_queue); 880EXPORT_SYMBOL(cx8802_buf_queue);
875EXPORT_SYMBOL(cx8802_cancel_buffers); 881EXPORT_SYMBOL(cx8802_cancel_buffers);
876 882
877EXPORT_SYMBOL(cx8802_init_common);
878EXPORT_SYMBOL(cx8802_fini_common);
879
880EXPORT_SYMBOL(cx8802_register_driver); 883EXPORT_SYMBOL(cx8802_register_driver);
881EXPORT_SYMBOL(cx8802_unregister_driver); 884EXPORT_SYMBOL(cx8802_unregister_driver);
882EXPORT_SYMBOL(cx8802_get_driver); 885EXPORT_SYMBOL(cx8802_get_driver);
diff --git a/drivers/media/video/cx88/cx88-vbi.c b/drivers/media/video/cx88/cx88-vbi.c
index babb08556406..d96ecfcf393a 100644
--- a/drivers/media/video/cx88/cx88-vbi.c
+++ b/drivers/media/video/cx88/cx88-vbi.c
@@ -130,7 +130,7 @@ void cx8800_vbi_timeout(unsigned long data)
130 while (!list_empty(&q->active)) { 130 while (!list_empty(&q->active)) {
131 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); 131 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
132 list_del(&buf->vb.queue); 132 list_del(&buf->vb.queue);
133 buf->vb.state = STATE_ERROR; 133 buf->vb.state = VIDEOBUF_ERROR;
134 wake_up(&buf->vb.done); 134 wake_up(&buf->vb.done);
135 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev->core->name, 135 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev->core->name,
136 buf, buf->vb.i, (unsigned long)buf->risc.dma); 136 buf, buf->vb.i, (unsigned long)buf->risc.dma);
@@ -168,7 +168,7 @@ vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
168 if (0 != buf->vb.baddr && buf->vb.bsize < size) 168 if (0 != buf->vb.baddr && buf->vb.bsize < size)
169 return -EINVAL; 169 return -EINVAL;
170 170
171 if (STATE_NEEDS_INIT == buf->vb.state) { 171 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
172 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); 172 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
173 buf->vb.width = VBI_LINE_LENGTH; 173 buf->vb.width = VBI_LINE_LENGTH;
174 buf->vb.height = VBI_LINE_COUNT; 174 buf->vb.height = VBI_LINE_COUNT;
@@ -183,7 +183,7 @@ vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
183 buf->vb.width, 0, 183 buf->vb.width, 0,
184 buf->vb.height); 184 buf->vb.height);
185 } 185 }
186 buf->vb.state = STATE_PREPARED; 186 buf->vb.state = VIDEOBUF_PREPARED;
187 return 0; 187 return 0;
188 188
189 fail: 189 fail:
@@ -207,7 +207,7 @@ vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
207 if (list_empty(&q->active)) { 207 if (list_empty(&q->active)) {
208 list_add_tail(&buf->vb.queue,&q->active); 208 list_add_tail(&buf->vb.queue,&q->active);
209 cx8800_start_vbi_dma(dev, q, buf); 209 cx8800_start_vbi_dma(dev, q, buf);
210 buf->vb.state = STATE_ACTIVE; 210 buf->vb.state = VIDEOBUF_ACTIVE;
211 buf->count = q->count++; 211 buf->count = q->count++;
212 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 212 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
213 dprintk(2,"[%p/%d] vbi_queue - first active\n", 213 dprintk(2,"[%p/%d] vbi_queue - first active\n",
@@ -216,7 +216,7 @@ vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
216 } else { 216 } else {
217 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue); 217 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
218 list_add_tail(&buf->vb.queue,&q->active); 218 list_add_tail(&buf->vb.queue,&q->active);
219 buf->vb.state = STATE_ACTIVE; 219 buf->vb.state = VIDEOBUF_ACTIVE;
220 buf->count = q->count++; 220 buf->count = q->count++;
221 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 221 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
222 dprintk(2,"[%p/%d] buffer_queue - append to active\n", 222 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index c84dafbdb991..7f1931aed207 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -392,13 +392,41 @@ int cx88_video_mux(struct cx88_core *core, unsigned int input)
392 break; 392 break;
393 } 393 }
394 394
395 if (core->board.mpeg & CX88_MPEG_BLACKBIRD) { 395 /* if there are audioroutes defined, we have an external
396 /* sets sound input from external adc */ 396 ADC to deal with audio */
397 if (INPUT(input).extadc) 397
398 if (INPUT(input).audioroute) {
399
400 /* cx2388's C-ADC is connected to the tuner only.
401 When used with S-Video, that ADC is busy dealing with
402 chroma, so an external must be used for baseband audio */
403
404 if (INPUT(input).type != CX88_VMUX_TELEVISION &&
405 INPUT(input).type != CX88_RADIO) {
406 /* "ADC mode" */
407 cx_write(AUD_I2SCNTL, 0x1);
398 cx_set(AUD_CTL, EN_I2SIN_ENABLE); 408 cx_set(AUD_CTL, EN_I2SIN_ENABLE);
399 else 409 } else {
410 /* Normal mode */
411 cx_write(AUD_I2SCNTL, 0x0);
400 cx_clear(AUD_CTL, EN_I2SIN_ENABLE); 412 cx_clear(AUD_CTL, EN_I2SIN_ENABLE);
413 }
414
415 /* The wm8775 module has the "2" route hardwired into
416 the initialization. Some boards may use different
417 routes for different inputs. HVR-1300 surely does */
418 if (core->board.audio_chip &&
419 core->board.audio_chip == AUDIO_CHIP_WM8775) {
420 struct v4l2_routing route;
421
422 route.input = INPUT(input).audioroute;
423 cx88_call_i2c_clients(core,
424 VIDIOC_INT_S_AUDIO_ROUTING, &route);
425
426 }
427
401 } 428 }
429
402 return 0; 430 return 0;
403} 431}
404EXPORT_SYMBOL(cx88_video_mux); 432EXPORT_SYMBOL(cx88_video_mux);
@@ -486,7 +514,7 @@ static int restart_video_queue(struct cx8800_dev *dev,
486 if (NULL == prev) { 514 if (NULL == prev) {
487 list_move_tail(&buf->vb.queue, &q->active); 515 list_move_tail(&buf->vb.queue, &q->active);
488 start_video_dma(dev, q, buf); 516 start_video_dma(dev, q, buf);
489 buf->vb.state = STATE_ACTIVE; 517 buf->vb.state = VIDEOBUF_ACTIVE;
490 buf->count = q->count++; 518 buf->count = q->count++;
491 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 519 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
492 dprintk(2,"[%p/%d] restart_queue - first active\n", 520 dprintk(2,"[%p/%d] restart_queue - first active\n",
@@ -496,7 +524,7 @@ static int restart_video_queue(struct cx8800_dev *dev,
496 prev->vb.height == buf->vb.height && 524 prev->vb.height == buf->vb.height &&
497 prev->fmt == buf->fmt) { 525 prev->fmt == buf->fmt) {
498 list_move_tail(&buf->vb.queue, &q->active); 526 list_move_tail(&buf->vb.queue, &q->active);
499 buf->vb.state = STATE_ACTIVE; 527 buf->vb.state = VIDEOBUF_ACTIVE;
500 buf->count = q->count++; 528 buf->count = q->count++;
501 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 529 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
502 dprintk(2,"[%p/%d] restart_queue - move to active\n", 530 dprintk(2,"[%p/%d] restart_queue - move to active\n",
@@ -553,7 +581,7 @@ buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
553 init_buffer = 1; 581 init_buffer = 1;
554 } 582 }
555 583
556 if (STATE_NEEDS_INIT == buf->vb.state) { 584 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
557 init_buffer = 1; 585 init_buffer = 1;
558 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) 586 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
559 goto fail; 587 goto fail;
@@ -601,7 +629,7 @@ buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
601 fh->width, fh->height, fh->fmt->depth, fh->fmt->name, 629 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
602 (unsigned long)buf->risc.dma); 630 (unsigned long)buf->risc.dma);
603 631
604 buf->vb.state = STATE_PREPARED; 632 buf->vb.state = VIDEOBUF_PREPARED;
605 return 0; 633 return 0;
606 634
607 fail: 635 fail:
@@ -625,14 +653,14 @@ buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
625 653
626 if (!list_empty(&q->queued)) { 654 if (!list_empty(&q->queued)) {
627 list_add_tail(&buf->vb.queue,&q->queued); 655 list_add_tail(&buf->vb.queue,&q->queued);
628 buf->vb.state = STATE_QUEUED; 656 buf->vb.state = VIDEOBUF_QUEUED;
629 dprintk(2,"[%p/%d] buffer_queue - append to queued\n", 657 dprintk(2,"[%p/%d] buffer_queue - append to queued\n",
630 buf, buf->vb.i); 658 buf, buf->vb.i);
631 659
632 } else if (list_empty(&q->active)) { 660 } else if (list_empty(&q->active)) {
633 list_add_tail(&buf->vb.queue,&q->active); 661 list_add_tail(&buf->vb.queue,&q->active);
634 start_video_dma(dev, q, buf); 662 start_video_dma(dev, q, buf);
635 buf->vb.state = STATE_ACTIVE; 663 buf->vb.state = VIDEOBUF_ACTIVE;
636 buf->count = q->count++; 664 buf->count = q->count++;
637 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 665 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
638 dprintk(2,"[%p/%d] buffer_queue - first active\n", 666 dprintk(2,"[%p/%d] buffer_queue - first active\n",
@@ -644,7 +672,7 @@ buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
644 prev->vb.height == buf->vb.height && 672 prev->vb.height == buf->vb.height &&
645 prev->fmt == buf->fmt) { 673 prev->fmt == buf->fmt) {
646 list_add_tail(&buf->vb.queue,&q->active); 674 list_add_tail(&buf->vb.queue,&q->active);
647 buf->vb.state = STATE_ACTIVE; 675 buf->vb.state = VIDEOBUF_ACTIVE;
648 buf->count = q->count++; 676 buf->count = q->count++;
649 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 677 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
650 dprintk(2,"[%p/%d] buffer_queue - append to active\n", 678 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
@@ -652,7 +680,7 @@ buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
652 680
653 } else { 681 } else {
654 list_add_tail(&buf->vb.queue,&q->queued); 682 list_add_tail(&buf->vb.queue,&q->queued);
655 buf->vb.state = STATE_QUEUED; 683 buf->vb.state = VIDEOBUF_QUEUED;
656 dprintk(2,"[%p/%d] buffer_queue - first queued\n", 684 dprintk(2,"[%p/%d] buffer_queue - first queued\n",
657 buf, buf->vb.i); 685 buf, buf->vb.i);
658 } 686 }
@@ -822,8 +850,8 @@ video_poll(struct file *file, struct poll_table_struct *wait)
822 return POLLERR; 850 return POLLERR;
823 } 851 }
824 poll_wait(file, &buf->vb.done, wait); 852 poll_wait(file, &buf->vb.done, wait);
825 if (buf->vb.state == STATE_DONE || 853 if (buf->vb.state == VIDEOBUF_DONE ||
826 buf->vb.state == STATE_ERROR) 854 buf->vb.state == VIDEOBUF_ERROR)
827 return POLLIN|POLLRDNORM; 855 return POLLIN|POLLRDNORM;
828 return 0; 856 return 0;
829} 857}
@@ -1496,7 +1524,7 @@ static void cx8800_vid_timeout(unsigned long data)
1496 while (!list_empty(&q->active)) { 1524 while (!list_empty(&q->active)) {
1497 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); 1525 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
1498 list_del(&buf->vb.queue); 1526 list_del(&buf->vb.queue);
1499 buf->vb.state = STATE_ERROR; 1527 buf->vb.state = VIDEOBUF_ERROR;
1500 wake_up(&buf->vb.done); 1528 wake_up(&buf->vb.done);
1501 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name, 1529 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name,
1502 buf, buf->vb.i, (unsigned long)buf->risc.dma); 1530 buf, buf->vb.i, (unsigned long)buf->risc.dma);
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index eb296bdecb1e..4e823f2a539a 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -210,6 +210,7 @@ extern struct sram_channel cx88_sram_channels[];
210#define CX88_BOARD_TE_DTV_250_OEM_SWANN 55 210#define CX88_BOARD_TE_DTV_250_OEM_SWANN 55
211#define CX88_BOARD_HAUPPAUGE_HVR1300 56 211#define CX88_BOARD_HAUPPAUGE_HVR1300 56
212#define CX88_BOARD_ADSTECH_PTV_390 57 212#define CX88_BOARD_ADSTECH_PTV_390 57
213#define CX88_BOARD_PINNACLE_PCTV_HD_800i 58
213 214
214enum cx88_itype { 215enum cx88_itype {
215 CX88_VMUX_COMPOSITE1 = 1, 216 CX88_VMUX_COMPOSITE1 = 1,
@@ -228,7 +229,7 @@ struct cx88_input {
228 enum cx88_itype type; 229 enum cx88_itype type;
229 u32 gpio0, gpio1, gpio2, gpio3; 230 u32 gpio0, gpio1, gpio2, gpio3;
230 unsigned int vmux:2; 231 unsigned int vmux:2;
231 unsigned int extadc:1; 232 unsigned int audioroute:2;
232}; 233};
233 234
234struct cx88_board { 235struct cx88_board {
@@ -461,6 +462,7 @@ struct cx8802_dev {
461 u32 mailbox; 462 u32 mailbox;
462 int width; 463 int width;
463 int height; 464 int height;
465 unsigned char mpeg_active; /* nonzero if mpeg encoder is active */
464 466
465 /* mpeg params */ 467 /* mpeg params */
466 struct cx2341x_mpeg_params params; 468 struct cx2341x_mpeg_params params;
@@ -588,6 +590,7 @@ extern void cx88_call_i2c_clients(struct cx88_core *core,
588/* ----------------------------------------------------------- */ 590/* ----------------------------------------------------------- */
589/* cx88-cards.c */ 591/* cx88-cards.c */
590 592
593extern int cx88_tuner_callback(void *dev, int command, int arg);
591extern int cx88_get_resources(const struct cx88_core *core, 594extern int cx88_get_resources(const struct cx88_core *core,
592 struct pci_dev *pci); 595 struct pci_dev *pci);
593extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr); 596extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr);
@@ -633,12 +636,6 @@ int cx8802_buf_prepare(struct videobuf_queue *q,struct cx8802_dev *dev,
633void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf); 636void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf);
634void cx8802_cancel_buffers(struct cx8802_dev *dev); 637void cx8802_cancel_buffers(struct cx8802_dev *dev);
635 638
636int cx8802_init_common(struct cx8802_dev *dev);
637void cx8802_fini_common(struct cx8802_dev *dev);
638
639int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state);
640int cx8802_resume_common(struct pci_dev *pci_dev);
641
642/* ----------------------------------------------------------- */ 639/* ----------------------------------------------------------- */
643/* cx88-video.c*/ 640/* cx88-video.c*/
644extern const u32 cx88_user_ctrls[]; 641extern const u32 cx88_user_ctrls[];
diff --git a/drivers/media/video/em28xx/Kconfig b/drivers/media/video/em28xx/Kconfig
index c1127802ad9c..abbd38c1ebba 100644
--- a/drivers/media/video/em28xx/Kconfig
+++ b/drivers/media/video/em28xx/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_EM28XX 1config VIDEO_EM28XX
2 tristate "Empia EM2800/2820/2840 USB video capture support" 2 tristate "Empia EM2800/2820/2840 USB video capture support"
3 depends on VIDEO_V4L1 && I2C && INPUT 3 depends on VIDEO_DEV && I2C && INPUT
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 select VIDEO_IR 6 select VIDEO_IR
@@ -11,3 +11,18 @@ config VIDEO_EM28XX
11 11
12 To compile this driver as a module, choose M here: the 12 To compile this driver as a module, choose M here: the
13 module will be called em28xx 13 module will be called em28xx
14
15config VIDEO_EM28XX_ALSA
16 depends on VIDEO_EM28XX
17 tristate "Empia EM28xx ALSA audio module"
18 ---help---
19 This is an ALSA driver for some Empia 28xx based TV cards.
20
21 This is not required for em2800/em2820/em2821 boards. However,
22 newer em28xx devices uses Vendor Class for audio, instead of
23 implementing the USB Audio Class. For those chips, this module
24 will enable digital audio.
25
26 To compile this driver as a module, choose M here: the
27 module will be called em28xx-alsa
28
diff --git a/drivers/media/video/em28xx/Makefile b/drivers/media/video/em28xx/Makefile
index 826d0e340753..0924550992d0 100644
--- a/drivers/media/video/em28xx/Makefile
+++ b/drivers/media/video/em28xx/Makefile
@@ -1,6 +1,12 @@
1em28xx-objs := em28xx-video.o em28xx-i2c.o em28xx-cards.o em28xx-core.o \ 1em28xx-objs := em28xx-video.o em28xx-i2c.o em28xx-cards.o em28xx-core.o \
2 em28xx-input.o 2 em28xx-input.o
3 3
4em28xx-alsa-objs := em28xx-audio.o
5
4obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o 6obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o
7obj-$(CONFIG_VIDEO_EM28XX_ALSA) += em28xx-alsa.o
5 8
6EXTRA_CFLAGS += -Idrivers/media/video 9EXTRA_CFLAGS += -Idrivers/media/video
10EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
11EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
12
diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
new file mode 100644
index 000000000000..941357c4f3f5
--- /dev/null
+++ b/drivers/media/video/em28xx/em28xx-audio.c
@@ -0,0 +1,489 @@
1/*
2 * Empiatech em28x1 audio extension
3 *
4 * Copyright (C) 2006 Markus Rechberger <mrechberger@gmail.com>
5 *
6 * Copyright (C) 2007 Mauro Carvalho Chehab <mchehab@infradead.org>
7 * - Port to work with the in-kernel driver
8 * - Several cleanups
9 *
10 * This driver is based on my previous au600 usb pstn audio driver
11 * and inherits all the copyrights
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#include <linux/kernel.h>
29#include <linux/usb.h>
30#include <linux/init.h>
31#include <linux/sound.h>
32#include <linux/spinlock.h>
33#include <linux/soundcard.h>
34#include <linux/slab.h>
35#include <linux/vmalloc.h>
36#include <linux/proc_fs.h>
37#include <linux/module.h>
38#include <sound/driver.h>
39#include <sound/core.h>
40#include <sound/pcm.h>
41#include <sound/pcm_params.h>
42#include <sound/info.h>
43#include <sound/initval.h>
44#include <sound/control.h>
45#include <media/v4l2-common.h>
46#include "em28xx.h"
47
48static int debug;
49module_param(debug, int, 0644);
50MODULE_PARM_DESC(debug, "activates debug info");
51
52#define dprintk(fmt, arg...) do { \
53 if (debug) \
54 printk(KERN_INFO "em28xx-audio %s: " fmt, \
55 __FUNCTION__, ##arg); \
56 } while (0)
57
58static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
59
60static int em28xx_isoc_audio_deinit(struct em28xx *dev)
61{
62 int i;
63
64 dprintk("Stopping isoc\n");
65 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
66 usb_kill_urb(dev->adev->urb[i]);
67 usb_free_urb(dev->adev->urb[i]);
68 dev->adev->urb[i] = NULL;
69 }
70
71 return 0;
72}
73
74static void em28xx_audio_isocirq(struct urb *urb)
75{
76 struct em28xx *dev = urb->context;
77 int i;
78 unsigned int oldptr;
79 unsigned long flags;
80 int period_elapsed = 0;
81 int status;
82 unsigned char *cp;
83 unsigned int stride;
84 struct snd_pcm_substream *substream;
85 struct snd_pcm_runtime *runtime;
86 if (dev->adev->capture_pcm_substream) {
87 substream = dev->adev->capture_pcm_substream;
88 runtime = substream->runtime;
89 stride = runtime->frame_bits >> 3;
90
91 for (i = 0; i < urb->number_of_packets; i++) {
92 int length =
93 urb->iso_frame_desc[i].actual_length / stride;
94 cp = (unsigned char *)urb->transfer_buffer +
95 urb->iso_frame_desc[i].offset;
96
97 if (!length)
98 continue;
99
100 spin_lock_irqsave(&dev->adev->slock, flags);
101
102 oldptr = dev->adev->hwptr_done_capture;
103 dev->adev->hwptr_done_capture += length;
104 if (dev->adev->hwptr_done_capture >=
105 runtime->buffer_size)
106 dev->adev->hwptr_done_capture -=
107 runtime->buffer_size;
108
109 dev->adev->capture_transfer_done += length;
110 if (dev->adev->capture_transfer_done >=
111 runtime->period_size) {
112 dev->adev->capture_transfer_done -=
113 runtime->period_size;
114 period_elapsed = 1;
115 }
116
117 spin_unlock_irqrestore(&dev->adev->slock, flags);
118
119 if (oldptr + length >= runtime->buffer_size) {
120 unsigned int cnt =
121 runtime->buffer_size - oldptr - 1;
122 memcpy(runtime->dma_area + oldptr * stride, cp,
123 cnt * stride);
124 memcpy(runtime->dma_area, cp + cnt,
125 length * stride - cnt * stride);
126 } else {
127 memcpy(runtime->dma_area + oldptr * stride, cp,
128 length * stride);
129 }
130 }
131 if (period_elapsed)
132 snd_pcm_period_elapsed(substream);
133 }
134 urb->status = 0;
135
136 if (dev->adev->shutdown)
137 return;
138
139 status = usb_submit_urb(urb, GFP_ATOMIC);
140 if (status < 0) {
141 em28xx_errdev("resubmit of audio urb failed (error=%i)\n",
142 status);
143 }
144 return;
145}
146
147static int em28xx_init_audio_isoc(struct em28xx *dev)
148{
149 int i, errCode;
150 const int sb_size = EM28XX_NUM_AUDIO_PACKETS *
151 EM28XX_AUDIO_MAX_PACKET_SIZE;
152
153 dprintk("Starting isoc transfers\n");
154
155 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
156 struct urb *urb;
157 int j, k;
158
159 dev->adev->transfer_buffer[i] = kmalloc(sb_size, GFP_ATOMIC);
160 if (!dev->adev->transfer_buffer[i])
161 return -ENOMEM;
162
163 memset(dev->adev->transfer_buffer[i], 0x80, sb_size);
164 urb = usb_alloc_urb(EM28XX_NUM_AUDIO_PACKETS, GFP_ATOMIC);
165 if (!urb)
166 return -ENOMEM;
167
168 urb->dev = dev->udev;
169 urb->context = dev;
170 urb->pipe = usb_rcvisocpipe(dev->udev, 0x83);
171 urb->transfer_flags = URB_ISO_ASAP;
172 urb->transfer_buffer = dev->adev->transfer_buffer[i];
173 urb->interval = 1;
174 urb->complete = em28xx_audio_isocirq;
175 urb->number_of_packets = EM28XX_NUM_AUDIO_PACKETS;
176 urb->transfer_buffer_length = sb_size;
177
178 for (j = k = 0; j < EM28XX_NUM_AUDIO_PACKETS;
179 j++, k += EM28XX_AUDIO_MAX_PACKET_SIZE) {
180 urb->iso_frame_desc[j].offset = k;
181 urb->iso_frame_desc[j].length =
182 EM28XX_AUDIO_MAX_PACKET_SIZE;
183 }
184 dev->adev->urb[i] = urb;
185 }
186
187 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
188 errCode = usb_submit_urb(dev->adev->urb[i], GFP_ATOMIC);
189 if (errCode) {
190 em28xx_isoc_audio_deinit(dev);
191
192 return errCode;
193 }
194 }
195
196 return 0;
197}
198
199static int em28xx_cmd(struct em28xx *dev, int cmd, int arg)
200{
201 dprintk("%s transfer\n", (dev->adev->capture_stream == STREAM_ON)?
202 "stop" : "start");
203
204 switch (cmd) {
205 case EM28XX_CAPTURE_STREAM_EN:
206 if (dev->adev->capture_stream == STREAM_OFF && arg == 1) {
207 dev->adev->capture_stream = STREAM_ON;
208 em28xx_init_audio_isoc(dev);
209 } else if (dev->adev->capture_stream == STREAM_ON && arg == 0) {
210 dev->adev->capture_stream = STREAM_OFF;
211 em28xx_isoc_audio_deinit(dev);
212 } else {
213 printk(KERN_ERR "An underrun very likely occurred. "
214 "Ignoring it.\n");
215 }
216 return 0;
217 default:
218 return -EINVAL;
219 }
220}
221
222static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
223 size_t size)
224{
225 struct snd_pcm_runtime *runtime = subs->runtime;
226
227 dprintk("Alocating vbuffer\n");
228 if (runtime->dma_area) {
229 if (runtime->dma_bytes > size)
230 return 0;
231
232 vfree(runtime->dma_area);
233 }
234 runtime->dma_area = vmalloc(size);
235 if (!runtime->dma_area)
236 return -ENOMEM;
237
238 runtime->dma_bytes = size;
239
240 return 0;
241}
242
243static struct snd_pcm_hardware snd_em28xx_hw_capture = {
244 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
245 SNDRV_PCM_INFO_MMAP |
246 SNDRV_PCM_INFO_INTERLEAVED |
247 SNDRV_PCM_INFO_MMAP_VALID,
248
249 .formats = SNDRV_PCM_FMTBIT_S16_LE,
250
251 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_KNOT,
252
253 .rate_min = 48000,
254 .rate_max = 48000,
255 .channels_min = 2,
256 .channels_max = 2,
257 .buffer_bytes_max = 62720 * 8, /* just about the value in usbaudio.c */
258 .period_bytes_min = 64, /* 12544/2, */
259 .period_bytes_max = 12544,
260 .periods_min = 2,
261 .periods_max = 98, /* 12544, */
262};
263
264static int snd_em28xx_capture_open(struct snd_pcm_substream *substream)
265{
266 struct em28xx *dev = snd_pcm_substream_chip(substream);
267 struct snd_pcm_runtime *runtime = substream->runtime;
268 int ret = 0;
269
270 dprintk("opening device and trying to acquire exclusive lock\n");
271
272 /* Sets volume, mute, etc */
273 dev->mute = 0;
274 ret = em28xx_audio_analog_set(dev);
275 if (ret < 0)
276 goto err;
277
278 runtime->hw = snd_em28xx_hw_capture;
279 if (dev->alt == 0 && dev->adev->users == 0) {
280 int errCode;
281 dev->alt = 7;
282 errCode = usb_set_interface(dev->udev, 0, 7);
283 dprintk("changing alternate number to 7\n");
284 }
285
286 dev->adev->users++;
287
288 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
289 dev->adev->capture_pcm_substream = substream;
290 runtime->private_data = dev;
291
292 return 0;
293err:
294 printk(KERN_ERR "Error while configuring em28xx mixer\n");
295 return ret;
296}
297
298static int snd_em28xx_pcm_close(struct snd_pcm_substream *substream)
299{
300 struct em28xx *dev = snd_pcm_substream_chip(substream);
301 dev->adev->users--;
302
303 dprintk("closing device\n");
304
305 dev->mute = 1;
306 em28xx_audio_analog_set(dev);
307
308 if (dev->adev->users == 0 && dev->adev->shutdown == 1) {
309 dprintk("audio users: %d\n", dev->adev->users);
310 dprintk("disabling audio stream!\n");
311 dev->adev->shutdown = 0;
312 dprintk("released lock\n");
313 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, 0);
314 }
315 return 0;
316}
317
318static int snd_em28xx_hw_capture_params(struct snd_pcm_substream *substream,
319 struct snd_pcm_hw_params *hw_params)
320{
321 unsigned int channels, rate, format;
322 int ret;
323
324 dprintk("Setting capture parameters\n");
325
326 ret = snd_pcm_alloc_vmalloc_buffer(substream,
327 params_buffer_bytes(hw_params));
328 format = params_format(hw_params);
329 rate = params_rate(hw_params);
330 channels = params_channels(hw_params);
331
332 /* TODO: set up em28xx audio chip to deliver the correct audio format,
333 current default is 48000hz multiplexed => 96000hz mono
334 which shouldn't matter since analogue TV only supports mono */
335 return 0;
336}
337
338static int snd_em28xx_hw_capture_free(struct snd_pcm_substream *substream)
339{
340 struct em28xx *dev = snd_pcm_substream_chip(substream);
341
342 dprintk("Stop capture, if needed\n");
343
344 if (dev->adev->capture_stream == STREAM_ON)
345 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, 0);
346
347 return 0;
348}
349
350static int snd_em28xx_prepare(struct snd_pcm_substream *substream)
351{
352 return 0;
353}
354
355static int snd_em28xx_capture_trigger(struct snd_pcm_substream *substream,
356 int cmd)
357{
358 struct em28xx *dev = snd_pcm_substream_chip(substream);
359
360 dprintk("Should %s capture\n", (cmd == SNDRV_PCM_TRIGGER_START)?
361 "start": "stop");
362 switch (cmd) {
363 case SNDRV_PCM_TRIGGER_START:
364 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, 1);
365 return 0;
366 case SNDRV_PCM_TRIGGER_STOP:
367 dev->adev->shutdown = 1;
368 return 0;
369 default:
370 return -EINVAL;
371 }
372}
373
374static snd_pcm_uframes_t snd_em28xx_capture_pointer(struct snd_pcm_substream
375 *substream)
376{
377 struct em28xx *dev;
378
379 snd_pcm_uframes_t hwptr_done;
380 dev = snd_pcm_substream_chip(substream);
381 hwptr_done = dev->adev->hwptr_done_capture;
382
383 return hwptr_done;
384}
385
386static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
387 unsigned long offset)
388{
389 void *pageptr = subs->runtime->dma_area + offset;
390
391 return vmalloc_to_page(pageptr);
392}
393
394static struct snd_pcm_ops snd_em28xx_pcm_capture = {
395 .open = snd_em28xx_capture_open,
396 .close = snd_em28xx_pcm_close,
397 .ioctl = snd_pcm_lib_ioctl,
398 .hw_params = snd_em28xx_hw_capture_params,
399 .hw_free = snd_em28xx_hw_capture_free,
400 .prepare = snd_em28xx_prepare,
401 .trigger = snd_em28xx_capture_trigger,
402 .pointer = snd_em28xx_capture_pointer,
403 .page = snd_pcm_get_vmalloc_page,
404};
405
406static int em28xx_audio_init(struct em28xx *dev)
407{
408 struct em28xx_audio *adev;
409 struct snd_pcm *pcm;
410 struct snd_card *card;
411 static int devnr;
412 int ret, err;
413
414 printk(KERN_INFO "em28xx-audio.c: probing for em28x1 "
415 "non standard usbaudio\n");
416 printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2006 Markus "
417 "Rechberger\n");
418
419 adev = kzalloc(sizeof(*adev), GFP_KERNEL);
420 if (!adev) {
421 printk(KERN_ERR "em28xx-audio.c: out of memory\n");
422 return -1;
423 }
424 card = snd_card_new(index[devnr], "Em28xx Audio", THIS_MODULE, 0);
425 if (card == NULL) {
426 kfree(adev);
427 return -ENOMEM;
428 }
429
430 spin_lock_init(&adev->slock);
431 ret = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm);
432 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_em28xx_pcm_capture);
433 pcm->info_flags = 0;
434 pcm->private_data = dev;
435 strcpy(pcm->name, "Empia 28xx Capture");
436 strcpy(card->driver, "Empia Em28xx Audio");
437 strcpy(card->shortname, "Em28xx Audio");
438 strcpy(card->longname, "Empia Em28xx Audio");
439
440 err = snd_card_register(card);
441 if (err < 0) {
442 snd_card_free(card);
443 return -ENOMEM;
444 }
445 adev->sndcard = card;
446 adev->udev = dev->udev;
447 dev->adev = adev;
448
449 return 0;
450}
451
452static int em28xx_audio_fini(struct em28xx *dev)
453{
454 if (dev == NULL)
455 return 0;
456
457 if (dev->adev) {
458 snd_card_free(dev->adev->sndcard);
459 kfree(dev->adev);
460 dev->adev = NULL;
461 }
462
463 return 0;
464}
465
466static struct em28xx_ops audio_ops = {
467 .id = EM28XX_AUDIO,
468 .name = "Em28xx Audio Extension",
469 .init = em28xx_audio_init,
470 .fini = em28xx_audio_fini,
471};
472
473static int __init em28xx_alsa_register(void)
474{
475 return em28xx_register_extension(&audio_ops);
476}
477
478static void __exit em28xx_alsa_unregister(void)
479{
480 em28xx_unregister_extension(&audio_ops);
481}
482
483MODULE_LICENSE("GPL");
484MODULE_AUTHOR("Markus Rechberger <mrechberger@gmail.com>");
485MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
486MODULE_DESCRIPTION("Em28xx Audio driver");
487
488module_init(em28xx_alsa_register);
489module_exit(em28xx_alsa_unregister);
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 418ea8b7f85a..2159d0160df2 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -1,5 +1,6 @@
1/* 1/*
2 em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB video capture devices 2 em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB
3 video capture devices
3 4
4 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> 5 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
5 Markus Rechberger <mrechberger@gmail.com> 6 Markus Rechberger <mrechberger@gmail.com>
@@ -35,294 +36,735 @@
35#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
36 37
37#include "em28xx.h" 38#include "em28xx.h"
39#include "tuner-xc2028.h"
40
41static int tuner = -1;
42module_param(tuner, int, 0444);
43MODULE_PARM_DESC(tuner, "tuner type");
44
45static unsigned int disable_ir;
46module_param(disable_ir, int, 0444);
47MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
48
49struct em28xx_hash_table {
50 unsigned long hash;
51 unsigned int model;
52 unsigned int tuner;
53};
54
55/* Boards supported by driver */
56
57#define EM2800_BOARD_UNKNOWN 0
58#define EM2820_BOARD_UNKNOWN 1
59#define EM2820_BOARD_TERRATEC_CINERGY_250 2
60#define EM2820_BOARD_PINNACLE_USB_2 3
61#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
62#define EM2820_BOARD_MSI_VOX_USB_2 5
63#define EM2800_BOARD_TERRATEC_CINERGY_200 6
64#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
65#define EM2800_BOARD_KWORLD_USB2800 8
66#define EM2820_BOARD_PINNACLE_DVC_90 9
67#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
68#define EM2880_BOARD_TERRATEC_HYBRID_XS 11
69#define EM2820_BOARD_KWORLD_PVRTV2800RF 12
70#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
71#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
72#define EM2800_BOARD_VGEAR_POCKETTV 15
73#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 16
38 74
39struct em28xx_board em28xx_boards[] = { 75struct em28xx_board em28xx_boards[] = {
40 [EM2800_BOARD_UNKNOWN] = { 76 [EM2800_BOARD_UNKNOWN] = {
41 .name = "Unknown EM2800 video grabber", 77 .name = "Unknown EM2800 video grabber",
42 .is_em2800 = 1, 78 .is_em2800 = 1,
43 .vchannels = 2, 79 .vchannels = 2,
44 .norm = VIDEO_MODE_PAL,
45 .tda9887_conf = TDA9887_PRESENT, 80 .tda9887_conf = TDA9887_PRESENT,
46 .has_tuner = 1,
47 .decoder = EM28XX_SAA7113, 81 .decoder = EM28XX_SAA7113,
48 .input = {{ 82 .input = { {
49 .type = EM28XX_VMUX_COMPOSITE1, 83 .type = EM28XX_VMUX_COMPOSITE1,
50 .vmux = SAA7115_COMPOSITE0, 84 .vmux = SAA7115_COMPOSITE0,
51 .amux = 1, 85 .amux = 1,
52 },{ 86 }, {
53 .type = EM28XX_VMUX_SVIDEO, 87 .type = EM28XX_VMUX_SVIDEO,
54 .vmux = SAA7115_SVIDEO3, 88 .vmux = SAA7115_SVIDEO3,
55 .amux = 1, 89 .amux = 1,
56 }}, 90 } },
57 }, 91 },
58 [EM2820_BOARD_UNKNOWN] = { 92 [EM2820_BOARD_UNKNOWN] = {
59 .name = "Unknown EM2820/2840 video grabber", 93 .name = "Unknown EM2750/28xx video grabber",
60 .is_em2800 = 0, 94 .is_em2800 = 0,
61 .vchannels = 2, 95 .tuner_type = TUNER_ABSENT,
62 .norm = VIDEO_MODE_PAL,
63 .tda9887_conf = TDA9887_PRESENT,
64 .has_tuner = 1,
65 .decoder = EM28XX_SAA7113,
66 .input = {{
67 .type = EM28XX_VMUX_COMPOSITE1,
68 .vmux = SAA7115_COMPOSITE0,
69 .amux = 1,
70 },{
71 .type = EM28XX_VMUX_SVIDEO,
72 .vmux = SAA7115_SVIDEO3,
73 .amux = 1,
74 }},
75 }, 96 },
76 [EM2820_BOARD_KWORLD_PVRTV2800RF] = { 97 [EM2820_BOARD_KWORLD_PVRTV2800RF] = {
77 .name = "Kworld PVR TV 2800 RF", 98 .name = "Kworld PVR TV 2800 RF",
78 .is_em2800 = 0, 99 .is_em2800 = 0,
79 .vchannels = 2, 100 .vchannels = 2,
80 .norm = VIDEO_MODE_PAL, 101 .tuner_type = TUNER_TEMIC_PAL,
81 .tda9887_conf = TDA9887_PRESENT, 102 .tda9887_conf = TDA9887_PRESENT,
82 .has_tuner = 1,
83 .decoder = EM28XX_SAA7113, 103 .decoder = EM28XX_SAA7113,
84 .input = {{ 104 .input = { {
85 .type = EM28XX_VMUX_COMPOSITE1, 105 .type = EM28XX_VMUX_COMPOSITE1,
86 .vmux = SAA7115_COMPOSITE0, 106 .vmux = SAA7115_COMPOSITE0,
87 .amux = 1, 107 .amux = 1,
88 },{ 108 }, {
89 .type = EM28XX_VMUX_SVIDEO, 109 .type = EM28XX_VMUX_SVIDEO,
90 .vmux = SAA7115_SVIDEO3, 110 .vmux = SAA7115_SVIDEO3,
91 .amux = 1, 111 .amux = 1,
92 }}, 112 } },
93 }, 113 },
94 [EM2820_BOARD_TERRATEC_CINERGY_250] = { 114 [EM2820_BOARD_TERRATEC_CINERGY_250] = {
95 .name = "Terratec Cinergy 250 USB", 115 .name = "Terratec Cinergy 250 USB",
96 .vchannels = 3, 116 .vchannels = 3,
97 .norm = VIDEO_MODE_PAL,
98 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 117 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
99 .tda9887_conf = TDA9887_PRESENT, 118 .tda9887_conf = TDA9887_PRESENT,
100 .has_tuner = 1,
101 .decoder = EM28XX_SAA7113, 119 .decoder = EM28XX_SAA7113,
102 .input = {{ 120 .input = { {
103 .type = EM28XX_VMUX_TELEVISION, 121 .type = EM28XX_VMUX_TELEVISION,
104 .vmux = SAA7115_COMPOSITE2, 122 .vmux = SAA7115_COMPOSITE2,
105 .amux = 1, 123 .amux = 1,
106 },{ 124 }, {
107 .type = EM28XX_VMUX_COMPOSITE1, 125 .type = EM28XX_VMUX_COMPOSITE1,
108 .vmux = SAA7115_COMPOSITE0, 126 .vmux = SAA7115_COMPOSITE0,
109 .amux = 1, 127 .amux = 1,
110 },{ 128 }, {
111 .type = EM28XX_VMUX_SVIDEO, 129 .type = EM28XX_VMUX_SVIDEO,
112 .vmux = SAA7115_SVIDEO3, 130 .vmux = SAA7115_SVIDEO3,
113 .amux = 1, 131 .amux = 1,
114 }}, 132 } },
115 }, 133 },
116 [EM2820_BOARD_PINNACLE_USB_2] = { 134 [EM2820_BOARD_PINNACLE_USB_2] = {
117 .name = "Pinnacle PCTV USB 2", 135 .name = "Pinnacle PCTV USB 2",
118 .vchannels = 3, 136 .vchannels = 3,
119 .norm = VIDEO_MODE_PAL,
120 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 137 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
121 .tda9887_conf = TDA9887_PRESENT, 138 .tda9887_conf = TDA9887_PRESENT,
122 .has_tuner = 1,
123 .decoder = EM28XX_SAA7113, 139 .decoder = EM28XX_SAA7113,
124 .input = {{ 140 .input = { {
125 .type = EM28XX_VMUX_TELEVISION, 141 .type = EM28XX_VMUX_TELEVISION,
126 .vmux = SAA7115_COMPOSITE2, 142 .vmux = SAA7115_COMPOSITE2,
127 .amux = 0, 143 .amux = 0,
128 },{ 144 }, {
129 .type = EM28XX_VMUX_COMPOSITE1, 145 .type = EM28XX_VMUX_COMPOSITE1,
130 .vmux = SAA7115_COMPOSITE0, 146 .vmux = SAA7115_COMPOSITE0,
131 .amux = 1, 147 .amux = 1,
132 },{ 148 }, {
133 .type = EM28XX_VMUX_SVIDEO, 149 .type = EM28XX_VMUX_SVIDEO,
134 .vmux = SAA7115_SVIDEO3, 150 .vmux = SAA7115_SVIDEO3,
135 .amux = 1, 151 .amux = 1,
136 }}, 152 } },
137 }, 153 },
138 [EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = { 154 [EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = {
139 .name = "Hauppauge WinTV USB 2", 155 .name = "Hauppauge WinTV USB 2",
140 .vchannels = 3, 156 .vchannels = 3,
141 .norm = VIDEO_MODE_NTSC,
142 .tuner_type = TUNER_PHILIPS_FM1236_MK3, 157 .tuner_type = TUNER_PHILIPS_FM1236_MK3,
143 .tda9887_conf = TDA9887_PRESENT|TDA9887_PORT1_ACTIVE|TDA9887_PORT2_ACTIVE, 158 .tda9887_conf = TDA9887_PRESENT |
144 .has_tuner = 1, 159 TDA9887_PORT1_ACTIVE|
160 TDA9887_PORT2_ACTIVE,
145 .decoder = EM28XX_TVP5150, 161 .decoder = EM28XX_TVP5150,
146 .has_msp34xx = 1, 162 .has_msp34xx = 1,
147 /*FIXME: S-Video not tested */ 163 /*FIXME: S-Video not tested */
148 .input = {{ 164 .input = { {
149 .type = EM28XX_VMUX_TELEVISION, 165 .type = EM28XX_VMUX_TELEVISION,
150 .vmux = TVP5150_COMPOSITE0, 166 .vmux = TVP5150_COMPOSITE0,
151 .amux = MSP_INPUT_DEFAULT, 167 .amux = MSP_INPUT_DEFAULT,
152 },{ 168 }, {
153 .type = EM28XX_VMUX_SVIDEO, 169 .type = EM28XX_VMUX_SVIDEO,
154 .vmux = TVP5150_SVIDEO, 170 .vmux = TVP5150_SVIDEO,
155 .amux = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1, 171 .amux = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
156 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART), 172 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
157 }}, 173 } },
158 }, 174 },
159 [EM2820_BOARD_MSI_VOX_USB_2] = { 175 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
160 .name = "MSI VOX USB 2.0", 176 .name = "Hauppauge WinTV HVR 900",
161 .vchannels = 3, 177 .vchannels = 3,
162 .norm = VIDEO_MODE_PAL, 178 .tda9887_conf = TDA9887_PRESENT,
163 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 179 .tuner_type = TUNER_XC2028,
164 .tda9887_conf = TDA9887_PRESENT|TDA9887_PORT1_ACTIVE|TDA9887_PORT2_ACTIVE, 180 .mts_firmware = 1,
165 .has_tuner = 1, 181 .decoder = EM28XX_TVP5150,
166 .decoder = EM28XX_SAA7114, 182 .input = { {
167 .input = {{ 183 .type = EM28XX_VMUX_TELEVISION,
184 .vmux = TVP5150_COMPOSITE0,
185 .amux = 0,
186 }, {
187 .type = EM28XX_VMUX_COMPOSITE1,
188 .vmux = TVP5150_COMPOSITE1,
189 .amux = 1,
190 }, {
191 .type = EM28XX_VMUX_SVIDEO,
192 .vmux = TVP5150_SVIDEO,
193 .amux = 1,
194 } },
195 },
196 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
197 .name = "Hauppauge WinTV HVR 950",
198 .vchannels = 3,
199 .tda9887_conf = TDA9887_PRESENT,
200 .tuner_type = TUNER_XC2028,
201 .mts_firmware = 1,
202 .has_12mhz_i2s = 1,
203 .decoder = EM28XX_TVP5150,
204 .input = { {
168 .type = EM28XX_VMUX_TELEVISION, 205 .type = EM28XX_VMUX_TELEVISION,
169 .vmux = SAA7115_COMPOSITE4, 206 .vmux = TVP5150_COMPOSITE0,
170 .amux = 0, 207 .amux = 0,
171 },{ 208 }, {
172 .type = EM28XX_VMUX_COMPOSITE1, 209 .type = EM28XX_VMUX_COMPOSITE1,
173 .vmux = SAA7115_COMPOSITE0, 210 .vmux = TVP5150_COMPOSITE1,
174 .amux = 1, 211 .amux = 1,
175 },{ 212 }, {
176 .type = EM28XX_VMUX_SVIDEO, 213 .type = EM28XX_VMUX_SVIDEO,
177 .vmux = SAA7115_SVIDEO3, 214 .vmux = TVP5150_SVIDEO,
178 .amux = 1, 215 .amux = 1,
179 }}, 216 } },
217
218 /* gpio's 4, 1, 0 */
219 .analog_gpio = 0x003d2d,
220 },
221 [EM2880_BOARD_TERRATEC_HYBRID_XS] = {
222 .name = "Terratec Hybrid XS",
223 .vchannels = 3,
224 .tda9887_conf = TDA9887_PRESENT,
225 .tuner_type = TUNER_XC2028,
226 .decoder = EM28XX_TVP5150,
227 .input = { {
228 .type = EM28XX_VMUX_TELEVISION,
229 .vmux = TVP5150_COMPOSITE0,
230 .amux = 0,
231 }, {
232 .type = EM28XX_VMUX_COMPOSITE1,
233 .vmux = TVP5150_COMPOSITE1,
234 .amux = 1,
235 }, {
236 .type = EM28XX_VMUX_SVIDEO,
237 .vmux = TVP5150_SVIDEO,
238 .amux = 1,
239 } },
240 },
241 /* maybe there's a reason behind it why Terratec sells the Hybrid XS
242 as Prodigy XS with a different PID, let's keep it separated for now
243 maybe we'll need it lateron */
244 [EM2880_BOARD_TERRATEC_PRODIGY_XS] = {
245 .name = "Terratec Prodigy XS",
246 .vchannels = 3,
247 .tda9887_conf = TDA9887_PRESENT,
248 .tuner_type = TUNER_XC2028,
249 .decoder = EM28XX_TVP5150,
250 .input = { {
251 .type = EM28XX_VMUX_TELEVISION,
252 .vmux = TVP5150_COMPOSITE0,
253 .amux = 0,
254 }, {
255 .type = EM28XX_VMUX_COMPOSITE1,
256 .vmux = TVP5150_COMPOSITE1,
257 .amux = 1,
258 }, {
259 .type = EM28XX_VMUX_SVIDEO,
260 .vmux = TVP5150_SVIDEO,
261 .amux = 1,
262 } },
263 },
264 [EM2820_BOARD_MSI_VOX_USB_2] = {
265 .name = "MSI VOX USB 2.0",
266 .vchannels = 3,
267 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
268 .tda9887_conf = TDA9887_PRESENT |
269 TDA9887_PORT1_ACTIVE |
270 TDA9887_PORT2_ACTIVE,
271 .max_range_640_480 = 1,
272
273 .decoder = EM28XX_SAA7114,
274 .input = { {
275 .type = EM28XX_VMUX_TELEVISION,
276 .vmux = SAA7115_COMPOSITE4,
277 .amux = 0,
278 }, {
279 .type = EM28XX_VMUX_COMPOSITE1,
280 .vmux = SAA7115_COMPOSITE0,
281 .amux = 1,
282 }, {
283 .type = EM28XX_VMUX_SVIDEO,
284 .vmux = SAA7115_SVIDEO3,
285 .amux = 1,
286 } },
180 }, 287 },
181 [EM2800_BOARD_TERRATEC_CINERGY_200] = { 288 [EM2800_BOARD_TERRATEC_CINERGY_200] = {
182 .name = "Terratec Cinergy 200 USB", 289 .name = "Terratec Cinergy 200 USB",
183 .is_em2800 = 1, 290 .is_em2800 = 1,
184 .vchannels = 3, 291 .vchannels = 3,
185 .norm = VIDEO_MODE_PAL,
186 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 292 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
187 .tda9887_conf = TDA9887_PRESENT, 293 .tda9887_conf = TDA9887_PRESENT,
188 .has_tuner = 1,
189 .decoder = EM28XX_SAA7113, 294 .decoder = EM28XX_SAA7113,
190 .input = {{ 295 .input = { {
191 .type = EM28XX_VMUX_TELEVISION, 296 .type = EM28XX_VMUX_TELEVISION,
192 .vmux = SAA7115_COMPOSITE2, 297 .vmux = SAA7115_COMPOSITE2,
193 .amux = 0, 298 .amux = 0,
194 },{ 299 }, {
195 .type = EM28XX_VMUX_COMPOSITE1, 300 .type = EM28XX_VMUX_COMPOSITE1,
196 .vmux = SAA7115_COMPOSITE0, 301 .vmux = SAA7115_COMPOSITE0,
197 .amux = 1, 302 .amux = 1,
198 },{ 303 }, {
199 .type = EM28XX_VMUX_SVIDEO, 304 .type = EM28XX_VMUX_SVIDEO,
200 .vmux = SAA7115_SVIDEO3, 305 .vmux = SAA7115_SVIDEO3,
201 .amux = 1, 306 .amux = 1,
202 }}, 307 } },
203 }, 308 },
204 [EM2800_BOARD_LEADTEK_WINFAST_USBII] = { 309 [EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
205 .name = "Leadtek Winfast USB II", 310 .name = "Leadtek Winfast USB II",
206 .is_em2800 = 1, 311 .is_em2800 = 1,
207 .vchannels = 3, 312 .vchannels = 3,
208 .norm = VIDEO_MODE_PAL,
209 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 313 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
210 .tda9887_conf = TDA9887_PRESENT, 314 .tda9887_conf = TDA9887_PRESENT,
211 .has_tuner = 1,
212 .decoder = EM28XX_SAA7113, 315 .decoder = EM28XX_SAA7113,
213 .input = {{ 316 .input = { {
214 .type = EM28XX_VMUX_TELEVISION, 317 .type = EM28XX_VMUX_TELEVISION,
215 .vmux = SAA7115_COMPOSITE2, 318 .vmux = SAA7115_COMPOSITE2,
216 .amux = 0, 319 .amux = 0,
217 },{ 320 }, {
218 .type = EM28XX_VMUX_COMPOSITE1, 321 .type = EM28XX_VMUX_COMPOSITE1,
219 .vmux = SAA7115_COMPOSITE0, 322 .vmux = SAA7115_COMPOSITE0,
220 .amux = 1, 323 .amux = 1,
221 },{ 324 }, {
222 .type = EM28XX_VMUX_SVIDEO, 325 .type = EM28XX_VMUX_SVIDEO,
223 .vmux = SAA7115_SVIDEO3, 326 .vmux = SAA7115_SVIDEO3,
224 .amux = 1, 327 .amux = 1,
225 }}, 328 } },
226 }, 329 },
227 [EM2800_BOARD_KWORLD_USB2800] = { 330 [EM2800_BOARD_KWORLD_USB2800] = {
228 .name = "Kworld USB2800", 331 .name = "Kworld USB2800",
229 .is_em2800 = 1, 332 .is_em2800 = 1,
230 .vchannels = 3, 333 .vchannels = 3,
231 .norm = VIDEO_MODE_PAL,
232 .tuner_type = TUNER_PHILIPS_ATSC, 334 .tuner_type = TUNER_PHILIPS_ATSC,
233 .tda9887_conf = TDA9887_PRESENT, 335 .tda9887_conf = TDA9887_PRESENT,
234 .has_tuner = 1,
235 .decoder = EM28XX_SAA7113, 336 .decoder = EM28XX_SAA7113,
236 .input = {{ 337 .input = { {
237 .type = EM28XX_VMUX_TELEVISION, 338 .type = EM28XX_VMUX_TELEVISION,
238 .vmux = SAA7115_COMPOSITE2, 339 .vmux = SAA7115_COMPOSITE2,
239 .amux = 0, 340 .amux = 0,
240 },{ 341 }, {
241 .type = EM28XX_VMUX_COMPOSITE1, 342 .type = EM28XX_VMUX_COMPOSITE1,
242 .vmux = SAA7115_COMPOSITE0, 343 .vmux = SAA7115_COMPOSITE0,
243 .amux = 1, 344 .amux = 1,
244 },{ 345 }, {
245 .type = EM28XX_VMUX_SVIDEO, 346 .type = EM28XX_VMUX_SVIDEO,
246 .vmux = SAA7115_SVIDEO3, 347 .vmux = SAA7115_SVIDEO3,
247 .amux = 1, 348 .amux = 1,
248 }}, 349 } },
249 }, 350 },
250 [EM2820_BOARD_PINNACLE_DVC_90] = { 351 [EM2820_BOARD_PINNACLE_DVC_90] = {
251 .name = "Pinnacle Dazzle DVC 90", 352 .name = "Pinnacle Dazzle DVC 90/DVC 100",
353 .vchannels = 3,
354 .tuner_type = TUNER_ABSENT,
355 .decoder = EM28XX_SAA7113,
356 .input = { {
357 .type = EM28XX_VMUX_COMPOSITE1,
358 .vmux = SAA7115_COMPOSITE0,
359 .amux = 1,
360 }, {
361 .type = EM28XX_VMUX_SVIDEO,
362 .vmux = SAA7115_SVIDEO3,
363 .amux = 1,
364 } },
365 },
366 [EM2800_BOARD_VGEAR_POCKETTV] = {
367 .name = "V-Gear PocketTV",
368 .is_em2800 = 1,
369 .vchannels = 3,
370 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
371 .tda9887_conf = TDA9887_PRESENT,
372 .decoder = EM28XX_SAA7113,
373 .input = { {
374 .type = EM28XX_VMUX_TELEVISION,
375 .vmux = SAA7115_COMPOSITE2,
376 .amux = 0,
377 }, {
378 .type = EM28XX_VMUX_COMPOSITE1,
379 .vmux = SAA7115_COMPOSITE0,
380 .amux = 1,
381 }, {
382 .type = EM28XX_VMUX_SVIDEO,
383 .vmux = SAA7115_SVIDEO3,
384 .amux = 1,
385 } },
386 },
387 [EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
388 .name = "Pixelview Prolink PlayTV USB 2.0",
252 .vchannels = 3, 389 .vchannels = 3,
253 .norm = VIDEO_MODE_PAL, 390 .tda9887_conf = TDA9887_PRESENT,
254 .has_tuner = 0, 391 .tuner_type = TUNER_YMEC_TVF_5533MF,
255 .decoder = EM28XX_SAA7113, 392 .decoder = EM28XX_SAA7113,
256 .input = {{ 393 .input = { {
394 .type = EM28XX_VMUX_TELEVISION,
395 .vmux = SAA7115_COMPOSITE2,
396 .amux = 1,
397 }, {
257 .type = EM28XX_VMUX_COMPOSITE1, 398 .type = EM28XX_VMUX_COMPOSITE1,
258 .vmux = SAA7115_COMPOSITE0, 399 .vmux = SAA7115_COMPOSITE0,
259 .amux = 1, 400 .amux = 1,
260 },{ 401 }, {
261 .type = EM28XX_VMUX_SVIDEO, 402 .type = EM28XX_VMUX_SVIDEO,
262 .vmux = SAA7115_SVIDEO3, 403 .vmux = SAA7115_SVIDEO3,
263 .amux = 1, 404 .amux = 1,
264 }}, 405 } },
265 }, 406 },
266}; 407};
267const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards); 408const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
268 409
269/* table of devices that work with this driver */ 410/* table of devices that work with this driver */
270struct usb_device_id em28xx_id_table [] = { 411struct usb_device_id em28xx_id_table [] = {
271 { USB_DEVICE(0xeb1a, 0x2800), .driver_info = EM2800_BOARD_UNKNOWN }, 412 { USB_DEVICE(0xeb1a, 0x2750),
272 { USB_DEVICE(0xeb1a, 0x2820), .driver_info = EM2820_BOARD_MSI_VOX_USB_2 }, 413 .driver_info = EM2820_BOARD_UNKNOWN },
273 { USB_DEVICE(0x0ccd, 0x0036), .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 }, 414 { USB_DEVICE(0xeb1a, 0x2800),
274 { USB_DEVICE(0x2304, 0x0208), .driver_info = EM2820_BOARD_PINNACLE_USB_2 }, 415 .driver_info = EM2800_BOARD_UNKNOWN },
275 { USB_DEVICE(0x2040, 0x4200), .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 }, 416 { USB_DEVICE(0xeb1a, 0x2820),
276 { USB_DEVICE(0x2304, 0x0207), .driver_info = EM2820_BOARD_PINNACLE_DVC_90 }, 417 .driver_info = EM2820_BOARD_UNKNOWN },
418 { USB_DEVICE(0xeb1a, 0x2821),
419 .driver_info = EM2820_BOARD_UNKNOWN },
420 { USB_DEVICE(0xeb1a, 0x2860),
421 .driver_info = EM2820_BOARD_UNKNOWN },
422 { USB_DEVICE(0xeb1a, 0x2861),
423 .driver_info = EM2820_BOARD_UNKNOWN },
424 { USB_DEVICE(0xeb1a, 0x2870),
425 .driver_info = EM2820_BOARD_UNKNOWN },
426 { USB_DEVICE(0xeb1a, 0x2881),
427 .driver_info = EM2820_BOARD_UNKNOWN },
428 { USB_DEVICE(0xeb1a, 0x2883),
429 .driver_info = EM2820_BOARD_UNKNOWN },
430 { USB_DEVICE(0x0ccd, 0x0036),
431 .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
432 { USB_DEVICE(0x2304, 0x0208),
433 .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
434 { USB_DEVICE(0x2040, 0x4200),
435 .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
436 { USB_DEVICE(0x2040, 0x4201),
437 .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
438 { USB_DEVICE(0x2304, 0x0207),
439 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
440 { USB_DEVICE(0x2304, 0x021a),
441 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
442 { USB_DEVICE(0x2040, 0x6500),
443 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
444 { USB_DEVICE(0x2040, 0x6513),
445 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
446 { USB_DEVICE(0x0ccd, 0x0042),
447 .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
448 { USB_DEVICE(0x0ccd, 0x0047),
449 .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
277 { }, 450 { },
278}; 451};
452MODULE_DEVICE_TABLE(usb, em28xx_id_table);
453
454/* EEPROM hash table for devices with generic USB IDs */
455static struct em28xx_hash_table em28xx_eeprom_hash [] = {
456 /* P/N: SA 60002070465 Tuner: TVF7533-MF */
457 {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
458};
459
460/* I2C devicelist hash table for devices with generic USB IDs */
461static struct em28xx_hash_table em28xx_i2c_hash[] = {
462 {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
463 {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
464};
279 465
466/* Since em28xx_pre_card_setup() requires a proper dev->model,
467 * this won't work for boards with generic PCI IDs
468 */
280void em28xx_pre_card_setup(struct em28xx *dev) 469void em28xx_pre_card_setup(struct em28xx *dev)
281{ 470{
282 /* request some modules */ 471 /* request some modules */
283 switch(dev->model){ 472 switch (dev->model) {
284 case EM2880_BOARD_TERRATEC_PRODIGY_XS: 473 case EM2880_BOARD_TERRATEC_PRODIGY_XS:
285 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: 474 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
286 case EM2880_BOARD_TERRATEC_HYBRID_XS: 475 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
287 { 476 case EM2880_BOARD_TERRATEC_HYBRID_XS:
288 em28xx_write_regs_req(dev, 0x00, 0x08, "\x7d", 1); // reset through GPIO? 477 em28xx_write_regs(dev, XCLK_REG, "\x27", 1);
289 break; 478 em28xx_write_regs(dev, I2C_CLK_REG, "\x40", 1);
479 em28xx_write_regs(dev, 0x08, "\xff", 1);
480 em28xx_write_regs(dev, 0x04, "\x00", 1);
481 msleep(100);
482 em28xx_write_regs(dev, 0x04, "\x08", 1);
483 msleep(100);
484 em28xx_write_regs(dev, 0x08, "\xff", 1);
485 msleep(50);
486 em28xx_write_regs(dev, 0x08, "\x2d", 1);
487 msleep(50);
488 em28xx_write_regs(dev, 0x08, "\x3d", 1);
489 break;
490 }
491}
492
493static int em28xx_tuner_callback(void *ptr, int command, int arg)
494{
495 int rc = 0;
496 struct em28xx *dev = ptr;
497
498 if (dev->tuner_type != TUNER_XC2028)
499 return 0;
500
501 switch (command) {
502 case XC2028_TUNER_RESET:
503 {
504 /* GPIO and initialization codes for analog TV and radio
505 This code should be complemented for DTV, since reset
506 codes are different.
507 */
508
509 dev->em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1);
510 dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x67", 1);
511
512 if (dev->analog_gpio) {
513 char gpio0 = dev->analog_gpio & 0xff;
514 char gpio1 = (dev->analog_gpio >> 8) & 0xff;
515 char gpio4 = dev->analog_gpio >> 24;
516
517 if (gpio4) {
518 dev->em28xx_write_regs(dev, 0x04, &gpio4, 1);
519 msleep(140);
290 } 520 }
521
522 msleep(6);
523 dev->em28xx_write_regs(dev, 0x08, &gpio0, 1);
524 msleep(10);
525 dev->em28xx_write_regs(dev, 0x08, &gpio1, 1);
526 msleep(5);
527 }
528
529 break;
530 }
531 }
532 return rc;
533}
534
535static void em28xx_config_tuner(struct em28xx *dev)
536{
537 struct v4l2_priv_tun_config xc2028_cfg;
538 struct xc2028_ctrl ctl;
539 struct tuner_setup tun_setup;
540 struct v4l2_frequency f;
541
542 if (dev->tuner_type == TUNER_ABSENT)
543 return;
544
545 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
546 tun_setup.type = dev->tuner_type;
547 tun_setup.addr = dev->tuner_addr;
548 tun_setup.tuner_callback = em28xx_tuner_callback;
549
550 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
551
552 if (dev->tuner_type == TUNER_XC2028) {
553 memset(&ctl, 0, sizeof(ctl));
554
555 ctl.fname = XC2028_DEFAULT_FIRMWARE;
556 ctl.max_len = 64;
557 ctl.mts = em28xx_boards[dev->model].mts_firmware;
558
559 xc2028_cfg.tuner = TUNER_XC2028;
560 xc2028_cfg.priv = &ctl;
561
562 em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
563 }
564
565 /* configure tuner */
566 f.tuner = 0;
567 f.type = V4L2_TUNER_ANALOG_TV;
568 f.frequency = 9076; /* just a magic number */
569 dev->ctl_freq = f.frequency;
570 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
571}
572
573static int em28xx_hint_board(struct em28xx *dev)
574{
575 int i;
576
577 /* HINT method: EEPROM
578 *
579 * This method works only for boards with eeprom.
580 * Uses a hash of all eeprom bytes. The hash should be
581 * unique for a vendor/tuner pair.
582 * There are a high chance that tuners for different
583 * video standards produce different hashes.
584 */
585 for (i = 0; i < ARRAY_SIZE(em28xx_eeprom_hash); i++) {
586 if (dev->hash == em28xx_eeprom_hash[i].hash) {
587 dev->model = em28xx_eeprom_hash[i].model;
588 dev->tuner_type = em28xx_eeprom_hash[i].tuner;
589
590 em28xx_errdev("Your board has no unique USB ID.\n");
591 em28xx_errdev("A hint were successfully done, "
592 "based on eeprom hash.\n");
593 em28xx_errdev("This method is not 100%% failproof.\n");
594 em28xx_errdev("If the board were missdetected, "
595 "please email this log to:\n");
596 em28xx_errdev("\tV4L Mailing List "
597 " <video4linux-list@redhat.com>\n");
598 em28xx_errdev("Board detected as %s\n",
599 em28xx_boards[dev->model].name);
600
601 return 0;
602 }
603 }
604
605 /* HINT method: I2C attached devices
606 *
607 * This method works for all boards.
608 * Uses a hash of i2c scanned devices.
609 * Devices with the same i2c attached chips will
610 * be considered equal.
611 * This method is less precise than the eeprom one.
612 */
613
614 /* user did not request i2c scanning => do it now */
615 if (!dev->i2c_hash)
616 em28xx_do_i2c_scan(dev);
617
618 for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
619 if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
620 dev->model = em28xx_i2c_hash[i].model;
621 dev->tuner_type = em28xx_i2c_hash[i].tuner;
622 em28xx_errdev("Your board has no unique USB ID.\n");
623 em28xx_errdev("A hint were successfully done, "
624 "based on i2c devicelist hash.\n");
625 em28xx_errdev("This method is not 100%% failproof.\n");
626 em28xx_errdev("If the board were missdetected, "
627 "please email this log to:\n");
628 em28xx_errdev("\tV4L Mailing List "
629 " <video4linux-list@redhat.com>\n");
630 em28xx_errdev("Board detected as %s\n",
631 em28xx_boards[dev->model].name);
632
633 return 0;
634 }
635 }
636
637 em28xx_errdev("Your board has no unique USB ID and thus need a "
638 "hint to be detected.\n");
639 em28xx_errdev("You may try to use card=<n> insmod option to "
640 "workaround that.\n");
641 em28xx_errdev("Please send an email with this log to:\n");
642 em28xx_errdev("\tV4L Mailing List <video4linux-list@redhat.com>\n");
643 em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
644 em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
645
646 em28xx_errdev("Here is a list of valid choices for the card=<n>"
647 " insmod option:\n");
648 for (i = 0; i < em28xx_bcount; i++) {
649 em28xx_errdev(" card=%d -> %s\n",
650 i, em28xx_boards[i].name);
651 }
652 return -1;
653}
654
655
656static void em28xx_set_model(struct em28xx *dev)
657{
658 dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
659 dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx;
660 dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
661 dev->decoder = em28xx_boards[dev->model].decoder;
662 dev->video_inputs = em28xx_boards[dev->model].vchannels;
663 dev->analog_gpio = em28xx_boards[dev->model].analog_gpio;
664 dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s;
665 dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480;
666}
667
668/* ----------------------------------------------------------------------- */
669void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir)
670{
671 if (disable_ir) {
672 ir->get_key = NULL;
673 return ;
674 }
675
676 /* detect & configure */
677 switch (dev->model) {
678 case (EM2800_BOARD_UNKNOWN):
679 break;
680 case (EM2820_BOARD_UNKNOWN):
681 break;
682 case (EM2800_BOARD_TERRATEC_CINERGY_200):
683 case (EM2820_BOARD_TERRATEC_CINERGY_250):
684 ir->ir_codes = ir_codes_em_terratec;
685 ir->get_key = em28xx_get_key_terratec;
686 snprintf(ir->c.name, sizeof(ir->c.name),
687 "i2c IR (EM28XX Terratec)");
688 break;
689 case (EM2820_BOARD_PINNACLE_USB_2):
690 ir->ir_codes = ir_codes_pinnacle_grey;
691 ir->get_key = em28xx_get_key_pinnacle_usb_grey;
692 snprintf(ir->c.name, sizeof(ir->c.name),
693 "i2c IR (EM28XX Pinnacle PCTV)");
694 break;
695 case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
696 ir->ir_codes = ir_codes_hauppauge_new;
697 ir->get_key = em28xx_get_key_em_haup;
698 snprintf(ir->c.name, sizeof(ir->c.name),
699 "i2c IR (EM2840 Hauppauge)");
700 break;
701 case (EM2820_BOARD_MSI_VOX_USB_2):
702 break;
703 case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
704 break;
705 case (EM2800_BOARD_KWORLD_USB2800):
706 break;
291 } 707 }
292} 708}
293 709
294void em28xx_card_setup(struct em28xx *dev) 710void em28xx_card_setup(struct em28xx *dev)
295{ 711{
712 em28xx_set_model(dev);
713
714 dev->tuner_type = em28xx_boards[dev->model].tuner_type;
715
296 /* request some modules */ 716 /* request some modules */
297 switch(dev->model){ 717 switch (dev->model) {
298 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2: 718 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
299 { 719 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
300 struct tveeprom tv; 720 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
721 {
722 struct tveeprom tv;
301#ifdef CONFIG_MODULES 723#ifdef CONFIG_MODULES
302 request_module("tveeprom"); 724 request_module("tveeprom");
303 request_module("ir-kbd-i2c");
304 request_module("msp3400");
305#endif 725#endif
306 /* Call first TVeeprom */ 726 /* Call first TVeeprom */
307 727
308 dev->i2c_client.addr = 0xa0 >> 1; 728 dev->i2c_client.addr = 0xa0 >> 1;
309 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata); 729 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
310
311 dev->tuner_type= tv.tuner_type;
312 if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
313 dev->i2s_speed=2048000;
314 dev->has_msp34xx=1;
315 } else
316 dev->has_msp34xx=0;
317 break;
318 }
319 case EM2820_BOARD_KWORLD_PVRTV2800RF:
320 {
321 em28xx_write_regs_req(dev,0x00,0x08, "\xf9", 1); // GPIO enables sound on KWORLD PVR TV 2800RF
322 break;
323 }
324 730
731 dev->tuner_type = tv.tuner_type;
732
733 if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
734 dev->i2s_speed = 2048000;
735 dev->has_msp34xx = 1;
736 }
737#ifdef CONFIG_MODULES
738 if (tv.has_ir)
739 request_module("ir-kbd-i2c");
740#endif
741 break;
742 }
743 case EM2820_BOARD_KWORLD_PVRTV2800RF:
744 /* GPIO enables sound on KWORLD PVR TV 2800RF */
745 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf9", 1);
746 break;
747 case EM2820_BOARD_UNKNOWN:
748 case EM2800_BOARD_UNKNOWN:
749 if (!em28xx_hint_board(dev))
750 em28xx_set_model(dev);
325 } 751 }
326}
327 752
328MODULE_DEVICE_TABLE (usb, em28xx_id_table); 753 /* Allow override tuner type by a module parameter */
754 if (tuner >= 0)
755 dev->tuner_type = tuner;
756
757#ifdef CONFIG_MODULES
758 /* request some modules */
759 if (dev->has_msp34xx)
760 request_module("msp3400");
761 if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114)
762 request_module("saa7115");
763 if (dev->decoder == EM28XX_TVP5150)
764 request_module("tvp5150");
765 if (dev->tuner_type != TUNER_ABSENT)
766 request_module("tuner");
767#endif
768
769 em28xx_config_tuner(dev);
770}
diff --git a/drivers/media/video/em28xx/em28xx-core.c b/drivers/media/video/em28xx/em28xx-core.c
index d56484f20467..f6b78357f0e5 100644
--- a/drivers/media/video/em28xx/em28xx-core.c
+++ b/drivers/media/video/em28xx/em28xx-core.c
@@ -252,7 +252,7 @@ int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
252 * em28xx_write_ac97() 252 * em28xx_write_ac97()
253 * write a 16 bit value to the specified AC97 address (LSB first!) 253 * write a 16 bit value to the specified AC97 address (LSB first!)
254 */ 254 */
255int em28xx_write_ac97(struct em28xx *dev, u8 reg, u8 * val) 255static int em28xx_write_ac97(struct em28xx *dev, u8 reg, u8 *val)
256{ 256{
257 int ret; 257 int ret;
258 u8 addr = reg & 0x7f; 258 u8 addr = reg & 0x7f;
@@ -268,16 +268,98 @@ int em28xx_write_ac97(struct em28xx *dev, u8 reg, u8 * val)
268 return 0; 268 return 0;
269} 269}
270 270
271int em28xx_set_audio_source(struct em28xx *dev)
272{
273 static char *enable = "\x08\x08";
274 static char *disable = "\x08\x88";
275 char *video = enable, *line = disable;
276 int ret, no_ac97;
277 u8 input;
278
279 if (dev->is_em2800) {
280 if (dev->ctl_ainput)
281 input = EM2800_AUDIO_SRC_LINE;
282 else
283 input = EM2800_AUDIO_SRC_TUNER;
284
285 ret = em28xx_write_regs(dev, EM2800_AUDIOSRC_REG, &input, 1);
286 if (ret < 0)
287 return ret;
288 }
289
290 if (dev->has_msp34xx)
291 input = EM28XX_AUDIO_SRC_TUNER;
292 else {
293 switch (dev->ctl_ainput) {
294 case EM28XX_AMUX_VIDEO:
295 input = EM28XX_AUDIO_SRC_TUNER;
296 no_ac97 = 1;
297 break;
298 case EM28XX_AMUX_LINE_IN:
299 input = EM28XX_AUDIO_SRC_LINE;
300 no_ac97 = 1;
301 break;
302 case EM28XX_AMUX_AC97_VIDEO:
303 input = EM28XX_AUDIO_SRC_LINE;
304 break;
305 case EM28XX_AMUX_AC97_LINE_IN:
306 input = EM28XX_AUDIO_SRC_LINE;
307 video = disable;
308 line = enable;
309 break;
310 }
311 }
312
313 ret = em28xx_write_reg_bits(dev, AUDIOSRC_REG, input, 0xc0);
314 if (ret < 0)
315 return ret;
316
317 if (no_ac97)
318 return 0;
319
320 /* Sets AC97 mixer registers */
321
322 ret = em28xx_write_ac97(dev, VIDEO_AC97, video);
323 if (ret < 0)
324 return ret;
325
326 ret = em28xx_write_ac97(dev, LINE_IN_AC97, line);
327
328 return ret;
329}
330
271int em28xx_audio_analog_set(struct em28xx *dev) 331int em28xx_audio_analog_set(struct em28xx *dev)
272{ 332{
333 int ret;
273 char s[2] = { 0x00, 0x00 }; 334 char s[2] = { 0x00, 0x00 };
335 u8 xclk = 0x07;
336
274 s[0] |= 0x1f - dev->volume; 337 s[0] |= 0x1f - dev->volume;
275 s[1] |= 0x1f - dev->volume; 338 s[1] |= 0x1f - dev->volume;
339
276 if (dev->mute) 340 if (dev->mute)
277 s[1] |= 0x80; 341 s[1] |= 0x80;
278 return em28xx_write_ac97(dev, MASTER_AC97, s); 342 ret = em28xx_write_ac97(dev, MASTER_AC97, s);
279} 343 if (ret < 0)
344 return ret;
345
346 if (dev->has_12mhz_i2s)
347 xclk |= 0x20;
348
349 if (!dev->mute)
350 xclk |= 0x80;
280 351
352 ret = em28xx_write_reg_bits(dev, XCLK_REG, xclk, 0xa7);
353 if (ret < 0)
354 return ret;
355 msleep(10);
356
357 /* Selects the proper audio input */
358 ret = em28xx_set_audio_source(dev);
359
360 return ret;
361}
362EXPORT_SYMBOL_GPL(em28xx_audio_analog_set);
281 363
282int em28xx_colorlevels_set_default(struct em28xx *dev) 364int em28xx_colorlevels_set_default(struct em28xx *dev)
283{ 365{
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index e3a4aa7a9df4..cacd04d46e99 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -25,9 +25,9 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/video_decoder.h>
29 28
30#include "em28xx.h" 29#include "em28xx.h"
30#include "tuner-xc2028.h"
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/tuner.h> 32#include <media/tuner.h>
33 33
@@ -291,6 +291,31 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
291 return rc; 291 return rc;
292} 292}
293 293
294/* based on linux/sunrpc/svcauth.h and linux/hash.h
295 * The original hash function returns a different value, if arch is x86_64
296 * or i386.
297 */
298static inline unsigned long em28xx_hash_mem(char *buf, int length, int bits)
299{
300 unsigned long hash = 0;
301 unsigned long l = 0;
302 int len = 0;
303 unsigned char c;
304 do {
305 if (len == length) {
306 c = (char)len;
307 len = -1;
308 } else
309 c = *buf++;
310 l = (l << 8) | c;
311 len++;
312 if ((len & (32 / 8 - 1)) == 0)
313 hash = ((hash^l) * 0x9e370001UL);
314 } while (len);
315
316 return (hash >> (32 - bits)) & 0xffffffffUL;
317}
318
294static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) 319static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
295{ 320{
296 unsigned char buf, *p = eedata; 321 unsigned char buf, *p = eedata;
@@ -334,7 +359,11 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
334 printk("\n"); 359 printk("\n");
335 } 360 }
336 361
337 printk(KERN_INFO "EEPROM ID= 0x%08x\n", em_eeprom->id); 362 if (em_eeprom->id == 0x9567eb1a)
363 dev->hash = em28xx_hash_mem(eedata, len, 32);
364
365 printk(KERN_INFO "EEPROM ID= 0x%08x, hash = 0x%08lx\n",
366 em_eeprom->id, dev->hash);
338 printk(KERN_INFO "Vendor/Product ID= %04x:%04x\n", em_eeprom->vendor_ID, 367 printk(KERN_INFO "Vendor/Product ID= %04x:%04x\n", em_eeprom->vendor_ID,
339 em_eeprom->product_ID); 368 em_eeprom->product_ID);
340 369
@@ -391,21 +420,6 @@ static u32 functionality(struct i2c_adapter *adap)
391} 420}
392 421
393 422
394static int em28xx_set_tuner(int check_eeprom, struct i2c_client *client)
395{
396 struct em28xx *dev = client->adapter->algo_data;
397 struct tuner_setup tun_setup;
398
399 if (dev->has_tuner) {
400 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
401 tun_setup.type = dev->tuner_type;
402 tun_setup.addr = dev->tuner_addr;
403 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
404 }
405
406 return (0);
407}
408
409/* 423/*
410 * attach_inform() 424 * attach_inform()
411 * gets called when a device attaches to the i2c bus 425 * gets called when a device attaches to the i2c bus
@@ -421,6 +435,8 @@ static int attach_inform(struct i2c_client *client)
421 case 0x96: 435 case 0x96:
422 case 0x94: 436 case 0x94:
423 { 437 {
438 struct v4l2_priv_tun_config tda9887_cfg;
439
424 struct tuner_setup tun_setup; 440 struct tuner_setup tun_setup;
425 441
426 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; 442 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
@@ -428,7 +444,11 @@ static int attach_inform(struct i2c_client *client)
428 tun_setup.addr = client->addr; 444 tun_setup.addr = client->addr;
429 445
430 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); 446 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
431 em28xx_i2c_call_clients(dev, TDA9887_SET_CONFIG, &dev->tda9887_conf); 447
448 tda9887_cfg.tuner = TUNER_TDA9887;
449 tda9887_cfg.priv = &dev->tda9887_conf;
450 em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG,
451 &tda9887_cfg);
432 break; 452 break;
433 } 453 }
434 case 0x42: 454 case 0x42:
@@ -458,9 +478,11 @@ static int attach_inform(struct i2c_client *client)
458 break; 478 break;
459 479
460 default: 480 default:
481 if (!dev->tuner_addr)
482 dev->tuner_addr = client->addr;
483
461 dprintk1(1,"attach inform: detected I2C address %x\n", client->addr << 1); 484 dprintk1(1,"attach inform: detected I2C address %x\n", client->addr << 1);
462 dev->tuner_addr = client->addr; 485
463 em28xx_set_tuner(-1, client);
464 } 486 }
465 487
466 return 0; 488 return 0;
@@ -510,19 +532,26 @@ static char *i2c_devs[128] = {
510 * do_i2c_scan() 532 * do_i2c_scan()
511 * check i2c address range for devices 533 * check i2c address range for devices
512 */ 534 */
513static void do_i2c_scan(char *name, struct i2c_client *c) 535void em28xx_do_i2c_scan(struct em28xx *dev)
514{ 536{
537 u8 i2c_devicelist[128];
515 unsigned char buf; 538 unsigned char buf;
516 int i, rc; 539 int i, rc;
517 540
541 memset(i2c_devicelist, 0, ARRAY_SIZE(i2c_devicelist));
542
518 for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) { 543 for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
519 c->addr = i; 544 dev->i2c_client.addr = i;
520 rc = i2c_master_recv(c, &buf, 0); 545 rc = i2c_master_recv(&dev->i2c_client, &buf, 0);
521 if (rc < 0) 546 if (rc < 0)
522 continue; 547 continue;
523 printk(KERN_INFO "%s: found i2c device @ 0x%x [%s]\n", name, 548 i2c_devicelist[i] = i;
524 i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); 549 printk(KERN_INFO "%s: found i2c device @ 0x%x [%s]\n",
550 dev->name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
525 } 551 }
552
553 dev->i2c_hash = em28xx_hash_mem(i2c_devicelist,
554 ARRAY_SIZE(i2c_devicelist), 32);
526} 555}
527 556
528/* 557/*
@@ -555,7 +584,7 @@ int em28xx_i2c_register(struct em28xx *dev)
555 em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata)); 584 em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
556 585
557 if (i2c_scan) 586 if (i2c_scan)
558 do_i2c_scan(dev->name, &dev->i2c_client); 587 em28xx_do_i2c_scan(dev);
559 return 0; 588 return 0;
560} 589}
561 590
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index e3894b68c4ee..10da2fd8d987 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -30,11 +30,7 @@
30 30
31#include "em28xx.h" 31#include "em28xx.h"
32 32
33static unsigned int disable_ir = 0; 33static unsigned int ir_debug;
34module_param(disable_ir, int, 0444);
35MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
36
37static unsigned int ir_debug = 0;
38module_param(ir_debug, int, 0644); 34module_param(ir_debug, int, 0644);
39MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]"); 35MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
40 36
@@ -43,7 +39,7 @@ MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
43 39
44/* ----------------------------------------------------------------------- */ 40/* ----------------------------------------------------------------------- */
45 41
46static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 42int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
47{ 43{
48 unsigned char b; 44 unsigned char b;
49 45
@@ -72,7 +68,7 @@ static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
72} 68}
73 69
74 70
75static int get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 71int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
76{ 72{
77 unsigned char buf[2]; 73 unsigned char buf[2];
78 unsigned char code; 74 unsigned char code;
@@ -103,7 +99,8 @@ static int get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
103 return 1; 99 return 1;
104} 100}
105 101
106static int get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 102int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
103 u32 *ir_raw)
107{ 104{
108 unsigned char buf[3]; 105 unsigned char buf[3];
109 106
@@ -125,45 +122,6 @@ static int get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw
125 return 1; 122 return 1;
126} 123}
127 124
128/* ----------------------------------------------------------------------- */
129void em28xx_set_ir(struct em28xx * dev,struct IR_i2c *ir)
130{
131 if (disable_ir) {
132 ir->get_key=NULL;
133 return ;
134 }
135
136 /* detect & configure */
137 switch (dev->model) {
138 case (EM2800_BOARD_UNKNOWN):
139 break;
140 case (EM2820_BOARD_UNKNOWN):
141 break;
142 case (EM2800_BOARD_TERRATEC_CINERGY_200):
143 case (EM2820_BOARD_TERRATEC_CINERGY_250):
144 ir->ir_codes = ir_codes_em_terratec;
145 ir->get_key = get_key_terratec;
146 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Terratec)");
147 break;
148 case (EM2820_BOARD_PINNACLE_USB_2):
149 ir->ir_codes = ir_codes_pinnacle_grey;
150 ir->get_key = get_key_pinnacle_usb_grey;
151 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Pinnacle PCTV)");
152 break;
153 case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
154 ir->ir_codes = ir_codes_hauppauge_new;
155 ir->get_key = get_key_em_haup;
156 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM2840 Hauppauge)");
157 break;
158 case (EM2820_BOARD_MSI_VOX_USB_2):
159 break;
160 case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
161 break;
162 case (EM2800_BOARD_KWORLD_USB2800):
163 break;
164 }
165}
166
167/* ---------------------------------------------------------------------- 125/* ----------------------------------------------------------------------
168 * Local variables: 126 * Local variables:
169 * c-basic-offset: 8 127 * c-basic-offset: 8
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 0906bc5766cc..a0c334672488 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -33,13 +33,12 @@
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/version.h> 34#include <linux/version.h>
35#include <linux/mm.h> 35#include <linux/mm.h>
36#include <linux/video_decoder.h>
37#include <linux/mutex.h> 36#include <linux/mutex.h>
38 37
39#include "em28xx.h" 38#include "em28xx.h"
40#include <media/tuner.h>
41#include <media/v4l2-common.h> 39#include <media/v4l2-common.h>
42#include <media/msp3400.h> 40#include <media/msp3400.h>
41#include <media/tuner.h>
43 42
44#define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \ 43#define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \
45 "Markus Rechberger <mrechberger@gmail.com>, " \ 44 "Markus Rechberger <mrechberger@gmail.com>, " \
@@ -48,7 +47,7 @@
48 47
49#define DRIVER_NAME "em28xx" 48#define DRIVER_NAME "em28xx"
50#define DRIVER_DESC "Empia em28xx based USB video device driver" 49#define DRIVER_DESC "Empia em28xx based USB video device driver"
51#define EM28XX_VERSION_CODE KERNEL_VERSION(0, 0, 1) 50#define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 0)
52 51
53#define em28xx_videodbg(fmt, arg...) do {\ 52#define em28xx_videodbg(fmt, arg...) do {\
54 if (video_debug) \ 53 if (video_debug) \
@@ -63,17 +62,17 @@ static LIST_HEAD(em28xx_devlist);
63 62
64static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 63static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
65static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 64static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
66static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 65static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
66static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
67
67module_param_array(card, int, NULL, 0444); 68module_param_array(card, int, NULL, 0444);
68module_param_array(video_nr, int, NULL, 0444); 69module_param_array(video_nr, int, NULL, 0444);
69module_param_array(vbi_nr, int, NULL, 0444); 70module_param_array(vbi_nr, int, NULL, 0444);
70MODULE_PARM_DESC(card,"card type"); 71module_param_array(radio_nr, int, NULL, 0444);
71MODULE_PARM_DESC(video_nr,"video device numbers"); 72MODULE_PARM_DESC(card, "card type");
72MODULE_PARM_DESC(vbi_nr,"vbi device numbers"); 73MODULE_PARM_DESC(video_nr, "video device numbers");
73 74MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
74static int tuner = -1; 75MODULE_PARM_DESC(radio_nr, "radio device numbers");
75module_param(tuner, int, 0444);
76MODULE_PARM_DESC(tuner, "tuner type");
77 76
78static unsigned int video_debug = 0; 77static unsigned int video_debug = 0;
79module_param(video_debug,int,0644); 78module_param(video_debug,int,0644);
@@ -82,29 +81,6 @@ MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
82/* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */ 81/* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */
83static unsigned long em28xx_devused; 82static unsigned long em28xx_devused;
84 83
85/* supported tv norms */
86static struct em28xx_tvnorm tvnorms[] = {
87 {
88 .name = "PAL",
89 .id = V4L2_STD_PAL,
90 .mode = VIDEO_MODE_PAL,
91 }, {
92 .name = "NTSC",
93 .id = V4L2_STD_NTSC,
94 .mode = VIDEO_MODE_NTSC,
95 }, {
96 .name = "SECAM",
97 .id = V4L2_STD_SECAM,
98 .mode = VIDEO_MODE_SECAM,
99 }, {
100 .name = "PAL-M",
101 .id = V4L2_STD_PAL_M,
102 .mode = VIDEO_MODE_PAL,
103 }
104};
105
106#define TVNORMS ARRAY_SIZE(tvnorms)
107
108/* supported controls */ 84/* supported controls */
109/* Common to all boards */ 85/* Common to all boards */
110static struct v4l2_queryctrl em28xx_qctrl[] = { 86static struct v4l2_queryctrl em28xx_qctrl[] = {
@@ -131,8 +107,6 @@ static struct v4l2_queryctrl em28xx_qctrl[] = {
131 107
132static struct usb_driver em28xx_usb_driver; 108static struct usb_driver em28xx_usb_driver;
133 109
134static DEFINE_MUTEX(em28xx_sysfs_lock);
135static DECLARE_RWSEM(em28xx_disconnect);
136 110
137/********************* v4l2 interface ******************************************/ 111/********************* v4l2 interface ******************************************/
138 112
@@ -153,11 +127,9 @@ static int em28xx_config(struct em28xx *dev)
153/* em28xx_write_regs_req(dev,0x00,0x0f,"\x80",1); clk register */ 127/* em28xx_write_regs_req(dev,0x00,0x0f,"\x80",1); clk register */
154 em28xx_write_regs_req(dev,0x00,0x11,"\x51",1); 128 em28xx_write_regs_req(dev,0x00,0x11,"\x51",1);
155 129
156 em28xx_audio_usb_mute(dev, 1);
157 dev->mute = 1; /* maybe not the right place... */ 130 dev->mute = 1; /* maybe not the right place... */
158 dev->volume = 0x1f; 131 dev->volume = 0x1f;
159 em28xx_audio_analog_set(dev); 132
160 em28xx_audio_analog_setup(dev);
161 em28xx_outfmt_set_yuv422(dev); 133 em28xx_outfmt_set_yuv422(dev);
162 em28xx_colorlevels_set_default(dev); 134 em28xx_colorlevels_set_default(dev);
163 em28xx_compression_disable(dev); 135 em28xx_compression_disable(dev);
@@ -171,7 +143,6 @@ static int em28xx_config(struct em28xx *dev)
171 */ 143 */
172static void em28xx_config_i2c(struct em28xx *dev) 144static void em28xx_config_i2c(struct em28xx *dev)
173{ 145{
174 struct v4l2_frequency f;
175 struct v4l2_routing route; 146 struct v4l2_routing route;
176 147
177 route.input = INPUT(dev->ctl_input)->vmux; 148 route.input = INPUT(dev->ctl_input)->vmux;
@@ -179,18 +150,6 @@ static void em28xx_config_i2c(struct em28xx *dev)
179 em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, NULL); 150 em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, NULL);
180 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); 151 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route);
181 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL); 152 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL);
182
183 /* configure tuner */
184 f.tuner = 0;
185 f.type = V4L2_TUNER_ANALOG_TV;
186 f.frequency = 9076; /* FIXME:remove magic number */
187 dev->ctl_freq = f.frequency;
188 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
189
190 /* configure tda9887 */
191
192
193/* em28xx_i2c_call_clients(dev,VIDIOC_S_STD,&dev->tvnorm->id); */
194} 153}
195 154
196/* 155/*
@@ -212,7 +171,6 @@ static void em28xx_empty_framequeues(struct em28xx *dev)
212 171
213static void video_mux(struct em28xx *dev, int index) 172static void video_mux(struct em28xx *dev, int index)
214{ 173{
215 int ainput;
216 struct v4l2_routing route; 174 struct v4l2_routing route;
217 175
218 route.input = INPUT(index)->vmux; 176 route.input = INPUT(index)->vmux;
@@ -222,8 +180,6 @@ static void video_mux(struct em28xx *dev, int index)
222 180
223 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); 181 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route);
224 182
225 em28xx_videodbg("Setting input index=%d, vmux=%d, amux=%d\n",index,route.input,dev->ctl_ainput);
226
227 if (dev->has_msp34xx) { 183 if (dev->has_msp34xx) {
228 if (dev->i2s_speed) 184 if (dev->i2s_speed)
229 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed); 185 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed);
@@ -231,18 +187,1068 @@ static void video_mux(struct em28xx *dev, int index)
231 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); 187 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
232 /* Note: this is msp3400 specific */ 188 /* Note: this is msp3400 specific */
233 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, &route); 189 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, &route);
234 ainput = EM28XX_AUDIO_SRC_TUNER; 190 }
235 em28xx_audio_source(dev, ainput); 191
192 em28xx_set_audio_source(dev);
193}
194
195/* Usage lock check functions */
196static int res_get(struct em28xx_fh *fh)
197{
198 struct em28xx *dev = fh->dev;
199 int rc = 0;
200
201 /* This instance already has stream_on */
202 if (fh->stream_on)
203 return rc;
204
205 mutex_lock(&dev->lock);
206
207 if (dev->stream_on)
208 rc = -EINVAL;
209 else {
210 dev->stream_on = 1;
211 fh->stream_on = 1;
212 }
213
214 mutex_unlock(&dev->lock);
215 return rc;
216}
217
218static int res_check(struct em28xx_fh *fh)
219{
220 return (fh->stream_on);
221}
222
223static void res_free(struct em28xx_fh *fh)
224{
225 struct em28xx *dev = fh->dev;
226
227 mutex_lock(&dev->lock);
228 fh->stream_on = 0;
229 dev->stream_on = 0;
230 mutex_unlock(&dev->lock);
231}
232
233/*
234 * em28xx_vm_open()
235 */
236static void em28xx_vm_open(struct vm_area_struct *vma)
237{
238 struct em28xx_frame_t *f = vma->vm_private_data;
239 f->vma_use_count++;
240}
241
242/*
243 * em28xx_vm_close()
244 */
245static void em28xx_vm_close(struct vm_area_struct *vma)
246{
247 /* NOTE: buffers are not freed here */
248 struct em28xx_frame_t *f = vma->vm_private_data;
249
250 if (f->vma_use_count)
251 f->vma_use_count--;
252}
253
254static struct vm_operations_struct em28xx_vm_ops = {
255 .open = em28xx_vm_open,
256 .close = em28xx_vm_close,
257};
258
259
260/*
261 * em28xx_get_ctrl()
262 * return the current saturation, brightness or contrast, mute state
263 */
264static int em28xx_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
265{
266 switch (ctrl->id) {
267 case V4L2_CID_AUDIO_MUTE:
268 ctrl->value = dev->mute;
269 return 0;
270 case V4L2_CID_AUDIO_VOLUME:
271 ctrl->value = dev->volume;
272 return 0;
273 default:
274 return -EINVAL;
275 }
276}
277
278/*
279 * em28xx_set_ctrl()
280 * mute or set new saturation, brightness or contrast
281 */
282static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
283{
284 switch (ctrl->id) {
285 case V4L2_CID_AUDIO_MUTE:
286 if (ctrl->value != dev->mute) {
287 dev->mute = ctrl->value;
288 return em28xx_audio_analog_set(dev);
289 }
290 return 0;
291 case V4L2_CID_AUDIO_VOLUME:
292 dev->volume = ctrl->value;
293 return em28xx_audio_analog_set(dev);
294 default:
295 return -EINVAL;
296 }
297}
298
299/*
300 * em28xx_stream_interrupt()
301 * stops streaming
302 */
303static int em28xx_stream_interrupt(struct em28xx *dev)
304{
305 int rc = 0;
306
307 /* stop reading from the device */
308
309 dev->stream = STREAM_INTERRUPT;
310 rc = wait_event_timeout(dev->wait_stream,
311 (dev->stream == STREAM_OFF) ||
312 (dev->state & DEV_DISCONNECTED),
313 EM28XX_URB_TIMEOUT);
314
315 if (rc) {
316 dev->state |= DEV_MISCONFIGURED;
317 em28xx_videodbg("device is misconfigured; close and "
318 "open /dev/video%d again\n",
319 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN);
320 return rc;
321 }
322
323 return 0;
324}
325
326
327static int check_dev(struct em28xx *dev)
328{
329 if (dev->state & DEV_DISCONNECTED) {
330 em28xx_errdev("v4l2 ioctl: device not present\n");
331 return -ENODEV;
332 }
333
334 if (dev->state & DEV_MISCONFIGURED) {
335 em28xx_errdev("v4l2 ioctl: device is misconfigured; "
336 "close and open it again\n");
337 return -EIO;
338 }
339 return 0;
340}
341
342static void get_scale(struct em28xx *dev,
343 unsigned int width, unsigned int height,
344 unsigned int *hscale, unsigned int *vscale)
345{
346 unsigned int maxw = norm_maxw(dev);
347 unsigned int maxh = norm_maxh(dev);
348
349 *hscale = (((unsigned long)maxw) << 12) / width - 4096L;
350 if (*hscale >= 0x4000)
351 *hscale = 0x3fff;
352
353 *vscale = (((unsigned long)maxh) << 12) / height - 4096L;
354 if (*vscale >= 0x4000)
355 *vscale = 0x3fff;
356}
357
358/* ------------------------------------------------------------------
359 IOCTL vidioc handling
360 ------------------------------------------------------------------*/
361
362static int vidioc_g_fmt_cap(struct file *file, void *priv,
363 struct v4l2_format *f)
364{
365 struct em28xx_fh *fh = priv;
366 struct em28xx *dev = fh->dev;
367
368 mutex_lock(&dev->lock);
369
370 f->fmt.pix.width = dev->width;
371 f->fmt.pix.height = dev->height;
372 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
373 f->fmt.pix.bytesperline = dev->bytesperline;
374 f->fmt.pix.sizeimage = dev->frame_size;
375 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
376
377 /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
378 f->fmt.pix.field = dev->interlaced ?
379 V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
380
381 mutex_unlock(&dev->lock);
382 return 0;
383}
384
385static int vidioc_try_fmt_cap(struct file *file, void *priv,
386 struct v4l2_format *f)
387{
388 struct em28xx_fh *fh = priv;
389 struct em28xx *dev = fh->dev;
390 int width = f->fmt.pix.width;
391 int height = f->fmt.pix.height;
392 unsigned int maxw = norm_maxw(dev);
393 unsigned int maxh = norm_maxh(dev);
394 unsigned int hscale, vscale;
395
396 /* width must even because of the YUYV format
397 height must be even because of interlacing */
398 height &= 0xfffe;
399 width &= 0xfffe;
400
401 if (height < 32)
402 height = 32;
403 if (height > maxh)
404 height = maxh;
405 if (width < 48)
406 width = 48;
407 if (width > maxw)
408 width = maxw;
409
410 mutex_lock(&dev->lock);
411
412 if (dev->is_em2800) {
413 /* the em2800 can only scale down to 50% */
414 if (height % (maxh / 2))
415 height = maxh;
416 if (width % (maxw / 2))
417 width = maxw;
418 /* according to empiatech support */
419 /* the MaxPacketSize is to small to support */
420 /* framesizes larger than 640x480 @ 30 fps */
421 /* or 640x576 @ 25 fps. As this would cut */
422 /* of a part of the image we prefer */
423 /* 360x576 or 360x480 for now */
424 if (width == maxw && height == maxh)
425 width /= 2;
426 }
427
428 get_scale(dev, width, height, &hscale, &vscale);
429
430 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
431 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
432
433 f->fmt.pix.width = width;
434 f->fmt.pix.height = height;
435 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
436 f->fmt.pix.bytesperline = width * 2;
437 f->fmt.pix.sizeimage = width * 2 * height;
438 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
439 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
440
441 mutex_unlock(&dev->lock);
442 return 0;
443}
444
445static int vidioc_s_fmt_cap(struct file *file, void *priv,
446 struct v4l2_format *f)
447{
448 struct em28xx_fh *fh = priv;
449 struct em28xx *dev = fh->dev;
450 int rc, i;
451
452 rc = check_dev(dev);
453 if (rc < 0)
454 return rc;
455
456 vidioc_try_fmt_cap(file, priv, f);
457
458 mutex_lock(&dev->lock);
459
460 for (i = 0; i < dev->num_frames; i++)
461 if (dev->frame[i].vma_use_count) {
462 em28xx_videodbg("VIDIOC_S_FMT failed. "
463 "Unmap the buffers first.\n");
464 rc = -EINVAL;
465 goto err;
466 }
467
468 /* stop io in case it is already in progress */
469 if (dev->stream == STREAM_ON) {
470 em28xx_videodbg("VIDIOC_SET_FMT: interrupting stream\n");
471 rc = em28xx_stream_interrupt(dev);
472 if (rc < 0)
473 goto err;
474 }
475
476 em28xx_release_buffers(dev);
477 dev->io = IO_NONE;
478
479 /* set new image size */
480 dev->width = f->fmt.pix.width;
481 dev->height = f->fmt.pix.height;
482 dev->frame_size = dev->width * dev->height * 2;
483 dev->field_size = dev->frame_size >> 1;
484 dev->bytesperline = dev->width * 2;
485 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
486
487 /* FIXME: This is really weird! Why capture is starting with
488 this ioctl ???
489 */
490 em28xx_uninit_isoc(dev);
491 em28xx_set_alternate(dev);
492 em28xx_capture_start(dev, 1);
493 em28xx_resolution_set(dev);
494 em28xx_init_isoc(dev);
495 rc = 0;
496
497err:
498 mutex_unlock(&dev->lock);
499 return rc;
500}
501
502static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
503{
504 struct em28xx_fh *fh = priv;
505 struct em28xx *dev = fh->dev;
506 struct v4l2_format f;
507 int rc;
508
509 rc = check_dev(dev);
510 if (rc < 0)
511 return rc;
512
513 mutex_lock(&dev->lock);
514 dev->norm = *norm;
515 mutex_unlock(&dev->lock);
516
517 /* Adjusts width/height, if needed */
518 f.fmt.pix.width = dev->width;
519 f.fmt.pix.height = dev->height;
520 vidioc_try_fmt_cap(file, priv, &f);
521
522 mutex_lock(&dev->lock);
523
524 /* set new image size */
525 dev->width = f.fmt.pix.width;
526 dev->height = f.fmt.pix.height;
527 dev->frame_size = dev->width * dev->height * 2;
528 dev->field_size = dev->frame_size >> 1;
529 dev->bytesperline = dev->width * 2;
530 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
531
532 em28xx_resolution_set(dev);
533 em28xx_i2c_call_clients(dev, VIDIOC_S_STD, &dev->norm);
534
535 mutex_unlock(&dev->lock);
536 return 0;
537}
538
539static const char *iname[] = {
540 [EM28XX_VMUX_COMPOSITE1] = "Composite1",
541 [EM28XX_VMUX_COMPOSITE2] = "Composite2",
542 [EM28XX_VMUX_COMPOSITE3] = "Composite3",
543 [EM28XX_VMUX_COMPOSITE4] = "Composite4",
544 [EM28XX_VMUX_SVIDEO] = "S-Video",
545 [EM28XX_VMUX_TELEVISION] = "Television",
546 [EM28XX_VMUX_CABLE] = "Cable TV",
547 [EM28XX_VMUX_DVB] = "DVB",
548 [EM28XX_VMUX_DEBUG] = "for debug only",
549};
550
551static int vidioc_enum_input(struct file *file, void *priv,
552 struct v4l2_input *i)
553{
554 struct em28xx_fh *fh = priv;
555 struct em28xx *dev = fh->dev;
556 unsigned int n;
557
558 n = i->index;
559 if (n >= MAX_EM28XX_INPUT)
560 return -EINVAL;
561 if (0 == INPUT(n)->type)
562 return -EINVAL;
563
564 i->index = n;
565 i->type = V4L2_INPUT_TYPE_CAMERA;
566
567 strcpy(i->name, iname[INPUT(n)->type]);
568
569 if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) ||
570 (EM28XX_VMUX_CABLE == INPUT(n)->type))
571 i->type = V4L2_INPUT_TYPE_TUNER;
572
573 i->std = dev->vdev->tvnorms;
574
575 return 0;
576}
577
578static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
579{
580 struct em28xx_fh *fh = priv;
581 struct em28xx *dev = fh->dev;
582
583 *i = dev->ctl_input;
584
585 return 0;
586}
587
588static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
589{
590 struct em28xx_fh *fh = priv;
591 struct em28xx *dev = fh->dev;
592 int rc;
593
594 rc = check_dev(dev);
595 if (rc < 0)
596 return rc;
597
598 if (i >= MAX_EM28XX_INPUT)
599 return -EINVAL;
600 if (0 == INPUT(i)->type)
601 return -EINVAL;
602
603 mutex_lock(&dev->lock);
604
605 video_mux(dev, i);
606
607 mutex_unlock(&dev->lock);
608 return 0;
609}
610
611static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
612{
613 struct em28xx_fh *fh = priv;
614 struct em28xx *dev = fh->dev;
615 unsigned int index = a->index;
616
617 if (a->index > 1)
618 return -EINVAL;
619
620 index = dev->ctl_ainput;
621
622 if (index == 0) {
623 strcpy(a->name, "Television");
236 } else { 624 } else {
237 switch (dev->ctl_ainput) { 625 strcpy(a->name, "Line In");
238 case 0: 626 }
239 ainput = EM28XX_AUDIO_SRC_TUNER; 627 a->capability = V4L2_AUDCAP_STEREO;
628 a->index = index;
629
630 return 0;
631}
632
633static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
634{
635 struct em28xx_fh *fh = priv;
636 struct em28xx *dev = fh->dev;
637
638 if (a->index != dev->ctl_ainput)
639 return -EINVAL;
640
641 return 0;
642}
643
644static int vidioc_queryctrl(struct file *file, void *priv,
645 struct v4l2_queryctrl *qc)
646{
647 struct em28xx_fh *fh = priv;
648 struct em28xx *dev = fh->dev;
649 int id = qc->id;
650 int i;
651 int rc;
652
653 rc = check_dev(dev);
654 if (rc < 0)
655 return rc;
656
657 memset(qc, 0, sizeof(*qc));
658
659 qc->id = id;
660
661 if (!dev->has_msp34xx) {
662 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
663 if (qc->id && qc->id == em28xx_qctrl[i].id) {
664 memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc));
665 return 0;
666 }
667 }
668 }
669 mutex_lock(&dev->lock);
670 em28xx_i2c_call_clients(dev, VIDIOC_QUERYCTRL, qc);
671 mutex_unlock(&dev->lock);
672
673 if (qc->type)
674 return 0;
675 else
676 return -EINVAL;
677}
678
679static int vidioc_g_ctrl(struct file *file, void *priv,
680 struct v4l2_control *ctrl)
681{
682 struct em28xx_fh *fh = priv;
683 struct em28xx *dev = fh->dev;
684 int rc;
685
686 rc = check_dev(dev);
687 if (rc < 0)
688 return rc;
689 mutex_lock(&dev->lock);
690
691 if (!dev->has_msp34xx)
692 rc = em28xx_get_ctrl(dev, ctrl);
693 else
694 rc = -EINVAL;
695
696 if (rc == -EINVAL) {
697 em28xx_i2c_call_clients(dev, VIDIOC_G_CTRL, ctrl);
698 rc = 0;
699 }
700
701 mutex_unlock(&dev->lock);
702 return rc;
703}
704
705static int vidioc_s_ctrl(struct file *file, void *priv,
706 struct v4l2_control *ctrl)
707{
708 struct em28xx_fh *fh = priv;
709 struct em28xx *dev = fh->dev;
710 u8 i;
711 int rc;
712
713 rc = check_dev(dev);
714 if (rc < 0)
715 return rc;
716
717 mutex_lock(&dev->lock);
718
719 if (dev->has_msp34xx)
720 em28xx_i2c_call_clients(dev, VIDIOC_S_CTRL, ctrl);
721 else {
722 rc = 1;
723 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
724 if (ctrl->id == em28xx_qctrl[i].id) {
725 if (ctrl->value < em28xx_qctrl[i].minimum ||
726 ctrl->value > em28xx_qctrl[i].maximum) {
727 rc = -ERANGE;
728 break;
729 }
730
731 rc = em28xx_set_ctrl(dev, ctrl);
240 break; 732 break;
241 default: 733 }
242 ainput = EM28XX_AUDIO_SRC_LINE; 734 }
735 }
736
737 /* Control not found - try to send it to the attached devices */
738 if (rc == 1) {
739 em28xx_i2c_call_clients(dev, VIDIOC_S_CTRL, ctrl);
740 rc = 0;
741 }
742
743 mutex_unlock(&dev->lock);
744 return rc;
745}
746
747static int vidioc_g_tuner(struct file *file, void *priv,
748 struct v4l2_tuner *t)
749{
750 struct em28xx_fh *fh = priv;
751 struct em28xx *dev = fh->dev;
752 int rc;
753
754 rc = check_dev(dev);
755 if (rc < 0)
756 return rc;
757
758 if (0 != t->index)
759 return -EINVAL;
760
761 strcpy(t->name, "Tuner");
762
763 mutex_lock(&dev->lock);
764
765 em28xx_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
766
767 mutex_unlock(&dev->lock);
768 return 0;
769}
770
771static int vidioc_s_tuner(struct file *file, void *priv,
772 struct v4l2_tuner *t)
773{
774 struct em28xx_fh *fh = priv;
775 struct em28xx *dev = fh->dev;
776 int rc;
777
778 rc = check_dev(dev);
779 if (rc < 0)
780 return rc;
781
782 if (0 != t->index)
783 return -EINVAL;
784
785 mutex_lock(&dev->lock);
786
787 em28xx_i2c_call_clients(dev, VIDIOC_S_TUNER, t);
788
789 mutex_unlock(&dev->lock);
790 return 0;
791}
792
793static int vidioc_g_frequency(struct file *file, void *priv,
794 struct v4l2_frequency *f)
795{
796 struct em28xx_fh *fh = priv;
797 struct em28xx *dev = fh->dev;
798
799 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
800 f->frequency = dev->ctl_freq;
801
802 return 0;
803}
804
805static int vidioc_s_frequency(struct file *file, void *priv,
806 struct v4l2_frequency *f)
807{
808 struct em28xx_fh *fh = priv;
809 struct em28xx *dev = fh->dev;
810 int rc;
811
812 rc = check_dev(dev);
813 if (rc < 0)
814 return rc;
815
816 if (0 != f->tuner)
817 return -EINVAL;
818
819 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
820 return -EINVAL;
821 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
822 return -EINVAL;
823
824 mutex_lock(&dev->lock);
825
826 dev->ctl_freq = f->frequency;
827 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
828
829 mutex_unlock(&dev->lock);
830 return 0;
831}
832
833static int vidioc_cropcap(struct file *file, void *priv,
834 struct v4l2_cropcap *cc)
835{
836 struct em28xx_fh *fh = priv;
837 struct em28xx *dev = fh->dev;
838
839 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
840 return -EINVAL;
841
842 cc->bounds.left = 0;
843 cc->bounds.top = 0;
844 cc->bounds.width = dev->width;
845 cc->bounds.height = dev->height;
846 cc->defrect = cc->bounds;
847 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
848 cc->pixelaspect.denominator = 59;
849
850 return 0;
851}
852
853static int vidioc_streamon(struct file *file, void *priv,
854 enum v4l2_buf_type type)
855{
856 struct em28xx_fh *fh = priv;
857 struct em28xx *dev = fh->dev;
858 int rc;
859
860 rc = check_dev(dev);
861 if (rc < 0)
862 return rc;
863
864 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP)
865 return -EINVAL;
866
867 if (list_empty(&dev->inqueue))
868 return -EINVAL;
869
870 mutex_lock(&dev->lock);
871
872 if (unlikely(res_get(fh) < 0)) {
873 mutex_unlock(&dev->lock);
874 return -EBUSY;
875 }
876
877 dev->stream = STREAM_ON; /* FIXME: Start video capture here? */
878
879 mutex_unlock(&dev->lock);
880 return 0;
881}
882
883static int vidioc_streamoff(struct file *file, void *priv,
884 enum v4l2_buf_type type)
885{
886 struct em28xx_fh *fh = priv;
887 struct em28xx *dev = fh->dev;
888 int rc;
889
890 rc = check_dev(dev);
891 if (rc < 0)
892 return rc;
893
894 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP)
895 return -EINVAL;
896
897 mutex_lock(&dev->lock);
898
899 if (dev->stream == STREAM_ON) {
900 em28xx_videodbg("VIDIOC_STREAMOFF: interrupting stream\n");
901 rc = em28xx_stream_interrupt(dev);
902 if (rc < 0) {
903 mutex_unlock(&dev->lock);
904 return rc;
905 }
906 }
907
908 em28xx_empty_framequeues(dev);
909
910 mutex_unlock(&dev->lock);
911 return 0;
912}
913
914static int vidioc_querycap(struct file *file, void *priv,
915 struct v4l2_capability *cap)
916{
917 struct em28xx_fh *fh = priv;
918 struct em28xx *dev = fh->dev;
919
920 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
921 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
922 strlcpy(cap->bus_info, dev->udev->dev.bus_id, sizeof(cap->bus_info));
923
924 cap->version = EM28XX_VERSION_CODE;
925
926 cap->capabilities =
927 V4L2_CAP_SLICED_VBI_CAPTURE |
928 V4L2_CAP_VIDEO_CAPTURE |
929 V4L2_CAP_AUDIO |
930 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
931
932 if (dev->tuner_type != TUNER_ABSENT)
933 cap->capabilities |= V4L2_CAP_TUNER;
934
935 return 0;
936}
937
938static int vidioc_enum_fmt_cap(struct file *file, void *priv,
939 struct v4l2_fmtdesc *fmtd)
940{
941 if (fmtd->index != 0)
942 return -EINVAL;
943
944 fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
945 strcpy(fmtd->description, "Packed YUY2");
946 fmtd->pixelformat = V4L2_PIX_FMT_YUYV;
947 memset(fmtd->reserved, 0, sizeof(fmtd->reserved));
948
949 return 0;
950}
951
952/* Sliced VBI ioctls */
953static int vidioc_g_fmt_vbi_capture(struct file *file, void *priv,
954 struct v4l2_format *f)
955{
956 struct em28xx_fh *fh = priv;
957 struct em28xx *dev = fh->dev;
958 int rc;
959
960 rc = check_dev(dev);
961 if (rc < 0)
962 return rc;
963
964 mutex_lock(&dev->lock);
965
966 f->fmt.sliced.service_set = 0;
967
968 em28xx_i2c_call_clients(dev, VIDIOC_G_FMT, f);
969
970 if (f->fmt.sliced.service_set == 0)
971 rc = -EINVAL;
972
973 mutex_unlock(&dev->lock);
974 return rc;
975}
976
977static int vidioc_try_set_vbi_capture(struct file *file, void *priv,
978 struct v4l2_format *f)
979{
980 struct em28xx_fh *fh = priv;
981 struct em28xx *dev = fh->dev;
982 int rc;
983
984 rc = check_dev(dev);
985 if (rc < 0)
986 return rc;
987
988 mutex_lock(&dev->lock);
989 em28xx_i2c_call_clients(dev, VIDIOC_G_FMT, f);
990 mutex_unlock(&dev->lock);
991
992 if (f->fmt.sliced.service_set == 0)
993 return -EINVAL;
994
995 return 0;
996}
997
998
999static int vidioc_reqbufs(struct file *file, void *priv,
1000 struct v4l2_requestbuffers *rb)
1001{
1002 struct em28xx_fh *fh = priv;
1003 struct em28xx *dev = fh->dev;
1004 u32 i;
1005 int rc;
1006
1007 rc = check_dev(dev);
1008 if (rc < 0)
1009 return rc;
1010
1011 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1012 rb->memory != V4L2_MEMORY_MMAP)
1013 return -EINVAL;
1014
1015 if (dev->io == IO_READ) {
1016 em28xx_videodbg("method is set to read;"
1017 " close and open the device again to"
1018 " choose the mmap I/O method\n");
1019 return -EINVAL;
1020 }
1021
1022 for (i = 0; i < dev->num_frames; i++)
1023 if (dev->frame[i].vma_use_count) {
1024 em28xx_videodbg("VIDIOC_REQBUFS failed; "
1025 "previous buffers are still mapped\n");
1026 return -EINVAL;
1027 }
1028
1029 mutex_lock(&dev->lock);
1030
1031 if (dev->stream == STREAM_ON) {
1032 em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream\n");
1033 rc = em28xx_stream_interrupt(dev);
1034 if (rc < 0) {
1035 mutex_unlock(&dev->lock);
1036 return rc;
243 } 1037 }
244 em28xx_audio_source(dev, ainput);
245 } 1038 }
1039
1040 em28xx_empty_framequeues(dev);
1041
1042 em28xx_release_buffers(dev);
1043 if (rb->count)
1044 rb->count = em28xx_request_buffers(dev, rb->count);
1045
1046 dev->frame_current = NULL;
1047 dev->io = rb->count ? IO_MMAP : IO_NONE;
1048
1049 mutex_unlock(&dev->lock);
1050 return 0;
1051}
1052
1053static int vidioc_querybuf(struct file *file, void *priv,
1054 struct v4l2_buffer *b)
1055{
1056 struct em28xx_fh *fh = priv;
1057 struct em28xx *dev = fh->dev;
1058 int rc;
1059
1060 rc = check_dev(dev);
1061 if (rc < 0)
1062 return rc;
1063
1064 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1065 b->index >= dev->num_frames || dev->io != IO_MMAP)
1066 return -EINVAL;
1067
1068 mutex_lock(&dev->lock);
1069
1070 memcpy(b, &dev->frame[b->index].buf, sizeof(*b));
1071
1072 if (dev->frame[b->index].vma_use_count)
1073 b->flags |= V4L2_BUF_FLAG_MAPPED;
1074
1075 if (dev->frame[b->index].state == F_DONE)
1076 b->flags |= V4L2_BUF_FLAG_DONE;
1077 else if (dev->frame[b->index].state != F_UNUSED)
1078 b->flags |= V4L2_BUF_FLAG_QUEUED;
1079
1080 mutex_unlock(&dev->lock);
1081 return 0;
1082}
1083
1084static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1085{
1086 struct em28xx_fh *fh = priv;
1087 struct em28xx *dev = fh->dev;
1088 unsigned long lock_flags;
1089 int rc;
1090
1091 rc = check_dev(dev);
1092 if (rc < 0)
1093 return rc;
1094
1095 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP ||
1096 b->index >= dev->num_frames)
1097 return -EINVAL;
1098
1099 if (dev->frame[b->index].state != F_UNUSED)
1100 return -EAGAIN;
1101
1102 dev->frame[b->index].state = F_QUEUED;
1103
1104 /* add frame to fifo */
1105 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1106 list_add_tail(&dev->frame[b->index].frame, &dev->inqueue);
1107 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1108
1109 return 0;
1110}
1111
1112static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1113{
1114 struct em28xx_fh *fh = priv;
1115 struct em28xx *dev = fh->dev;
1116 int rc;
1117 struct em28xx_frame_t *f;
1118 unsigned long lock_flags;
1119
1120 rc = check_dev(dev);
1121 if (rc < 0)
1122 return rc;
1123
1124 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP)
1125 return -EINVAL;
1126
1127 if (list_empty(&dev->outqueue)) {
1128 if (dev->stream == STREAM_OFF)
1129 return -EINVAL;
1130
1131 if (file->f_flags & O_NONBLOCK)
1132 return -EAGAIN;
1133
1134 rc = wait_event_interruptible(dev->wait_frame,
1135 (!list_empty(&dev->outqueue)) ||
1136 (dev->state & DEV_DISCONNECTED));
1137 if (rc)
1138 return rc;
1139
1140 if (dev->state & DEV_DISCONNECTED)
1141 return -ENODEV;
1142 }
1143
1144 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1145 f = list_entry(dev->outqueue.next, struct em28xx_frame_t, frame);
1146 list_del(dev->outqueue.next);
1147 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1148
1149 f->state = F_UNUSED;
1150 memcpy(b, &f->buf, sizeof(*b));
1151
1152 if (f->vma_use_count)
1153 b->flags |= V4L2_BUF_FLAG_MAPPED;
1154
1155 return 0;
1156}
1157
1158/* ----------------------------------------------------------- */
1159/* RADIO ESPECIFIC IOCTLS */
1160/* ----------------------------------------------------------- */
1161
1162static int radio_querycap(struct file *file, void *priv,
1163 struct v4l2_capability *cap)
1164{
1165 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
1166
1167 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1168 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
1169 strlcpy(cap->bus_info, dev->udev->dev.bus_id, sizeof(cap->bus_info));
1170
1171 cap->version = EM28XX_VERSION_CODE;
1172 cap->capabilities = V4L2_CAP_TUNER;
1173 return 0;
1174}
1175
1176static int radio_g_tuner(struct file *file, void *priv,
1177 struct v4l2_tuner *t)
1178{
1179 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
1180
1181 if (unlikely(t->index > 0))
1182 return -EINVAL;
1183
1184 strcpy(t->name, "Radio");
1185 t->type = V4L2_TUNER_RADIO;
1186
1187 em28xx_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
1188 return 0;
1189}
1190
1191static int radio_enum_input(struct file *file, void *priv,
1192 struct v4l2_input *i)
1193{
1194 if (i->index != 0)
1195 return -EINVAL;
1196 strcpy(i->name, "Radio");
1197 i->type = V4L2_INPUT_TYPE_TUNER;
1198
1199 return 0;
1200}
1201
1202static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1203{
1204 if (unlikely(a->index))
1205 return -EINVAL;
1206
1207 strcpy(a->name, "Radio");
1208 return 0;
1209}
1210
1211static int radio_s_tuner(struct file *file, void *priv,
1212 struct v4l2_tuner *t)
1213{
1214 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
1215
1216 if (0 != t->index)
1217 return -EINVAL;
1218
1219 em28xx_i2c_call_clients(dev, VIDIOC_S_TUNER, t);
1220
1221 return 0;
1222}
1223
1224static int radio_s_audio(struct file *file, void *fh,
1225 struct v4l2_audio *a)
1226{
1227 return 0;
1228}
1229
1230static int radio_s_input(struct file *file, void *fh, unsigned int i)
1231{
1232 return 0;
1233}
1234
1235static int radio_queryctrl(struct file *file, void *priv,
1236 struct v4l2_queryctrl *qc)
1237{
1238 int i;
1239
1240 if (qc->id < V4L2_CID_BASE ||
1241 qc->id >= V4L2_CID_LASTP1)
1242 return -EINVAL;
1243
1244 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1245 if (qc->id && qc->id == em28xx_qctrl[i].id) {
1246 memcpy(qc, &(em28xx_qctrl[i]), sizeof(*qc));
1247 return 0;
1248 }
1249 }
1250
1251 return -EINVAL;
246} 1252}
247 1253
248/* 1254/*
@@ -252,8 +1258,9 @@ static void video_mux(struct em28xx *dev, int index)
252static int em28xx_v4l2_open(struct inode *inode, struct file *filp) 1258static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
253{ 1259{
254 int minor = iminor(inode); 1260 int minor = iminor(inode);
255 int errCode = 0; 1261 int errCode = 0, radio = 0;
256 struct em28xx *h,*dev = NULL; 1262 struct em28xx *h,*dev = NULL;
1263 struct em28xx_fh *fh;
257 1264
258 list_for_each_entry(h, &em28xx_devlist, devlist) { 1265 list_for_each_entry(h, &em28xx_devlist, devlist) {
259 if (h->vdev->minor == minor) { 1266 if (h->vdev->minor == minor) {
@@ -264,6 +1271,11 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
264 dev = h; 1271 dev = h;
265 dev->type = V4L2_BUF_TYPE_VBI_CAPTURE; 1272 dev->type = V4L2_BUF_TYPE_VBI_CAPTURE;
266 } 1273 }
1274 if (h->radio_dev &&
1275 h->radio_dev->minor == minor) {
1276 radio = 1;
1277 dev = h;
1278 }
267 } 1279 }
268 if (NULL == dev) 1280 if (NULL == dev)
269 return -ENODEV; 1281 return -ENODEV;
@@ -271,23 +1283,18 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
271 em28xx_videodbg("open minor=%d type=%s users=%d\n", 1283 em28xx_videodbg("open minor=%d type=%s users=%d\n",
272 minor,v4l2_type_names[dev->type],dev->users); 1284 minor,v4l2_type_names[dev->type],dev->users);
273 1285
274 if (!down_read_trylock(&em28xx_disconnect)) 1286 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
275 return -ERESTARTSYS;
276 1287
277 if (dev->users) { 1288 if (!fh) {
278 em28xx_warn("this driver can be opened only once\n"); 1289 em28xx_errdev("em28xx-video.c: Out of memory?!\n");
279 up_read(&em28xx_disconnect); 1290 return -ENOMEM;
280 return -EBUSY;
281 } 1291 }
282
283 mutex_init(&dev->fileop_lock); /* to 1 == available */
284 spin_lock_init(&dev->queue_lock);
285 init_waitqueue_head(&dev->wait_frame);
286 init_waitqueue_head(&dev->wait_stream);
287
288 mutex_lock(&dev->lock); 1292 mutex_lock(&dev->lock);
1293 fh->dev = dev;
1294 fh->radio = radio;
1295 filp->private_data = fh;
289 1296
290 if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1297 if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
291 em28xx_set_alternate(dev); 1298 em28xx_set_alternate(dev);
292 1299
293 dev->width = norm_maxw(dev); 1300 dev->width = norm_maxw(dev);
@@ -301,30 +1308,23 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
301 em28xx_capture_start(dev, 1); 1308 em28xx_capture_start(dev, 1);
302 em28xx_resolution_set(dev); 1309 em28xx_resolution_set(dev);
303 1310
304 /* device needs to be initialized before isoc transfer */
305 video_mux(dev, 0);
306 1311
307 /* start the transfer */ 1312 /* start the transfer */
308 errCode = em28xx_init_isoc(dev); 1313 errCode = em28xx_init_isoc(dev);
309 if (errCode) 1314 if (errCode)
310 goto err; 1315 goto err;
311 1316
1317 em28xx_empty_framequeues(dev);
1318 }
1319 if (fh->radio) {
1320 em28xx_videodbg("video_open: setting radio device\n");
1321 em28xx_i2c_call_clients(dev, AUDC_SET_RADIO, NULL);
312 } 1322 }
313 1323
314 dev->users++; 1324 dev->users++;
315 filp->private_data = dev;
316 dev->io = IO_NONE;
317 dev->stream = STREAM_OFF;
318 dev->num_frames = 0;
319
320 /* prepare queues */
321 em28xx_empty_framequeues(dev);
322
323 dev->state |= DEV_INITIALIZED;
324 1325
325err: 1326err:
326 mutex_unlock(&dev->lock); 1327 mutex_unlock(&dev->lock);
327 up_read(&em28xx_disconnect);
328 return errCode; 1328 return errCode;
329} 1329}
330 1330
@@ -335,7 +1335,6 @@ err:
335*/ 1335*/
336static void em28xx_release_resources(struct em28xx *dev) 1336static void em28xx_release_resources(struct em28xx *dev)
337{ 1337{
338 mutex_lock(&em28xx_sysfs_lock);
339 1338
340 /*FIXME: I2C IR should be disconnected */ 1339 /*FIXME: I2C IR should be disconnected */
341 1340
@@ -343,12 +1342,29 @@ static void em28xx_release_resources(struct em28xx *dev)
343 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN, 1342 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN,
344 dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN); 1343 dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN);
345 list_del(&dev->devlist); 1344 list_del(&dev->devlist);
346 video_unregister_device(dev->vdev); 1345 if (dev->radio_dev) {
347 video_unregister_device(dev->vbi_dev); 1346 if (-1 != dev->radio_dev->minor)
1347 video_unregister_device(dev->radio_dev);
1348 else
1349 video_device_release(dev->radio_dev);
1350 dev->radio_dev = NULL;
1351 }
1352 if (dev->vbi_dev) {
1353 if (-1 != dev->vbi_dev->minor)
1354 video_unregister_device(dev->vbi_dev);
1355 else
1356 video_device_release(dev->vbi_dev);
1357 dev->vbi_dev = NULL;
1358 }
1359 if (dev->vdev) {
1360 if (-1 != dev->vdev->minor)
1361 video_unregister_device(dev->vdev);
1362 else
1363 video_device_release(dev->vdev);
1364 dev->vdev = NULL;
1365 }
348 em28xx_i2c_unregister(dev); 1366 em28xx_i2c_unregister(dev);
349 usb_put_dev(dev->udev); 1367 usb_put_dev(dev->udev);
350 mutex_unlock(&em28xx_sysfs_lock);
351
352 1368
353 /* Mark device as unused */ 1369 /* Mark device as unused */
354 em28xx_devused&=~(1<<dev->devno); 1370 em28xx_devused&=~(1<<dev->devno);
@@ -360,34 +1376,42 @@ static void em28xx_release_resources(struct em28xx *dev)
360 */ 1376 */
361static int em28xx_v4l2_close(struct inode *inode, struct file *filp) 1377static int em28xx_v4l2_close(struct inode *inode, struct file *filp)
362{ 1378{
363 int errCode; 1379 struct em28xx_fh *fh = filp->private_data;
364 struct em28xx *dev=filp->private_data; 1380 struct em28xx *dev = fh->dev;
1381 int errCode;
365 1382
366 em28xx_videodbg("users=%d\n", dev->users); 1383 em28xx_videodbg("users=%d\n", dev->users);
367 1384
368 mutex_lock(&dev->lock);
369 1385
370 em28xx_uninit_isoc(dev); 1386 if (res_check(fh))
1387 res_free(fh);
371 1388
372 em28xx_release_buffers(dev); 1389 mutex_lock(&dev->lock);
373 1390
374 /* the device is already disconnect, free the remaining resources */ 1391 if (dev->users == 1) {
375 if (dev->state & DEV_DISCONNECTED) { 1392 em28xx_uninit_isoc(dev);
376 em28xx_release_resources(dev); 1393 em28xx_release_buffers(dev);
377 mutex_unlock(&dev->lock); 1394 dev->io = IO_NONE;
378 kfree(dev);
379 return 0;
380 }
381 1395
382 /* set alternate 0 */ 1396 /* the device is already disconnect,
383 dev->alt = 0; 1397 free the remaining resources */
384 em28xx_videodbg("setting alternate 0\n"); 1398 if (dev->state & DEV_DISCONNECTED) {
385 errCode = usb_set_interface(dev->udev, 0, 0); 1399 em28xx_release_resources(dev);
386 if (errCode < 0) { 1400 mutex_unlock(&dev->lock);
387 em28xx_errdev ("cannot change alternate number to 0 (error=%i)\n", 1401 kfree(dev);
388 errCode); 1402 return 0;
389 } 1403 }
390 1404
1405 /* set alternate 0 */
1406 dev->alt = 0;
1407 em28xx_videodbg("setting alternate 0\n");
1408 errCode = usb_set_interface(dev->udev, 0, 0);
1409 if (errCode < 0) {
1410 em28xx_errdev("cannot change alternate number to "
1411 "0 (error=%i)\n", errCode);
1412 }
1413 }
1414 kfree(fh);
391 dev->users--; 1415 dev->users--;
392 wake_up_interruptible_nr(&dev->open, 1); 1416 wake_up_interruptible_nr(&dev->open, 1);
393 mutex_unlock(&dev->lock); 1417 mutex_unlock(&dev->lock);
@@ -405,56 +1429,65 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
405 struct em28xx_frame_t *f, *i; 1429 struct em28xx_frame_t *f, *i;
406 unsigned long lock_flags; 1430 unsigned long lock_flags;
407 int ret = 0; 1431 int ret = 0;
408 struct em28xx *dev = filp->private_data; 1432 struct em28xx_fh *fh = filp->private_data;
1433 struct em28xx *dev = fh->dev;
409 1434
410 if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1435 /* FIXME: read() is not prepared to allow changing the video
1436 resolution while streaming. Seems a bug at em28xx_set_fmt
1437 */
1438
1439 if (unlikely(res_get(fh) < 0))
1440 return -EBUSY;
1441
1442 mutex_lock(&dev->lock);
1443
1444 if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
411 em28xx_videodbg("V4l2_Buf_type_videocapture is set\n"); 1445 em28xx_videodbg("V4l2_Buf_type_videocapture is set\n");
412 } 1446
413 if (dev->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 1447 if (dev->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
414 em28xx_videodbg("V4L2_BUF_TYPE_VBI_CAPTURE is set\n"); 1448 em28xx_videodbg("V4L2_BUF_TYPE_VBI_CAPTURE is set\n");
415 em28xx_videodbg("not supported yet! ...\n"); 1449 em28xx_videodbg("not supported yet! ...\n");
416 if (copy_to_user(buf, "", 1)) { 1450 if (copy_to_user(buf, "", 1)) {
417 mutex_unlock(&dev->fileop_lock); 1451 mutex_unlock(&dev->lock);
418 return -EFAULT; 1452 return -EFAULT;
419 } 1453 }
1454 mutex_unlock(&dev->lock);
420 return (1); 1455 return (1);
421 } 1456 }
422 if (dev->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) { 1457 if (dev->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
423 em28xx_videodbg("V4L2_BUF_TYPE_SLICED_VBI_CAPTURE is set\n"); 1458 em28xx_videodbg("V4L2_BUF_TYPE_SLICED_VBI_CAPTURE is set\n");
424 em28xx_videodbg("not supported yet! ...\n"); 1459 em28xx_videodbg("not supported yet! ...\n");
425 if (copy_to_user(buf, "", 1)) { 1460 if (copy_to_user(buf, "", 1)) {
426 mutex_unlock(&dev->fileop_lock); 1461 mutex_unlock(&dev->lock);
427 return -EFAULT; 1462 return -EFAULT;
428 } 1463 }
1464 mutex_unlock(&dev->lock);
429 return (1); 1465 return (1);
430 } 1466 }
431 1467
432 if (mutex_lock_interruptible(&dev->fileop_lock))
433 return -ERESTARTSYS;
434
435 if (dev->state & DEV_DISCONNECTED) { 1468 if (dev->state & DEV_DISCONNECTED) {
436 em28xx_videodbg("device not present\n"); 1469 em28xx_videodbg("device not present\n");
437 mutex_unlock(&dev->fileop_lock); 1470 mutex_unlock(&dev->lock);
438 return -ENODEV; 1471 return -ENODEV;
439 } 1472 }
440 1473
441 if (dev->state & DEV_MISCONFIGURED) { 1474 if (dev->state & DEV_MISCONFIGURED) {
442 em28xx_videodbg("device misconfigured; close and open it again\n"); 1475 em28xx_videodbg("device misconfigured; close and open it again\n");
443 mutex_unlock(&dev->fileop_lock); 1476 mutex_unlock(&dev->lock);
444 return -EIO; 1477 return -EIO;
445 } 1478 }
446 1479
447 if (dev->io == IO_MMAP) { 1480 if (dev->io == IO_MMAP) {
448 em28xx_videodbg ("IO method is set to mmap; close and open" 1481 em28xx_videodbg ("IO method is set to mmap; close and open"
449 " the device again to choose the read method\n"); 1482 " the device again to choose the read method\n");
450 mutex_unlock(&dev->fileop_lock); 1483 mutex_unlock(&dev->lock);
451 return -EINVAL; 1484 return -EINVAL;
452 } 1485 }
453 1486
454 if (dev->io == IO_NONE) { 1487 if (dev->io == IO_NONE) {
455 if (!em28xx_request_buffers(dev, EM28XX_NUM_READ_FRAMES)) { 1488 if (!em28xx_request_buffers(dev, EM28XX_NUM_READ_FRAMES)) {
456 em28xx_errdev("read failed, not enough memory\n"); 1489 em28xx_errdev("read failed, not enough memory\n");
457 mutex_unlock(&dev->fileop_lock); 1490 mutex_unlock(&dev->lock);
458 return -ENOMEM; 1491 return -ENOMEM;
459 } 1492 }
460 dev->io = IO_READ; 1493 dev->io = IO_READ;
@@ -463,13 +1496,13 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
463 } 1496 }
464 1497
465 if (!count) { 1498 if (!count) {
466 mutex_unlock(&dev->fileop_lock); 1499 mutex_unlock(&dev->lock);
467 return 0; 1500 return 0;
468 } 1501 }
469 1502
470 if (list_empty(&dev->outqueue)) { 1503 if (list_empty(&dev->outqueue)) {
471 if (filp->f_flags & O_NONBLOCK) { 1504 if (filp->f_flags & O_NONBLOCK) {
472 mutex_unlock(&dev->fileop_lock); 1505 mutex_unlock(&dev->lock);
473 return -EAGAIN; 1506 return -EAGAIN;
474 } 1507 }
475 ret = wait_event_interruptible 1508 ret = wait_event_interruptible
@@ -477,35 +1510,46 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
477 (!list_empty(&dev->outqueue)) || 1510 (!list_empty(&dev->outqueue)) ||
478 (dev->state & DEV_DISCONNECTED)); 1511 (dev->state & DEV_DISCONNECTED));
479 if (ret) { 1512 if (ret) {
480 mutex_unlock(&dev->fileop_lock); 1513 mutex_unlock(&dev->lock);
481 return ret; 1514 return ret;
482 } 1515 }
483 if (dev->state & DEV_DISCONNECTED) { 1516 if (dev->state & DEV_DISCONNECTED) {
484 mutex_unlock(&dev->fileop_lock); 1517 mutex_unlock(&dev->lock);
485 return -ENODEV; 1518 return -ENODEV;
486 } 1519 }
1520 dev->video_bytesread = 0;
487 } 1521 }
488 1522
489 f = list_entry(dev->outqueue.prev, struct em28xx_frame_t, frame); 1523 f = list_entry(dev->outqueue.prev, struct em28xx_frame_t, frame);
490 1524
491 spin_lock_irqsave(&dev->queue_lock, lock_flags);
492 list_for_each_entry(i, &dev->outqueue, frame)
493 i->state = F_UNUSED;
494 INIT_LIST_HEAD(&dev->outqueue);
495 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
496
497 em28xx_queue_unusedframes(dev); 1525 em28xx_queue_unusedframes(dev);
498 1526
499 if (count > f->buf.length) 1527 if (count > f->buf.length)
500 count = f->buf.length; 1528 count = f->buf.length;
501 1529
502 if (copy_to_user(buf, f->bufmem, count)) { 1530 if ((dev->video_bytesread + count) > dev->frame_size)
503 mutex_unlock(&dev->fileop_lock); 1531 count = dev->frame_size - dev->video_bytesread;
1532
1533 if (copy_to_user(buf, f->bufmem+dev->video_bytesread, count)) {
1534 em28xx_err("Error while copying to user\n");
504 return -EFAULT; 1535 return -EFAULT;
505 } 1536 }
1537 dev->video_bytesread += count;
1538
1539 if (dev->video_bytesread == dev->frame_size) {
1540 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1541 list_for_each_entry(i, &dev->outqueue, frame)
1542 i->state = F_UNUSED;
1543 INIT_LIST_HEAD(&dev->outqueue);
1544 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1545
1546 em28xx_queue_unusedframes(dev);
1547 dev->video_bytesread = 0;
1548 }
1549
506 *f_pos += count; 1550 *f_pos += count;
507 1551
508 mutex_unlock(&dev->fileop_lock); 1552 mutex_unlock(&dev->lock);
509 1553
510 return count; 1554 return count;
511} 1555}
@@ -517,11 +1561,14 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
517static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait) 1561static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait)
518{ 1562{
519 unsigned int mask = 0; 1563 unsigned int mask = 0;
520 struct em28xx *dev = filp->private_data; 1564 struct em28xx_fh *fh = filp->private_data;
1565 struct em28xx *dev = fh->dev;
521 1566
522 if (mutex_lock_interruptible(&dev->fileop_lock)) 1567 if (unlikely(res_get(fh) < 0))
523 return POLLERR; 1568 return POLLERR;
524 1569
1570 mutex_lock(&dev->lock);
1571
525 if (dev->state & DEV_DISCONNECTED) { 1572 if (dev->state & DEV_DISCONNECTED) {
526 em28xx_videodbg("device not present\n"); 1573 em28xx_videodbg("device not present\n");
527 } else if (dev->state & DEV_MISCONFIGURED) { 1574 } else if (dev->state & DEV_MISCONFIGURED) {
@@ -545,83 +1592,61 @@ static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait)
545 if (!list_empty(&dev->outqueue)) 1592 if (!list_empty(&dev->outqueue))
546 mask |= POLLIN | POLLRDNORM; 1593 mask |= POLLIN | POLLRDNORM;
547 1594
548 mutex_unlock(&dev->fileop_lock); 1595 mutex_unlock(&dev->lock);
549 1596
550 return mask; 1597 return mask;
551 } 1598 }
552 } 1599 }
553 1600
554 mutex_unlock(&dev->fileop_lock); 1601 mutex_unlock(&dev->lock);
555 return POLLERR; 1602 return POLLERR;
556} 1603}
557 1604
558/* 1605/*
559 * em28xx_vm_open()
560 */
561static void em28xx_vm_open(struct vm_area_struct *vma)
562{
563 struct em28xx_frame_t *f = vma->vm_private_data;
564 f->vma_use_count++;
565}
566
567/*
568 * em28xx_vm_close()
569 */
570static void em28xx_vm_close(struct vm_area_struct *vma)
571{
572 /* NOTE: buffers are not freed here */
573 struct em28xx_frame_t *f = vma->vm_private_data;
574
575 if (f->vma_use_count)
576 f->vma_use_count--;
577}
578
579static struct vm_operations_struct em28xx_vm_ops = {
580 .open = em28xx_vm_open,
581 .close = em28xx_vm_close,
582};
583
584/*
585 * em28xx_v4l2_mmap() 1606 * em28xx_v4l2_mmap()
586 */ 1607 */
587static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) 1608static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
588{ 1609{
589 unsigned long size = vma->vm_end - vma->vm_start, 1610 struct em28xx_fh *fh = filp->private_data;
590 start = vma->vm_start; 1611 struct em28xx *dev = fh->dev;
591 void *pos; 1612 unsigned long size = vma->vm_end - vma->vm_start;
592 u32 i; 1613 unsigned long start = vma->vm_start;
593 1614 void *pos;
594 struct em28xx *dev = filp->private_data; 1615 u32 i;
1616
1617 if (unlikely(res_get(fh) < 0))
1618 return -EBUSY;
595 1619
596 if (mutex_lock_interruptible(&dev->fileop_lock)) 1620 mutex_lock(&dev->lock);
597 return -ERESTARTSYS;
598 1621
599 if (dev->state & DEV_DISCONNECTED) { 1622 if (dev->state & DEV_DISCONNECTED) {
600 em28xx_videodbg("mmap: device not present\n"); 1623 em28xx_videodbg("mmap: device not present\n");
601 mutex_unlock(&dev->fileop_lock); 1624 mutex_unlock(&dev->lock);
602 return -ENODEV; 1625 return -ENODEV;
603 } 1626 }
604 1627
605 if (dev->state & DEV_MISCONFIGURED) { 1628 if (dev->state & DEV_MISCONFIGURED) {
606 em28xx_videodbg ("mmap: Device is misconfigured; close and " 1629 em28xx_videodbg ("mmap: Device is misconfigured; close and "
607 "open it again\n"); 1630 "open it again\n");
608 mutex_unlock(&dev->fileop_lock); 1631 mutex_unlock(&dev->lock);
609 return -EIO; 1632 return -EIO;
610 } 1633 }
611 1634
612 if (dev->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) || 1635 if (dev->io != IO_MMAP || !(vma->vm_flags & VM_WRITE)) {
613 size != PAGE_ALIGN(dev->frame[0].buf.length)) { 1636 mutex_unlock(&dev->lock);
614 mutex_unlock(&dev->fileop_lock);
615 return -EINVAL; 1637 return -EINVAL;
616 } 1638 }
617 1639
1640 if (size > PAGE_ALIGN(dev->frame[0].buf.length))
1641 size = PAGE_ALIGN(dev->frame[0].buf.length);
1642
618 for (i = 0; i < dev->num_frames; i++) { 1643 for (i = 0; i < dev->num_frames; i++) {
619 if ((dev->frame[i].buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff) 1644 if ((dev->frame[i].buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
620 break; 1645 break;
621 } 1646 }
622 if (i == dev->num_frames) { 1647 if (i == dev->num_frames) {
623 em28xx_videodbg("mmap: user supplied mapping address is out of range\n"); 1648 em28xx_videodbg("mmap: user supplied mapping address is out of range\n");
624 mutex_unlock(&dev->fileop_lock); 1649 mutex_unlock(&dev->lock);
625 return -EINVAL; 1650 return -EINVAL;
626 } 1651 }
627 1652
@@ -633,7 +1658,7 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
633 while (size > 0) { /* size is page-aligned */ 1658 while (size > 0) { /* size is page-aligned */
634 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { 1659 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
635 em28xx_videodbg("mmap: vm_insert_page failed\n"); 1660 em28xx_videodbg("mmap: vm_insert_page failed\n");
636 mutex_unlock(&dev->fileop_lock); 1661 mutex_unlock(&dev->lock);
637 return -EAGAIN; 1662 return -EAGAIN;
638 } 1663 }
639 start += PAGE_SIZE; 1664 start += PAGE_SIZE;
@@ -645,900 +1670,210 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
645 vma->vm_private_data = &dev->frame[i]; 1670 vma->vm_private_data = &dev->frame[i];
646 1671
647 em28xx_vm_open(vma); 1672 em28xx_vm_open(vma);
648 mutex_unlock(&dev->fileop_lock); 1673 mutex_unlock(&dev->lock);
649 return 0;
650}
651
652/*
653 * em28xx_get_ctrl()
654 * return the current saturation, brightness or contrast, mute state
655 */
656static int em28xx_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
657{
658 switch (ctrl->id) {
659 case V4L2_CID_AUDIO_MUTE:
660 ctrl->value = dev->mute;
661 return 0;
662 case V4L2_CID_AUDIO_VOLUME:
663 ctrl->value = dev->volume;
664 return 0;
665 default:
666 return -EINVAL;
667 }
668}
669
670/*
671 * em28xx_set_ctrl()
672 * mute or set new saturation, brightness or contrast
673 */
674static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
675{
676 switch (ctrl->id) {
677 case V4L2_CID_AUDIO_MUTE:
678 if (ctrl->value != dev->mute) {
679 dev->mute = ctrl->value;
680 em28xx_audio_usb_mute(dev, ctrl->value);
681 return em28xx_audio_analog_set(dev);
682 }
683 return 0;
684 case V4L2_CID_AUDIO_VOLUME:
685 dev->volume = ctrl->value;
686 return em28xx_audio_analog_set(dev);
687 default:
688 return -EINVAL;
689 }
690}
691
692/*
693 * em28xx_stream_interrupt()
694 * stops streaming
695 */
696static int em28xx_stream_interrupt(struct em28xx *dev)
697{
698 int ret = 0;
699
700 /* stop reading from the device */
701
702 dev->stream = STREAM_INTERRUPT;
703 ret = wait_event_timeout(dev->wait_stream,
704 (dev->stream == STREAM_OFF) ||
705 (dev->state & DEV_DISCONNECTED),
706 EM28XX_URB_TIMEOUT);
707 if (dev->state & DEV_DISCONNECTED)
708 return -ENODEV;
709 else if (ret) {
710 dev->state |= DEV_MISCONFIGURED;
711 em28xx_videodbg("device is misconfigured; close and "
712 "open /dev/video%d again\n",
713 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN);
714 return ret;
715 }
716
717 return 0;
718}
719
720static int em28xx_set_norm(struct em28xx *dev, int width, int height)
721{
722 unsigned int hscale, vscale;
723 unsigned int maxh, maxw;
724
725 maxw = norm_maxw(dev);
726 maxh = norm_maxh(dev);
727
728 /* width must even because of the YUYV format */
729 /* height must be even because of interlacing */
730 height &= 0xfffe;
731 width &= 0xfffe;
732
733 if (height < 32)
734 height = 32;
735 if (height > maxh)
736 height = maxh;
737 if (width < 48)
738 width = 48;
739 if (width > maxw)
740 width = maxw;
741
742 if ((hscale = (((unsigned long)maxw) << 12) / width - 4096L) >= 0x4000)
743 hscale = 0x3fff;
744 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
745
746 if ((vscale = (((unsigned long)maxh) << 12) / height - 4096L) >= 0x4000)
747 vscale = 0x3fff;
748 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
749
750 /* set new image size */
751 dev->width = width;
752 dev->height = height;
753 dev->frame_size = dev->width * dev->height * 2;
754 dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
755 dev->bytesperline = dev->width * 2;
756 dev->hscale = hscale;
757 dev->vscale = vscale;
758
759 em28xx_resolution_set(dev);
760
761 return 0; 1674 return 0;
762} 1675}
763 1676
764static int em28xx_get_fmt(struct em28xx *dev, struct v4l2_format *format) 1677static const struct file_operations em28xx_v4l_fops = {
765{ 1678 .owner = THIS_MODULE,
766 em28xx_videodbg("VIDIOC_G_FMT: type=%s\n", 1679 .open = em28xx_v4l2_open,
767 (format->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE) ? 1680 .release = em28xx_v4l2_close,
768 "V4L2_BUF_TYPE_VIDEO_CAPTURE" : 1681 .read = em28xx_v4l2_read,
769 (format->type ==V4L2_BUF_TYPE_VBI_CAPTURE) ? 1682 .poll = em28xx_v4l2_poll,
770 "V4L2_BUF_TYPE_VBI_CAPTURE" : 1683 .mmap = em28xx_v4l2_mmap,
771 (format->type ==V4L2_CAP_SLICED_VBI_CAPTURE) ? 1684 .ioctl = video_ioctl2,
772 "V4L2_BUF_TYPE_SLICED_VBI_CAPTURE " : 1685 .llseek = no_llseek,
773 "not supported"); 1686 .compat_ioctl = v4l_compat_ioctl32,
774 1687};
775 switch (format->type) {
776 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
777 {
778 format->fmt.pix.width = dev->width;
779 format->fmt.pix.height = dev->height;
780 format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
781 format->fmt.pix.bytesperline = dev->bytesperline;
782 format->fmt.pix.sizeimage = dev->frame_size;
783 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
784 format->fmt.pix.field = dev->interlaced ? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
785 1688
786 em28xx_videodbg("VIDIOC_G_FMT: %dx%d\n", dev->width, 1689static const struct file_operations radio_fops = {
787 dev->height); 1690 .owner = THIS_MODULE,
788 break; 1691 .open = em28xx_v4l2_open,
789 } 1692 .release = em28xx_v4l2_close,
1693 .ioctl = video_ioctl2,
1694 .compat_ioctl = v4l_compat_ioctl32,
1695 .llseek = no_llseek,
1696};
790 1697
791 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 1698static const struct video_device em28xx_video_template = {
792 { 1699 .fops = &em28xx_v4l_fops,
793 format->fmt.sliced.service_set=0; 1700 .release = video_device_release,
1701
1702 .minor = -1,
1703 .vidioc_querycap = vidioc_querycap,
1704 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
1705 .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
1706 .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
1707 .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
1708 .vidioc_g_audio = vidioc_g_audio,
1709 .vidioc_s_audio = vidioc_s_audio,
1710 .vidioc_cropcap = vidioc_cropcap,
1711
1712 .vidioc_g_fmt_vbi_capture = vidioc_g_fmt_vbi_capture,
1713 .vidioc_try_fmt_vbi_capture = vidioc_try_set_vbi_capture,
1714 .vidioc_s_fmt_vbi_capture = vidioc_try_set_vbi_capture,
1715
1716 .vidioc_reqbufs = vidioc_reqbufs,
1717 .vidioc_querybuf = vidioc_querybuf,
1718 .vidioc_qbuf = vidioc_qbuf,
1719 .vidioc_dqbuf = vidioc_dqbuf,
1720 .vidioc_s_std = vidioc_s_std,
1721 .vidioc_enum_input = vidioc_enum_input,
1722 .vidioc_g_input = vidioc_g_input,
1723 .vidioc_s_input = vidioc_s_input,
1724 .vidioc_queryctrl = vidioc_queryctrl,
1725 .vidioc_g_ctrl = vidioc_g_ctrl,
1726 .vidioc_s_ctrl = vidioc_s_ctrl,
1727 .vidioc_streamon = vidioc_streamon,
1728 .vidioc_streamoff = vidioc_streamoff,
1729 .vidioc_g_tuner = vidioc_g_tuner,
1730 .vidioc_s_tuner = vidioc_s_tuner,
1731 .vidioc_g_frequency = vidioc_g_frequency,
1732 .vidioc_s_frequency = vidioc_s_frequency,
1733
1734 .tvnorms = V4L2_STD_ALL,
1735 .current_norm = V4L2_STD_PAL,
1736};
794 1737
795 em28xx_i2c_call_clients(dev,VIDIOC_G_FMT,format); 1738static struct video_device em28xx_radio_template = {
1739 .name = "em28xx-radio",
1740 .type = VID_TYPE_TUNER,
1741 .fops = &radio_fops,
1742 .minor = -1,
1743 .vidioc_querycap = radio_querycap,
1744 .vidioc_g_tuner = radio_g_tuner,
1745 .vidioc_enum_input = radio_enum_input,
1746 .vidioc_g_audio = radio_g_audio,
1747 .vidioc_s_tuner = radio_s_tuner,
1748 .vidioc_s_audio = radio_s_audio,
1749 .vidioc_s_input = radio_s_input,
1750 .vidioc_queryctrl = radio_queryctrl,
1751 .vidioc_g_ctrl = vidioc_g_ctrl,
1752 .vidioc_s_ctrl = vidioc_s_ctrl,
1753 .vidioc_g_frequency = vidioc_g_frequency,
1754 .vidioc_s_frequency = vidioc_s_frequency,
1755};
796 1756
797 if (format->fmt.sliced.service_set==0) 1757/******************************** usb interface *****************************************/
798 return -EINVAL;
799 1758
800 break;
801 }
802 1759
803 default: 1760static LIST_HEAD(em28xx_extension_devlist);
804 return -EINVAL; 1761static DEFINE_MUTEX(em28xx_extension_devlist_lock);
805 }
806 return (0);
807}
808 1762
809static int em28xx_set_fmt(struct em28xx *dev, unsigned int cmd, struct v4l2_format *format) 1763int em28xx_register_extension(struct em28xx_ops *ops)
810{ 1764{
811 u32 i; 1765 struct em28xx *h, *dev = NULL;
812 int ret = 0;
813 int width = format->fmt.pix.width;
814 int height = format->fmt.pix.height;
815 unsigned int hscale, vscale;
816 unsigned int maxh, maxw;
817 1766
818 maxw = norm_maxw(dev); 1767 list_for_each_entry(h, &em28xx_devlist, devlist)
819 maxh = norm_maxh(dev); 1768 dev = h;
820
821 em28xx_videodbg("%s: type=%s\n",
822 cmd == VIDIOC_TRY_FMT ?
823 "VIDIOC_TRY_FMT" : "VIDIOC_S_FMT",
824 format->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ?
825 "V4L2_BUF_TYPE_VIDEO_CAPTURE" :
826 format->type == V4L2_BUF_TYPE_VBI_CAPTURE ?
827 "V4L2_BUF_TYPE_VBI_CAPTURE " :
828 "not supported");
829
830 if (format->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
831 em28xx_i2c_call_clients(dev,VIDIOC_G_FMT,format);
832
833 if (format->fmt.sliced.service_set==0)
834 return -EINVAL;
835 1769
836 return 0; 1770 mutex_lock(&em28xx_extension_devlist_lock);
837 } 1771 list_add_tail(&ops->next, &em28xx_extension_devlist);
1772 if (dev)
1773 ops->init(dev);
838 1774
839 1775 printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
840 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1776 mutex_unlock(&em28xx_extension_devlist_lock);
841 return -EINVAL;
842
843 em28xx_videodbg("%s: requested %dx%d\n",
844 cmd == VIDIOC_TRY_FMT ?
845 "VIDIOC_TRY_FMT" : "VIDIOC_S_FMT",
846 format->fmt.pix.width, format->fmt.pix.height);
847
848 /* FIXME: Move some code away from here */
849 /* width must even because of the YUYV format */
850 /* height must be even because of interlacing */
851 height &= 0xfffe;
852 width &= 0xfffe;
853
854 if (height < 32)
855 height = 32;
856 if (height > maxh)
857 height = maxh;
858 if (width < 48)
859 width = 48;
860 if (width > maxw)
861 width = maxw;
862
863 if(dev->is_em2800){
864 /* the em2800 can only scale down to 50% */
865 if(height % (maxh / 2))
866 height=maxh;
867 if(width % (maxw / 2))
868 width=maxw;
869 /* according to empiatech support */
870 /* the MaxPacketSize is to small to support */
871 /* framesizes larger than 640x480 @ 30 fps */
872 /* or 640x576 @ 25 fps. As this would cut */
873 /* of a part of the image we prefer */
874 /* 360x576 or 360x480 for now */
875 if(width == maxw && height == maxh)
876 width /= 2;
877 }
878
879 if ((hscale = (((unsigned long)maxw) << 12) / width - 4096L) >= 0x4000)
880 hscale = 0x3fff;
881
882 width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
883
884 if ((vscale = (((unsigned long)maxh) << 12) / height - 4096L) >= 0x4000)
885 vscale = 0x3fff;
886
887 height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
888
889 format->fmt.pix.width = width;
890 format->fmt.pix.height = height;
891 format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
892 format->fmt.pix.bytesperline = width * 2;
893 format->fmt.pix.sizeimage = width * 2 * height;
894 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
895 format->fmt.pix.field = V4L2_FIELD_INTERLACED;
896
897 em28xx_videodbg("%s: returned %dx%d (%d, %d)\n",
898 cmd == VIDIOC_TRY_FMT ?
899 "VIDIOC_TRY_FMT" :"VIDIOC_S_FMT",
900 format->fmt.pix.width, format->fmt.pix.height, hscale, vscale);
901
902 if (cmd == VIDIOC_TRY_FMT)
903 return 0;
904
905 for (i = 0; i < dev->num_frames; i++)
906 if (dev->frame[i].vma_use_count) {
907 em28xx_videodbg("VIDIOC_S_FMT failed. "
908 "Unmap the buffers first.\n");
909 return -EINVAL;
910 }
911
912 /* stop io in case it is already in progress */
913 if (dev->stream == STREAM_ON) {
914 em28xx_videodbg("VIDIOC_SET_FMT: interrupting stream\n");
915 if ((ret = em28xx_stream_interrupt(dev)))
916 return ret;
917 }
918
919 em28xx_release_buffers(dev);
920 dev->io = IO_NONE;
921
922 /* set new image size */
923 dev->width = width;
924 dev->height = height;
925 dev->frame_size = dev->width * dev->height * 2;
926 dev->field_size = dev->frame_size >> 1;
927 dev->bytesperline = dev->width * 2;
928 dev->hscale = hscale;
929 dev->vscale = vscale;
930 em28xx_uninit_isoc(dev);
931 em28xx_set_alternate(dev);
932 em28xx_capture_start(dev, 1);
933 em28xx_resolution_set(dev);
934 em28xx_init_isoc(dev);
935 1777
936 return 0; 1778 return 0;
937} 1779}
1780EXPORT_SYMBOL(em28xx_register_extension);
938 1781
939/* 1782void em28xx_unregister_extension(struct em28xx_ops *ops)
940 * em28xx_v4l2_do_ioctl()
941 * This function is _not_ called directly, but from
942 * em28xx_v4l2_ioctl. Userspace
943 * copying is done already, arg is a kernel pointer.
944 */
945static int em28xx_do_ioctl(struct inode *inode, struct file *filp,
946 struct em28xx *dev, unsigned int cmd, void *arg,
947 v4l2_kioctl driver_ioctl)
948{ 1783{
949 int ret; 1784 struct em28xx *h, *dev = NULL;
950 1785
951 switch (cmd) { 1786 list_for_each_entry(h, &em28xx_devlist, devlist)
952 /* ---------- tv norms ---------- */ 1787 dev = h;
953 case VIDIOC_ENUMSTD:
954 {
955 struct v4l2_standard *e = arg;
956 unsigned int i;
957 1788
958 i = e->index; 1789 if (dev)
959 if (i >= TVNORMS) 1790 ops->fini(dev);
960 return -EINVAL;
961 ret = v4l2_video_std_construct(e, tvnorms[e->index].id,
962 tvnorms[e->index].name);
963 e->index = i;
964 if (ret < 0)
965 return ret;
966 return 0;
967 }
968 case VIDIOC_G_STD:
969 {
970 v4l2_std_id *id = arg;
971 1791
972 *id = dev->tvnorm->id; 1792 mutex_lock(&em28xx_extension_devlist_lock);
973 return 0; 1793 printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
974 } 1794 list_del(&ops->next);
975 case VIDIOC_S_STD: 1795 mutex_unlock(&em28xx_extension_devlist_lock);
976 {
977 v4l2_std_id *id = arg;
978 unsigned int i;
979
980 for (i = 0; i < TVNORMS; i++)
981 if (*id == tvnorms[i].id)
982 break;
983 if (i == TVNORMS)
984 for (i = 0; i < TVNORMS; i++)
985 if (*id & tvnorms[i].id)
986 break;
987 if (i == TVNORMS)
988 return -EINVAL;
989
990 mutex_lock(&dev->lock);
991 dev->tvnorm = &tvnorms[i];
992
993 em28xx_set_norm(dev, dev->width, dev->height);
994
995 em28xx_i2c_call_clients(dev, VIDIOC_S_STD,
996 &dev->tvnorm->id);
997
998 mutex_unlock(&dev->lock);
999
1000 return 0;
1001 }
1002
1003 /* ------ input switching ---------- */
1004 case VIDIOC_ENUMINPUT:
1005 {
1006 struct v4l2_input *i = arg;
1007 unsigned int n;
1008 static const char *iname[] = {
1009 [EM28XX_VMUX_COMPOSITE1] = "Composite1",
1010 [EM28XX_VMUX_COMPOSITE2] = "Composite2",
1011 [EM28XX_VMUX_COMPOSITE3] = "Composite3",
1012 [EM28XX_VMUX_COMPOSITE4] = "Composite4",
1013 [EM28XX_VMUX_SVIDEO] = "S-Video",
1014 [EM28XX_VMUX_TELEVISION] = "Television",
1015 [EM28XX_VMUX_CABLE] = "Cable TV",
1016 [EM28XX_VMUX_DVB] = "DVB",
1017 [EM28XX_VMUX_DEBUG] = "for debug only",
1018 };
1019
1020 n = i->index;
1021 if (n >= MAX_EM28XX_INPUT)
1022 return -EINVAL;
1023 if (0 == INPUT(n)->type)
1024 return -EINVAL;
1025 memset(i, 0, sizeof(*i));
1026 i->index = n;
1027 i->type = V4L2_INPUT_TYPE_CAMERA;
1028 strcpy(i->name, iname[INPUT(n)->type]);
1029 if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) ||
1030 (EM28XX_VMUX_CABLE == INPUT(n)->type))
1031 i->type = V4L2_INPUT_TYPE_TUNER;
1032 for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
1033 i->std |= tvnorms[n].id;
1034 return 0;
1035 }
1036 case VIDIOC_G_INPUT:
1037 {
1038 int *i = arg;
1039 *i = dev->ctl_input;
1040
1041 return 0;
1042 }
1043 case VIDIOC_S_INPUT:
1044 {
1045 int *index = arg;
1046
1047 if (*index >= MAX_EM28XX_INPUT)
1048 return -EINVAL;
1049 if (0 == INPUT(*index)->type)
1050 return -EINVAL;
1051
1052 mutex_lock(&dev->lock);
1053 video_mux(dev, *index);
1054 mutex_unlock(&dev->lock);
1055
1056 return 0;
1057 }
1058 case VIDIOC_G_AUDIO:
1059 {
1060 struct v4l2_audio *a = arg;
1061 unsigned int index = a->index;
1062
1063 if (a->index > 1)
1064 return -EINVAL;
1065 memset(a, 0, sizeof(*a));
1066 index = dev->ctl_ainput;
1067
1068 if (index == 0) {
1069 strcpy(a->name, "Television");
1070 } else {
1071 strcpy(a->name, "Line In");
1072 }
1073 a->capability = V4L2_AUDCAP_STEREO;
1074 a->index = index;
1075 return 0;
1076 }
1077 case VIDIOC_S_AUDIO:
1078 {
1079 struct v4l2_audio *a = arg;
1080
1081 if (a->index != dev->ctl_ainput)
1082 return -EINVAL;
1083
1084 return 0;
1085 }
1086
1087 /* --- controls ---------------------------------------------- */
1088 case VIDIOC_QUERYCTRL:
1089 {
1090 struct v4l2_queryctrl *qc = arg;
1091 int i, id=qc->id;
1092
1093 memset(qc,0,sizeof(*qc));
1094 qc->id=id;
1095
1096 if (!dev->has_msp34xx) {
1097 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1098 if (qc->id && qc->id == em28xx_qctrl[i].id) {
1099 memcpy(qc, &(em28xx_qctrl[i]),
1100 sizeof(*qc));
1101 return 0;
1102 }
1103 }
1104 }
1105 em28xx_i2c_call_clients(dev,cmd,qc);
1106 if (qc->type)
1107 return 0;
1108 else
1109 return -EINVAL;
1110 }
1111 case VIDIOC_G_CTRL:
1112 {
1113 struct v4l2_control *ctrl = arg;
1114 int retval=-EINVAL;
1115
1116 if (!dev->has_msp34xx)
1117 retval=em28xx_get_ctrl(dev, ctrl);
1118 if (retval==-EINVAL) {
1119 em28xx_i2c_call_clients(dev,cmd,arg);
1120 return 0;
1121 } else return retval;
1122 }
1123 case VIDIOC_S_CTRL:
1124 {
1125 struct v4l2_control *ctrl = arg;
1126 u8 i;
1127
1128 if (!dev->has_msp34xx){
1129 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
1130 if (ctrl->id == em28xx_qctrl[i].id) {
1131 if (ctrl->value <
1132 em28xx_qctrl[i].minimum
1133 || ctrl->value >
1134 em28xx_qctrl[i].maximum)
1135 return -ERANGE;
1136 return em28xx_set_ctrl(dev, ctrl);
1137 }
1138 }
1139 }
1140
1141 em28xx_i2c_call_clients(dev,cmd,arg);
1142 return 0;
1143 }
1144 /* --- tuner ioctls ------------------------------------------ */
1145 case VIDIOC_G_TUNER:
1146 {
1147 struct v4l2_tuner *t = arg;
1148
1149 if (0 != t->index)
1150 return -EINVAL;
1151
1152 memset(t, 0, sizeof(*t));
1153 strcpy(t->name, "Tuner");
1154 mutex_lock(&dev->lock);
1155 /* let clients fill in the remainder of this struct */
1156 em28xx_i2c_call_clients(dev, cmd, t);
1157 mutex_unlock(&dev->lock);
1158 em28xx_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x\n", t->signal,
1159 t->afc);
1160 return 0;
1161 }
1162 case VIDIOC_S_TUNER:
1163 {
1164 struct v4l2_tuner *t = arg;
1165
1166 if (0 != t->index)
1167 return -EINVAL;
1168 mutex_lock(&dev->lock);
1169 /* let clients handle this */
1170 em28xx_i2c_call_clients(dev, cmd, t);
1171 mutex_unlock(&dev->lock);
1172 return 0;
1173 }
1174 case VIDIOC_G_FREQUENCY:
1175 {
1176 struct v4l2_frequency *f = arg;
1177
1178 memset(f, 0, sizeof(*f));
1179 f->type = V4L2_TUNER_ANALOG_TV;
1180 f->frequency = dev->ctl_freq;
1181
1182 return 0;
1183 }
1184 case VIDIOC_S_FREQUENCY:
1185 {
1186 struct v4l2_frequency *f = arg;
1187
1188 if (0 != f->tuner)
1189 return -EINVAL;
1190
1191 if (V4L2_TUNER_ANALOG_TV != f->type)
1192 return -EINVAL;
1193
1194 mutex_lock(&dev->lock);
1195 dev->ctl_freq = f->frequency;
1196 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
1197 mutex_unlock(&dev->lock);
1198 return 0;
1199 }
1200 case VIDIOC_CROPCAP:
1201 {
1202 struct v4l2_cropcap *cc = arg;
1203
1204 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1205 return -EINVAL;
1206 cc->bounds.left = 0;
1207 cc->bounds.top = 0;
1208 cc->bounds.width = dev->width;
1209 cc->bounds.height = dev->height;
1210 cc->defrect = cc->bounds;
1211 cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
1212 cc->pixelaspect.denominator = 59;
1213 return 0;
1214 }
1215 case VIDIOC_STREAMON:
1216 {
1217 int *type = arg;
1218
1219 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1220 || dev->io != IO_MMAP)
1221 return -EINVAL;
1222
1223 if (list_empty(&dev->inqueue))
1224 return -EINVAL;
1225
1226 dev->stream = STREAM_ON; /* FIXME: Start video capture here? */
1227
1228 em28xx_videodbg("VIDIOC_STREAMON: starting stream\n");
1229
1230 return 0;
1231 }
1232 case VIDIOC_STREAMOFF:
1233 {
1234 int *type = arg;
1235 int ret;
1236
1237 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1238 || dev->io != IO_MMAP)
1239 return -EINVAL;
1240
1241 if (dev->stream == STREAM_ON) {
1242 em28xx_videodbg ("VIDIOC_STREAMOFF: interrupting stream\n");
1243 if ((ret = em28xx_stream_interrupt(dev)))
1244 return ret;
1245 }
1246 em28xx_empty_framequeues(dev);
1247
1248 return 0;
1249 }
1250 default:
1251 return v4l_compat_translate_ioctl(inode, filp, cmd, arg,
1252 driver_ioctl);
1253 }
1254 return 0;
1255}
1256
1257/*
1258 * em28xx_v4l2_do_ioctl()
1259 * This function is _not_ called directly, but from
1260 * em28xx_v4l2_ioctl. Userspace
1261 * copying is done already, arg is a kernel pointer.
1262 */
1263static int em28xx_video_do_ioctl(struct inode *inode, struct file *filp,
1264 unsigned int cmd, void *arg)
1265{
1266 struct em28xx *dev = filp->private_data;
1267
1268 if (!dev)
1269 return -ENODEV;
1270
1271 if (video_debug > 1)
1272 v4l_print_ioctl(dev->name,cmd);
1273
1274 switch (cmd) {
1275
1276 /* --- capabilities ------------------------------------------ */
1277 case VIDIOC_QUERYCAP:
1278 {
1279 struct v4l2_capability *cap = arg;
1280
1281 memset(cap, 0, sizeof(*cap));
1282 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1283 strlcpy(cap->card, em28xx_boards[dev->model].name,
1284 sizeof(cap->card));
1285 strlcpy(cap->bus_info, dev->udev->dev.bus_id,
1286 sizeof(cap->bus_info));
1287 cap->version = EM28XX_VERSION_CODE;
1288 cap->capabilities =
1289 V4L2_CAP_SLICED_VBI_CAPTURE |
1290 V4L2_CAP_VIDEO_CAPTURE |
1291 V4L2_CAP_AUDIO |
1292 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1293 if (dev->has_tuner)
1294 cap->capabilities |= V4L2_CAP_TUNER;
1295 return 0;
1296 }
1297 /* --- capture ioctls ---------------------------------------- */
1298 case VIDIOC_ENUM_FMT:
1299 {
1300 struct v4l2_fmtdesc *fmtd = arg;
1301
1302 if (fmtd->index != 0)
1303 return -EINVAL;
1304 memset(fmtd, 0, sizeof(*fmtd));
1305 fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1306 strcpy(fmtd->description, "Packed YUY2");
1307 fmtd->pixelformat = V4L2_PIX_FMT_YUYV;
1308 memset(fmtd->reserved, 0, sizeof(fmtd->reserved));
1309 return 0;
1310 }
1311 case VIDIOC_G_FMT:
1312 return em28xx_get_fmt(dev, (struct v4l2_format *) arg);
1313
1314 case VIDIOC_TRY_FMT:
1315 case VIDIOC_S_FMT:
1316 return em28xx_set_fmt(dev, cmd, (struct v4l2_format *)arg);
1317
1318 case VIDIOC_REQBUFS:
1319 {
1320 struct v4l2_requestbuffers *rb = arg;
1321 u32 i;
1322 int ret;
1323
1324 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1325 rb->memory != V4L2_MEMORY_MMAP)
1326 return -EINVAL;
1327
1328 if (dev->io == IO_READ) {
1329 em28xx_videodbg ("method is set to read;"
1330 " close and open the device again to"
1331 " choose the mmap I/O method\n");
1332 return -EINVAL;
1333 }
1334
1335 for (i = 0; i < dev->num_frames; i++)
1336 if (dev->frame[i].vma_use_count) {
1337 em28xx_videodbg ("VIDIOC_REQBUFS failed; previous buffers are still mapped\n");
1338 return -EINVAL;
1339 }
1340
1341 if (dev->stream == STREAM_ON) {
1342 em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream\n");
1343 if ((ret = em28xx_stream_interrupt(dev)))
1344 return ret;
1345 }
1346
1347 em28xx_empty_framequeues(dev);
1348
1349 em28xx_release_buffers(dev);
1350 if (rb->count)
1351 rb->count =
1352 em28xx_request_buffers(dev, rb->count);
1353
1354 dev->frame_current = NULL;
1355
1356 em28xx_videodbg ("VIDIOC_REQBUFS: setting io method to mmap: num bufs %i\n",
1357 rb->count);
1358 dev->io = rb->count ? IO_MMAP : IO_NONE;
1359 return 0;
1360 }
1361 case VIDIOC_QUERYBUF:
1362 {
1363 struct v4l2_buffer *b = arg;
1364
1365 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1366 b->index >= dev->num_frames || dev->io != IO_MMAP)
1367 return -EINVAL;
1368
1369 memcpy(b, &dev->frame[b->index].buf, sizeof(*b));
1370
1371 if (dev->frame[b->index].vma_use_count) {
1372 b->flags |= V4L2_BUF_FLAG_MAPPED;
1373 }
1374 if (dev->frame[b->index].state == F_DONE)
1375 b->flags |= V4L2_BUF_FLAG_DONE;
1376 else if (dev->frame[b->index].state != F_UNUSED)
1377 b->flags |= V4L2_BUF_FLAG_QUEUED;
1378 return 0;
1379 }
1380 case VIDIOC_QBUF:
1381 {
1382 struct v4l2_buffer *b = arg;
1383 unsigned long lock_flags;
1384
1385 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1386 b->index >= dev->num_frames || dev->io != IO_MMAP) {
1387 return -EINVAL;
1388 }
1389
1390 if (dev->frame[b->index].state != F_UNUSED) {
1391 return -EAGAIN;
1392 }
1393 dev->frame[b->index].state = F_QUEUED;
1394
1395 /* add frame to fifo */
1396 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1397 list_add_tail(&dev->frame[b->index].frame,
1398 &dev->inqueue);
1399 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1400
1401 return 0;
1402 }
1403 case VIDIOC_DQBUF:
1404 {
1405 struct v4l2_buffer *b = arg;
1406 struct em28xx_frame_t *f;
1407 unsigned long lock_flags;
1408 int ret = 0;
1409
1410 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1411 || dev->io != IO_MMAP)
1412 return -EINVAL;
1413
1414 if (list_empty(&dev->outqueue)) {
1415 if (dev->stream == STREAM_OFF)
1416 return -EINVAL;
1417 if (filp->f_flags & O_NONBLOCK)
1418 return -EAGAIN;
1419 ret = wait_event_interruptible
1420 (dev->wait_frame,
1421 (!list_empty(&dev->outqueue)) ||
1422 (dev->state & DEV_DISCONNECTED));
1423 if (ret)
1424 return ret;
1425 if (dev->state & DEV_DISCONNECTED)
1426 return -ENODEV;
1427 }
1428
1429 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1430 f = list_entry(dev->outqueue.next,
1431 struct em28xx_frame_t, frame);
1432 list_del(dev->outqueue.next);
1433 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1434
1435 f->state = F_UNUSED;
1436 memcpy(b, &f->buf, sizeof(*b));
1437
1438 if (f->vma_use_count)
1439 b->flags |= V4L2_BUF_FLAG_MAPPED;
1440
1441 return 0;
1442 }
1443 default:
1444 return em28xx_do_ioctl(inode, filp, dev, cmd, arg,
1445 em28xx_video_do_ioctl);
1446 }
1447 return 0;
1448} 1796}
1797EXPORT_SYMBOL(em28xx_unregister_extension);
1449 1798
1450/* 1799struct video_device *em28xx_vdev_init(struct em28xx *dev,
1451 * em28xx_v4l2_ioctl() 1800 const struct video_device *template,
1452 * handle v4l2 ioctl the main action happens in em28xx_v4l2_do_ioctl() 1801 const int type,
1453 */ 1802 const char *type_name)
1454static int em28xx_v4l2_ioctl(struct inode *inode, struct file *filp,
1455 unsigned int cmd, unsigned long arg)
1456{ 1803{
1457 int ret = 0; 1804 struct video_device *vfd;
1458 struct em28xx *dev = filp->private_data;
1459
1460 if (mutex_lock_interruptible(&dev->fileop_lock))
1461 return -ERESTARTSYS;
1462
1463 if (dev->state & DEV_DISCONNECTED) {
1464 em28xx_errdev("v4l2 ioctl: device not present\n");
1465 mutex_unlock(&dev->fileop_lock);
1466 return -ENODEV;
1467 }
1468
1469 if (dev->state & DEV_MISCONFIGURED) {
1470 em28xx_errdev
1471 ("v4l2 ioctl: device is misconfigured; close and open it again\n");
1472 mutex_unlock(&dev->fileop_lock);
1473 return -EIO;
1474 }
1475 1805
1476 ret = video_usercopy(inode, filp, cmd, arg, em28xx_video_do_ioctl); 1806 vfd = video_device_alloc();
1807 if (NULL == vfd)
1808 return NULL;
1809 *vfd = *template;
1810 vfd->minor = -1;
1811 vfd->dev = &dev->udev->dev;
1812 vfd->release = video_device_release;
1813 vfd->type = type;
1477 1814
1478 mutex_unlock(&dev->fileop_lock); 1815 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
1816 dev->name, type_name);
1479 1817
1480 return ret; 1818 return vfd;
1481} 1819}
1482 1820
1483static const struct file_operations em28xx_v4l_fops = {
1484 .owner = THIS_MODULE,
1485 .open = em28xx_v4l2_open,
1486 .release = em28xx_v4l2_close,
1487 .ioctl = em28xx_v4l2_ioctl,
1488 .read = em28xx_v4l2_read,
1489 .poll = em28xx_v4l2_poll,
1490 .mmap = em28xx_v4l2_mmap,
1491 .llseek = no_llseek,
1492 .compat_ioctl = v4l_compat_ioctl32,
1493
1494};
1495
1496/******************************** usb interface *****************************************/
1497 1821
1498/* 1822/*
1499 * em28xx_init_dev() 1823 * em28xx_init_dev()
1500 * allocates and inits the device structs, registers i2c bus and v4l device 1824 * allocates and inits the device structs, registers i2c bus and v4l device
1501 */ 1825 */
1502static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, 1826static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1503 int minor, int model) 1827 int minor)
1504{ 1828{
1829 struct em28xx_ops *ops = NULL;
1505 struct em28xx *dev = *devhandle; 1830 struct em28xx *dev = *devhandle;
1506 int retval = -ENOMEM; 1831 int retval = -ENOMEM;
1507 int errCode, i; 1832 int errCode;
1508 unsigned int maxh, maxw; 1833 unsigned int maxh, maxw;
1509 1834
1510 dev->udev = udev; 1835 dev->udev = udev;
1511 dev->model = model;
1512 mutex_init(&dev->lock); 1836 mutex_init(&dev->lock);
1837 spin_lock_init(&dev->queue_lock);
1513 init_waitqueue_head(&dev->open); 1838 init_waitqueue_head(&dev->open);
1839 init_waitqueue_head(&dev->wait_frame);
1840 init_waitqueue_head(&dev->wait_stream);
1514 1841
1515 dev->em28xx_write_regs = em28xx_write_regs; 1842 dev->em28xx_write_regs = em28xx_write_regs;
1516 dev->em28xx_read_reg = em28xx_read_reg; 1843 dev->em28xx_read_reg = em28xx_read_reg;
1517 dev->em28xx_read_reg_req_len = em28xx_read_reg_req_len; 1844 dev->em28xx_read_reg_req_len = em28xx_read_reg_req_len;
1518 dev->em28xx_write_regs_req = em28xx_write_regs_req; 1845 dev->em28xx_write_regs_req = em28xx_write_regs_req;
1519 dev->em28xx_read_reg_req = em28xx_read_reg_req; 1846 dev->em28xx_read_reg_req = em28xx_read_reg_req;
1520 dev->is_em2800 = em28xx_boards[model].is_em2800; 1847 dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
1521 dev->has_tuner = em28xx_boards[model].has_tuner;
1522 dev->has_msp34xx = em28xx_boards[model].has_msp34xx;
1523 dev->tda9887_conf = em28xx_boards[model].tda9887_conf;
1524 dev->decoder = em28xx_boards[model].decoder;
1525
1526 if (tuner >= 0)
1527 dev->tuner_type = tuner;
1528 else
1529 dev->tuner_type = em28xx_boards[model].tuner_type;
1530 1848
1531 dev->video_inputs = em28xx_boards[model].vchannels; 1849 errCode = em28xx_read_reg(dev, CHIPID_REG);
1850 if (errCode >= 0)
1851 em28xx_info("em28xx chip ID = %d\n", errCode);
1532 1852
1533 for (i = 0; i < TVNORMS; i++) 1853 em28xx_pre_card_setup(dev);
1534 if (em28xx_boards[model].norm == tvnorms[i].mode) 1854
1535 break; 1855 errCode = em28xx_config(dev);
1536 if (i == TVNORMS) 1856 if (errCode) {
1537 i = 0; 1857 em28xx_errdev("error configuring device\n");
1858 em28xx_devused &= ~(1<<dev->devno);
1859 kfree(dev);
1860 return -ENOMEM;
1861 }
1862
1863 /* register i2c bus */
1864 em28xx_i2c_register(dev);
1538 1865
1539 dev->tvnorm = &tvnorms[i]; /* set default norm */ 1866 /* Do board specific init and eeprom reading */
1867 em28xx_card_setup(dev);
1540 1868
1541 em28xx_videodbg("tvnorm=%s\n", dev->tvnorm->name); 1869 /* Configure audio */
1870 em28xx_audio_analog_set(dev);
1871
1872 /* configure the device */
1873 em28xx_config_i2c(dev);
1874
1875 /* set default norm */
1876 dev->norm = em28xx_video_template.current_norm;
1542 1877
1543 maxw = norm_maxw(dev); 1878 maxw = norm_maxw(dev);
1544 maxh = norm_maxh(dev); 1879 maxh = norm_maxh(dev);
@@ -1555,138 +1890,110 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1555 dev->vscale = 0; 1890 dev->vscale = 0;
1556 dev->ctl_input = 2; 1891 dev->ctl_input = 2;
1557 1892
1558 /* setup video picture settings for saa7113h */
1559 memset(&dev->vpic, 0, sizeof(dev->vpic));
1560 dev->vpic.colour = 128 << 8;
1561 dev->vpic.hue = 128 << 8;
1562 dev->vpic.brightness = 128 << 8;
1563 dev->vpic.contrast = 192 << 8;
1564 dev->vpic.whiteness = 128 << 8; /* This one isn't used */
1565 dev->vpic.depth = 16;
1566 dev->vpic.palette = VIDEO_PALETTE_YUV422;
1567
1568 em28xx_pre_card_setup(dev);
1569#ifdef CONFIG_MODULES
1570 /* request some modules */
1571 if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114)
1572 request_module("saa7115");
1573 if (dev->decoder == EM28XX_TVP5150)
1574 request_module("tvp5150");
1575 if (dev->has_tuner)
1576 request_module("tuner");
1577#endif
1578 errCode = em28xx_config(dev); 1893 errCode = em28xx_config(dev);
1579 if (errCode) {
1580 em28xx_errdev("error configuring device\n");
1581 em28xx_devused&=~(1<<dev->devno);
1582 kfree(dev);
1583 return -ENOMEM;
1584 }
1585
1586 mutex_lock(&dev->lock);
1587 /* register i2c bus */
1588 em28xx_i2c_register(dev);
1589 1894
1590 /* Do board specific init and eeprom reading */ 1895 list_add_tail(&dev->devlist, &em28xx_devlist);
1591 em28xx_card_setup(dev);
1592 1896
1593 /* configure the device */ 1897 /* allocate and fill video video_device struct */
1594 em28xx_config_i2c(dev); 1898 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template,
1595 1899 VID_TYPE_CAPTURE, "video");
1596 mutex_unlock(&dev->lock);
1597
1598 errCode = em28xx_config(dev);
1599
1600#ifdef CONFIG_MODULES
1601 if (dev->has_msp34xx)
1602 request_module("msp3400");
1603#endif
1604 /* allocate and fill v4l2 device struct */
1605 dev->vdev = video_device_alloc();
1606 if (NULL == dev->vdev) { 1900 if (NULL == dev->vdev) {
1607 em28xx_errdev("cannot allocate video_device.\n"); 1901 em28xx_errdev("cannot allocate video_device.\n");
1608 em28xx_devused&=~(1<<dev->devno); 1902 goto fail_unreg;
1609 kfree(dev);
1610 return -ENOMEM;
1611 }
1612
1613 dev->vbi_dev = video_device_alloc();
1614 if (NULL == dev->vbi_dev) {
1615 em28xx_errdev("cannot allocate video_device.\n");
1616 kfree(dev->vdev);
1617 em28xx_devused&=~(1<<dev->devno);
1618 kfree(dev);
1619 return -ENOMEM;
1620 } 1903 }
1621 1904 if (dev->tuner_type != TUNER_ABSENT)
1622 /* Fills VBI device info */
1623 dev->vbi_dev->type = VFL_TYPE_VBI;
1624 dev->vbi_dev->fops = &em28xx_v4l_fops;
1625 dev->vbi_dev->minor = -1;
1626 dev->vbi_dev->dev = &dev->udev->dev;
1627 dev->vbi_dev->release = video_device_release;
1628 snprintf(dev->vbi_dev->name, sizeof(dev->vbi_dev->name), "%s#%d %s",
1629 "em28xx",dev->devno,"vbi");
1630
1631 /* Fills CAPTURE device info */
1632 dev->vdev->type = VID_TYPE_CAPTURE;
1633 if (dev->has_tuner)
1634 dev->vdev->type |= VID_TYPE_TUNER; 1905 dev->vdev->type |= VID_TYPE_TUNER;
1635 dev->vdev->fops = &em28xx_v4l_fops;
1636 dev->vdev->minor = -1;
1637 dev->vdev->dev = &dev->udev->dev;
1638 dev->vdev->release = video_device_release;
1639 snprintf(dev->vdev->name, sizeof(dev->vbi_dev->name), "%s#%d %s",
1640 "em28xx",dev->devno,"video");
1641
1642 list_add_tail(&dev->devlist,&em28xx_devlist);
1643 1906
1644 /* register v4l2 device */ 1907 /* register v4l2 video video_device */
1645 mutex_lock(&dev->lock); 1908 retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
1646 if ((retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, 1909 video_nr[dev->devno]);
1647 video_nr[dev->devno]))) { 1910 if (retval) {
1648 em28xx_errdev("unable to register video device (error=%i).\n", 1911 em28xx_errdev("unable to register video device (error=%i).\n",
1649 retval); 1912 retval);
1650 mutex_unlock(&dev->lock); 1913 goto fail_unreg;
1651 list_del(&dev->devlist);
1652 video_device_release(dev->vdev);
1653 em28xx_devused&=~(1<<dev->devno);
1654 kfree(dev);
1655 return -ENODEV;
1656 } 1914 }
1657 1915
1916 /* Allocate and fill vbi video_device struct */
1917 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template,
1918 VFL_TYPE_VBI, "vbi");
1919 /* register v4l2 vbi video_device */
1658 if (video_register_device(dev->vbi_dev, VFL_TYPE_VBI, 1920 if (video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
1659 vbi_nr[dev->devno]) < 0) { 1921 vbi_nr[dev->devno]) < 0) {
1660 printk("unable to register vbi device\n"); 1922 em28xx_errdev("unable to register vbi device\n");
1661 mutex_unlock(&dev->lock); 1923 retval = -ENODEV;
1662 list_del(&dev->devlist); 1924 goto fail_unreg;
1663 video_device_release(dev->vbi_dev);
1664 video_device_release(dev->vdev);
1665 em28xx_devused&=~(1<<dev->devno);
1666 kfree(dev);
1667 return -ENODEV;
1668 } else {
1669 printk("registered VBI\n");
1670 } 1925 }
1671 1926
1927 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
1928 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template,
1929 VFL_TYPE_RADIO, "radio");
1930 if (NULL == dev->radio_dev) {
1931 em28xx_errdev("cannot allocate video_device.\n");
1932 goto fail_unreg;
1933 }
1934 retval = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
1935 radio_nr[dev->devno]);
1936 if (retval < 0) {
1937 em28xx_errdev("can't register radio device\n");
1938 goto fail_unreg;
1939 }
1940 em28xx_info("Registered radio device as /dev/radio%d\n",
1941 dev->radio_dev->minor & 0x1f);
1942 }
1943
1944
1672 if (dev->has_msp34xx) { 1945 if (dev->has_msp34xx) {
1673 /* Send a reset to other chips via gpio */ 1946 /* Send a reset to other chips via gpio */
1674 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1); 1947 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
1675 msleep(3); 1948 msleep(3);
1676 em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1); 1949 em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
1677 msleep(3); 1950 msleep(3);
1678
1679 } 1951 }
1680 video_mux(dev, 0);
1681 1952
1682 mutex_unlock(&dev->lock); 1953 video_mux(dev, 0);
1683 1954
1684 em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n", 1955 em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n",
1685 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN, 1956 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN,
1686 dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN); 1957 dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN);
1687 1958
1959 mutex_lock(&em28xx_extension_devlist_lock);
1960 if (!list_empty(&em28xx_extension_devlist)) {
1961 list_for_each_entry(ops, &em28xx_extension_devlist, next) {
1962 if (ops->id)
1963 ops->init(dev);
1964 }
1965 }
1966 mutex_unlock(&em28xx_extension_devlist_lock);
1967
1688 return 0; 1968 return 0;
1969
1970fail_unreg:
1971 em28xx_release_resources(dev);
1972 mutex_unlock(&dev->lock);
1973 kfree(dev);
1974 return retval;
1975}
1976
1977#if defined(CONFIG_MODULES) && defined(MODULE)
1978static void request_module_async(struct work_struct *work)
1979{
1980 struct em28xx *dev = container_of(work,
1981 struct em28xx, request_module_wk);
1982
1983 if (dev->has_audio_class)
1984 request_module("snd-usb-audio");
1985 else
1986 request_module("em28xx-alsa");
1987}
1988
1989static void request_modules(struct em28xx *dev)
1990{
1991 INIT_WORK(&dev->request_module_wk, request_module_async);
1992 schedule_work(&dev->request_module_wk);
1689} 1993}
1994#else
1995#define request_modules(dev)
1996#endif /* CONFIG_MODULES */
1690 1997
1691/* 1998/*
1692 * em28xx_usb_probe() 1999 * em28xx_usb_probe()
@@ -1700,7 +2007,7 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1700 struct usb_interface *uif; 2007 struct usb_interface *uif;
1701 struct em28xx *dev = NULL; 2008 struct em28xx *dev = NULL;
1702 int retval = -ENODEV; 2009 int retval = -ENODEV;
1703 int model,i,nr,ifnum; 2010 int i, nr, ifnum;
1704 2011
1705 udev = usb_get_dev(interface_to_usbdev(interface)); 2012 udev = usb_get_dev(interface_to_usbdev(interface));
1706 ifnum = interface->altsetting[0].desc.bInterfaceNumber; 2013 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
@@ -1740,8 +2047,6 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1740 return -ENODEV; 2047 return -ENODEV;
1741 } 2048 }
1742 2049
1743 model=id->driver_info;
1744
1745 if (nr >= EM28XX_MAXBOARDS) { 2050 if (nr >= EM28XX_MAXBOARDS) {
1746 printk (DRIVER_NAME ": Supports only %i em28xx boards.\n",EM28XX_MAXBOARDS); 2051 printk (DRIVER_NAME ": Supports only %i em28xx boards.\n",EM28XX_MAXBOARDS);
1747 em28xx_devused&=~(1<<nr); 2052 em28xx_devused&=~(1<<nr);
@@ -1757,7 +2062,20 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1757 } 2062 }
1758 2063
1759 snprintf(dev->name, 29, "em28xx #%d", nr); 2064 snprintf(dev->name, 29, "em28xx #%d", nr);
1760 dev->devno=nr; 2065 dev->devno = nr;
2066 dev->model = id->driver_info;
2067
2068 /* Checks if audio is provided by some interface */
2069 for (i = 0; i < udev->config->desc.bNumInterfaces; i++) {
2070 uif = udev->config->interface[i];
2071 if (uif->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
2072 dev->has_audio_class = 1;
2073 break;
2074 }
2075 }
2076
2077 printk(KERN_INFO DRIVER_NAME " %s usb audio class\n",
2078 dev->has_audio_class ? "Has" : "Doesn't have");
1761 2079
1762 /* compute alternate max packet sizes */ 2080 /* compute alternate max packet sizes */
1763 uif = udev->actconfig->interface[0]; 2081 uif = udev->actconfig->interface[0];
@@ -1784,33 +2102,20 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1784 } 2102 }
1785 2103
1786 if ((card[nr]>=0)&&(card[nr]<em28xx_bcount)) 2104 if ((card[nr]>=0)&&(card[nr]<em28xx_bcount))
1787 model=card[nr]; 2105 dev->model = card[nr];
1788
1789 if ((model==EM2800_BOARD_UNKNOWN)||(model==EM2820_BOARD_UNKNOWN)) {
1790 em28xx_errdev( "Your board has no eeprom inside it and thus can't\n"
1791 "%s: be autodetected. Please pass card=<n> insmod option to\n"
1792 "%s: workaround that. Redirect complaints to the vendor of\n"
1793 "%s: the TV card. Generic type will be used."
1794 "%s: Best regards,\n"
1795 "%s: -- tux\n",
1796 dev->name,dev->name,dev->name,dev->name,dev->name);
1797 em28xx_errdev("%s: Here is a list of valid choices for the card=<n> insmod option:\n",
1798 dev->name);
1799 for (i = 0; i < em28xx_bcount; i++) {
1800 em28xx_errdev(" card=%d -> %s\n", i,
1801 em28xx_boards[i].name);
1802 }
1803 }
1804 2106
1805 /* allocate device struct */ 2107 /* allocate device struct */
1806 retval = em28xx_init_dev(&dev, udev, nr, model); 2108 retval = em28xx_init_dev(&dev, udev, nr);
1807 if (retval) 2109 if (retval)
1808 return retval; 2110 return retval;
1809 2111
1810 em28xx_info("Found %s\n", em28xx_boards[model].name); 2112 em28xx_info("Found %s\n", em28xx_boards[dev->model].name);
1811 2113
1812 /* save our data pointer in this interface device */ 2114 /* save our data pointer in this interface device */
1813 usb_set_intfdata(interface, dev); 2115 usb_set_intfdata(interface, dev);
2116
2117 request_modules(dev);
2118
1814 return 0; 2119 return 0;
1815} 2120}
1816 2121
@@ -1821,18 +2126,20 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1821 */ 2126 */
1822static void em28xx_usb_disconnect(struct usb_interface *interface) 2127static void em28xx_usb_disconnect(struct usb_interface *interface)
1823{ 2128{
1824 struct em28xx *dev = usb_get_intfdata(interface); 2129 struct em28xx *dev;
2130 struct em28xx_ops *ops = NULL;
2131
2132 dev = usb_get_intfdata(interface);
1825 usb_set_intfdata(interface, NULL); 2133 usb_set_intfdata(interface, NULL);
1826 2134
1827 if (!dev) 2135 if (!dev)
1828 return; 2136 return;
1829 2137
1830 down_write(&em28xx_disconnect); 2138 em28xx_info("disconnecting %s\n", dev->vdev->name);
1831 2139
2140 /* wait until all current v4l2 io is finished then deallocate resources */
1832 mutex_lock(&dev->lock); 2141 mutex_lock(&dev->lock);
1833 2142
1834 em28xx_info("disconnecting %s\n", dev->vdev->name);
1835
1836 wake_up_interruptible_all(&dev->open); 2143 wake_up_interruptible_all(&dev->open);
1837 2144
1838 if (dev->users) { 2145 if (dev->users) {
@@ -1850,15 +2157,20 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
1850 dev->state |= DEV_DISCONNECTED; 2157 dev->state |= DEV_DISCONNECTED;
1851 em28xx_release_resources(dev); 2158 em28xx_release_resources(dev);
1852 } 2159 }
1853
1854 mutex_unlock(&dev->lock); 2160 mutex_unlock(&dev->lock);
1855 2161
2162 mutex_lock(&em28xx_extension_devlist_lock);
2163 if (!list_empty(&em28xx_extension_devlist)) {
2164 list_for_each_entry(ops, &em28xx_extension_devlist, next) {
2165 ops->fini(dev);
2166 }
2167 }
2168 mutex_unlock(&em28xx_extension_devlist_lock);
2169
1856 if (!dev->users) { 2170 if (!dev->users) {
1857 kfree(dev->alt_max_pkt_size); 2171 kfree(dev->alt_max_pkt_size);
1858 kfree(dev); 2172 kfree(dev);
1859 } 2173 }
1860
1861 up_write(&em28xx_disconnect);
1862} 2174}
1863 2175
1864static struct usb_driver em28xx_usb_driver = { 2176static struct usb_driver em28xx_usb_driver = {
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index d8fcc9e17ac0..f3bad0c1c517 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -25,28 +25,11 @@
25#ifndef _EM28XX_H 25#ifndef _EM28XX_H
26#define _EM28XX_H 26#define _EM28XX_H
27 27
28#include <linux/videodev.h> 28#include <linux/videodev2.h>
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/mutex.h> 30#include <linux/mutex.h>
31#include <media/ir-kbd-i2c.h> 31#include <media/ir-kbd-i2c.h>
32 32
33/* Boards supported by driver */
34
35#define EM2800_BOARD_UNKNOWN 0
36#define EM2820_BOARD_UNKNOWN 1
37#define EM2820_BOARD_TERRATEC_CINERGY_250 2
38#define EM2820_BOARD_PINNACLE_USB_2 3
39#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
40#define EM2820_BOARD_MSI_VOX_USB_2 5
41#define EM2800_BOARD_TERRATEC_CINERGY_200 6
42#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
43#define EM2800_BOARD_KWORLD_USB2800 8
44#define EM2820_BOARD_PINNACLE_DVC_90 9
45#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
46#define EM2880_BOARD_TERRATEC_HYBRID_XS 11
47#define EM2820_BOARD_KWORLD_PVRTV2800RF 12
48#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
49
50#define UNSET -1 33#define UNSET -1
51 34
52/* maximum number of em28xx boards */ 35/* maximum number of em28xx boards */
@@ -148,10 +131,17 @@ enum enum28xx_itype {
148 EM28XX_RADIO, 131 EM28XX_RADIO,
149}; 132};
150 133
134enum em28xx_amux {
135 EM28XX_AMUX_VIDEO,
136 EM28XX_AMUX_LINE_IN,
137 EM28XX_AMUX_AC97_VIDEO,
138 EM28XX_AMUX_AC97_LINE_IN,
139};
140
151struct em28xx_input { 141struct em28xx_input {
152 enum enum28xx_itype type; 142 enum enum28xx_itype type;
153 unsigned int vmux; 143 unsigned int vmux;
154 unsigned int amux; 144 enum em28xx_amux amux;
155}; 145};
156 146
157#define INPUT(nr) (&em28xx_boards[dev->model].input[nr]) 147#define INPUT(nr) (&em28xx_boards[dev->model].input[nr])
@@ -165,19 +155,23 @@ enum em28xx_decoder {
165struct em28xx_board { 155struct em28xx_board {
166 char *name; 156 char *name;
167 int vchannels; 157 int vchannels;
168 int norm;
169 int tuner_type; 158 int tuner_type;
170 159
171 /* i2c flags */ 160 /* i2c flags */
172 unsigned int is_em2800;
173 unsigned int tda9887_conf; 161 unsigned int tda9887_conf;
174 162
175 unsigned int has_tuner:1; 163 unsigned int is_em2800:1;
176 unsigned int has_msp34xx:1; 164 unsigned int has_msp34xx:1;
165 unsigned int mts_firmware:1;
166 unsigned int has_12mhz_i2s:1;
167 unsigned int max_range_640_480:1;
168
169 unsigned int analog_gpio;
177 170
178 enum em28xx_decoder decoder; 171 enum em28xx_decoder decoder;
179 172
180 struct em28xx_input input[MAX_EM28XX_INPUT]; 173 struct em28xx_input input[MAX_EM28XX_INPUT];
174 struct em28xx_input radio;
181}; 175};
182 176
183struct em28xx_eeprom { 177struct em28xx_eeprom {
@@ -201,12 +195,26 @@ enum em28xx_dev_state {
201 DEV_MISCONFIGURED = 0x04, 195 DEV_MISCONFIGURED = 0x04,
202}; 196};
203 197
204/* tvnorms */ 198#define EM28XX_AUDIO_BUFS 5
205struct em28xx_tvnorm { 199#define EM28XX_NUM_AUDIO_PACKETS 64
206 char *name; 200#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */
207 v4l2_std_id id; 201#define EM28XX_CAPTURE_STREAM_EN 1
208 /* mode for saa7113h */ 202#define EM28XX_AUDIO 0x10
209 int mode; 203
204struct em28xx_audio {
205 char name[50];
206 char *transfer_buffer[EM28XX_AUDIO_BUFS];
207 struct urb *urb[EM28XX_AUDIO_BUFS];
208 struct usb_device *udev;
209 unsigned int capture_transfer_done;
210 struct snd_pcm_substream *capture_pcm_substream;
211
212 unsigned int hwptr_done_capture;
213 struct snd_card *sndcard;
214
215 int users, shutdown;
216 enum em28xx_stream_state capture_stream;
217 spinlock_t slock;
210}; 218};
211 219
212/* main device struct */ 220/* main device struct */
@@ -215,12 +223,17 @@ struct em28xx {
215 char name[30]; /* name (including minor) of the device */ 223 char name[30]; /* name (including minor) of the device */
216 int model; /* index in the device_data struct */ 224 int model; /* index in the device_data struct */
217 int devno; /* marks the number of this device */ 225 int devno; /* marks the number of this device */
218 unsigned int is_em2800; 226 unsigned int analog_gpio;
219 int video_inputs; /* number of video inputs */ 227 unsigned int is_em2800:1;
220 struct list_head devlist;
221 unsigned int has_tuner:1;
222 unsigned int has_msp34xx:1; 228 unsigned int has_msp34xx:1;
223 unsigned int has_tda9887:1; 229 unsigned int has_tda9887:1;
230 unsigned int stream_on:1; /* Locks streams */
231 unsigned int has_audio_class:1;
232 unsigned int has_12mhz_i2s:1;
233 unsigned int max_range_640_480:1;
234
235 int video_inputs; /* number of video inputs */
236 struct list_head devlist;
224 237
225 u32 i2s_speed; /* I2S speed for audio digital stream */ 238 u32 i2s_speed; /* I2S speed for audio digital stream */
226 239
@@ -235,8 +248,7 @@ struct em28xx {
235 /* video for linux */ 248 /* video for linux */
236 int users; /* user count for exclusive use */ 249 int users; /* user count for exclusive use */
237 struct video_device *vdev; /* video for linux device struct */ 250 struct video_device *vdev; /* video for linux device struct */
238 struct video_picture vpic; /* picture settings only used to init saa7113h */ 251 v4l2_std_id norm; /* selected tv norm */
239 struct em28xx_tvnorm *tvnorm; /* selected tv norm */
240 int ctl_freq; /* selected frequency */ 252 int ctl_freq; /* selected frequency */
241 unsigned int ctl_input; /* selected input */ 253 unsigned int ctl_input; /* selected input */
242 unsigned int ctl_ainput; /* slected audio input */ 254 unsigned int ctl_ainput; /* slected audio input */
@@ -256,17 +268,27 @@ struct em28xx {
256 int vscale; /* vertical scale factor (see datasheet) */ 268 int vscale; /* vertical scale factor (see datasheet) */
257 int interlaced; /* 1=interlace fileds, 0=just top fileds */ 269 int interlaced; /* 1=interlace fileds, 0=just top fileds */
258 int type; 270 int type;
271 unsigned int video_bytesread; /* Number of bytes read */
272
273 unsigned long hash; /* eeprom hash - for boards with generic ID */
274 unsigned long i2c_hash; /* i2c devicelist hash - for boards with generic ID */
275
276 struct em28xx_audio *adev;
259 277
260 /* states */ 278 /* states */
261 enum em28xx_dev_state state; 279 enum em28xx_dev_state state;
262 enum em28xx_stream_state stream; 280 enum em28xx_stream_state stream;
263 enum em28xx_io_method io; 281 enum em28xx_io_method io;
282
283 struct work_struct request_module_wk;
284
264 /* locks */ 285 /* locks */
265 struct mutex lock, fileop_lock; 286 struct mutex lock;
266 spinlock_t queue_lock; 287 spinlock_t queue_lock;
267 struct list_head inqueue, outqueue; 288 struct list_head inqueue, outqueue;
268 wait_queue_head_t open, wait_frame, wait_stream; 289 wait_queue_head_t open, wait_frame, wait_stream;
269 struct video_device *vbi_dev; 290 struct video_device *vbi_dev;
291 struct video_device *radio_dev;
270 292
271 unsigned char eedata[256]; 293 unsigned char eedata[256];
272 294
@@ -289,16 +311,27 @@ struct em28xx {
289 int (*em28xx_read_reg_req) (struct em28xx * dev, u8 req, u16 reg); 311 int (*em28xx_read_reg_req) (struct em28xx * dev, u8 req, u16 reg);
290}; 312};
291 313
314struct em28xx_fh {
315 struct em28xx *dev;
316 unsigned int stream_on:1; /* Locks streams */
317 int radio;
318};
319
320struct em28xx_ops {
321 struct list_head next;
322 char *name;
323 int id;
324 int (*init)(struct em28xx *);
325 int (*fini)(struct em28xx *);
326};
327
292/* Provided by em28xx-i2c.c */ 328/* Provided by em28xx-i2c.c */
293 329
294void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg); 330void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg);
331void em28xx_do_i2c_scan(struct em28xx *dev);
295int em28xx_i2c_register(struct em28xx *dev); 332int em28xx_i2c_register(struct em28xx *dev);
296int em28xx_i2c_unregister(struct em28xx *dev); 333int em28xx_i2c_unregister(struct em28xx *dev);
297 334
298/* Provided by em28xx-input.c */
299
300void em28xx_set_ir(struct em28xx * dev,struct IR_i2c *ir);
301
302/* Provided by em28xx-core.c */ 335/* Provided by em28xx-core.c */
303 336
304u32 em28xx_request_buffers(struct em28xx *dev, u32 count); 337u32 em28xx_request_buffers(struct em28xx *dev, u32 count);
@@ -314,8 +347,9 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
314int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len); 347int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len);
315int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val, 348int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
316 u8 bitmask); 349 u8 bitmask);
317int em28xx_write_ac97(struct em28xx *dev, u8 reg, u8 * val); 350int em28xx_set_audio_source(struct em28xx *dev);
318int em28xx_audio_analog_set(struct em28xx *dev); 351int em28xx_audio_analog_set(struct em28xx *dev);
352
319int em28xx_colorlevels_set_default(struct em28xx *dev); 353int em28xx_colorlevels_set_default(struct em28xx *dev);
320int em28xx_capture_start(struct em28xx *dev, int start); 354int em28xx_capture_start(struct em28xx *dev, int start);
321int em28xx_outfmt_set_yuv422(struct em28xx *dev); 355int em28xx_outfmt_set_yuv422(struct em28xx *dev);
@@ -324,6 +358,10 @@ int em28xx_init_isoc(struct em28xx *dev);
324void em28xx_uninit_isoc(struct em28xx *dev); 358void em28xx_uninit_isoc(struct em28xx *dev);
325int em28xx_set_alternate(struct em28xx *dev); 359int em28xx_set_alternate(struct em28xx *dev);
326 360
361/* Provided by em28xx-video.c */
362int em28xx_register_extension(struct em28xx_ops *dev);
363void em28xx_unregister_extension(struct em28xx_ops *dev);
364
327/* Provided by em28xx-cards.c */ 365/* Provided by em28xx-cards.c */
328extern int em2800_variant_detect(struct usb_device* udev,int model); 366extern int em2800_variant_detect(struct usb_device* udev,int model);
329extern void em28xx_pre_card_setup(struct em28xx *dev); 367extern void em28xx_pre_card_setup(struct em28xx *dev);
@@ -331,8 +369,20 @@ extern void em28xx_card_setup(struct em28xx *dev);
331extern struct em28xx_board em28xx_boards[]; 369extern struct em28xx_board em28xx_boards[];
332extern struct usb_device_id em28xx_id_table[]; 370extern struct usb_device_id em28xx_id_table[];
333extern const unsigned int em28xx_bcount; 371extern const unsigned int em28xx_bcount;
372void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir);
373
374/* Provided by em28xx-input.c */
375/* TODO: Check if the standard get_key handlers on ir-common can be used */
376int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw);
377int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw);
378int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
379 u32 *ir_raw);
380
381/* em2800 registers */
382#define EM2800_AUDIOSRC_REG 0x08
334 383
335/* em28xx registers */ 384/* em28xx registers */
385#define I2C_CLK_REG 0x06
336#define CHIPID_REG 0x0a 386#define CHIPID_REG 0x0a
337#define USBSUSP_REG 0x0c /* */ 387#define USBSUSP_REG 0x0c /* */
338 388
@@ -384,9 +434,12 @@ extern const unsigned int em28xx_bcount;
384 434
385/* em202 registers */ 435/* em202 registers */
386#define MASTER_AC97 0x02 436#define MASTER_AC97 0x02
437#define LINE_IN_AC97 0x10
387#define VIDEO_AC97 0x14 438#define VIDEO_AC97 0x14
388 439
389/* register settings */ 440/* register settings */
441#define EM2800_AUDIO_SRC_TUNER 0x0d
442#define EM2800_AUDIO_SRC_LINE 0x0c
390#define EM28XX_AUDIO_SRC_TUNER 0xc0 443#define EM28XX_AUDIO_SRC_TUNER 0xc0
391#define EM28XX_AUDIO_SRC_LINE 0x80 444#define EM28XX_AUDIO_SRC_LINE 0x80
392 445
@@ -406,22 +459,6 @@ extern const unsigned int em28xx_bcount;
406 printk(KERN_WARNING "%s: "fmt,\ 459 printk(KERN_WARNING "%s: "fmt,\
407 dev->name , ##arg); } while (0) 460 dev->name , ##arg); } while (0)
408 461
409inline static int em28xx_audio_source(struct em28xx *dev, int input)
410{
411 return em28xx_write_reg_bits(dev, AUDIOSRC_REG, input, 0xc0);
412}
413
414inline static int em28xx_audio_usb_mute(struct em28xx *dev, int mute)
415{
416 return em28xx_write_reg_bits(dev, XCLK_REG, mute ? 0x00 : 0x80, 0x80);
417}
418
419inline static int em28xx_audio_analog_setup(struct em28xx *dev)
420{
421 /* unmute video mixer with default volume level */
422 return em28xx_write_ac97(dev, VIDEO_AC97, "\x08\x08");
423}
424
425inline static int em28xx_compression_disable(struct em28xx *dev) 462inline static int em28xx_compression_disable(struct em28xx *dev)
426{ 463{
427 /* side effect of disabling scaler and mixer */ 464 /* side effect of disabling scaler and mixer */
@@ -497,18 +534,17 @@ inline static int em28xx_gamma_set(struct em28xx *dev, s32 val)
497/*FIXME: maxw should be dependent of alt mode */ 534/*FIXME: maxw should be dependent of alt mode */
498inline static unsigned int norm_maxw(struct em28xx *dev) 535inline static unsigned int norm_maxw(struct em28xx *dev)
499{ 536{
500 switch(dev->model){ 537 if (dev->max_range_640_480)
501 case (EM2820_BOARD_MSI_VOX_USB_2): return(640); 538 return 640;
502 default: return(720); 539 else
503 } 540 return 720;
504} 541}
505 542
506inline static unsigned int norm_maxh(struct em28xx *dev) 543inline static unsigned int norm_maxh(struct em28xx *dev)
507{ 544{
508 switch(dev->model){ 545 if (dev->max_range_640_480)
509 case (EM2820_BOARD_MSI_VOX_USB_2): return(480); 546 return 480;
510 default: return (dev->tvnorm->id & V4L2_STD_625_50) ? 576 : 480; 547 else
511 } 548 return (dev->norm & V4L2_STD_625_50) ? 576 : 480;
512} 549}
513
514#endif 550#endif
diff --git a/drivers/media/video/et61x251/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index d19d73b81ede..06b6a3ae06c4 100644
--- a/drivers/media/video/et61x251/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -227,7 +227,7 @@ int et61x251_write_reg(struct et61x251_device* cam, u8 value, u16 index)
227} 227}
228 228
229 229
230int et61x251_read_reg(struct et61x251_device* cam, u16 index) 230static int et61x251_read_reg(struct et61x251_device* cam, u16 index)
231{ 231{
232 struct usb_device* udev = cam->usbdev; 232 struct usb_device* udev = cam->usbdev;
233 u8* buff = cam->control_buffer; 233 u8* buff = cam->control_buffer;
@@ -269,73 +269,6 @@ et61x251_i2c_wait(struct et61x251_device* cam,
269 269
270 270
271int 271int
272et61x251_i2c_try_read(struct et61x251_device* cam,
273 const struct et61x251_sensor* sensor, u8 address)
274{
275 struct usb_device* udev = cam->usbdev;
276 u8* data = cam->control_buffer;
277 int err = 0, res;
278
279 data[0] = address;
280 data[1] = cam->sensor.i2c_slave_id;
281 data[2] = cam->sensor.rsta | 0x10;
282 data[3] = !(et61x251_read_reg(cam, 0x8b) & 0x02);
283 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
284 0, 0x88, data, 4, ET61X251_CTRL_TIMEOUT);
285 if (res < 0)
286 err += res;
287
288 err += et61x251_i2c_wait(cam, sensor);
289
290 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1,
291 0, 0x80, data, 8, ET61X251_CTRL_TIMEOUT);
292 if (res < 0)
293 err += res;
294
295 if (err)
296 DBG(3, "I2C read failed for %s image sensor", sensor->name);
297
298 PDBGG("I2C read: address 0x%02X, value: 0x%02X", address, data[0]);
299
300 return err ? -1 : (int)data[0];
301}
302
303
304int
305et61x251_i2c_try_write(struct et61x251_device* cam,
306 const struct et61x251_sensor* sensor, u8 address,
307 u8 value)
308{
309 struct usb_device* udev = cam->usbdev;
310 u8* data = cam->control_buffer;
311 int err = 0, res;
312
313 data[0] = address;
314 data[1] = cam->sensor.i2c_slave_id;
315 data[2] = cam->sensor.rsta | 0x12;
316 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
317 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT);
318 if (res < 0)
319 err += res;
320
321 data[0] = value;
322 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
323 0, 0x80, data, 1, ET61X251_CTRL_TIMEOUT);
324 if (res < 0)
325 err += res;
326
327 err += et61x251_i2c_wait(cam, sensor);
328
329 if (err)
330 DBG(3, "I2C write failed for %s image sensor", sensor->name);
331
332 PDBGG("I2C write: address 0x%02X, value: 0x%02X", address, value);
333
334 return err ? -1 : 0;
335}
336
337
338int
339et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2, 272et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2,
340 u8 data3, u8 data4, u8 data5, u8 data6, u8 data7, 273 u8 data3, u8 data4, u8 data5, u8 data6, u8 data7,
341 u8 data8, u8 address) 274 u8 data8, u8 address)
@@ -387,17 +320,6 @@ et61x251_i2c_raw_write(struct et61x251_device* cam, u8 n, u8 data1, u8 data2,
387} 320}
388 321
389 322
390int et61x251_i2c_read(struct et61x251_device* cam, u8 address)
391{
392 return et61x251_i2c_try_read(cam, &cam->sensor, address);
393}
394
395
396int et61x251_i2c_write(struct et61x251_device* cam, u8 address, u8 value)
397{
398 return et61x251_i2c_try_write(cam, &cam->sensor, address, value);
399}
400
401/*****************************************************************************/ 323/*****************************************************************************/
402 324
403static void et61x251_urb_complete(struct urb *urb) 325static void et61x251_urb_complete(struct urb *urb)
@@ -675,6 +597,83 @@ static int et61x251_stream_interrupt(struct et61x251_device* cam)
675/*****************************************************************************/ 597/*****************************************************************************/
676 598
677#ifdef CONFIG_VIDEO_ADV_DEBUG 599#ifdef CONFIG_VIDEO_ADV_DEBUG
600
601static int et61x251_i2c_try_read(struct et61x251_device* cam,
602 const struct et61x251_sensor* sensor,
603 u8 address)
604{
605 struct usb_device* udev = cam->usbdev;
606 u8* data = cam->control_buffer;
607 int err = 0, res;
608
609 data[0] = address;
610 data[1] = cam->sensor.i2c_slave_id;
611 data[2] = cam->sensor.rsta | 0x10;
612 data[3] = !(et61x251_read_reg(cam, 0x8b) & 0x02);
613 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
614 0, 0x88, data, 4, ET61X251_CTRL_TIMEOUT);
615 if (res < 0)
616 err += res;
617
618 err += et61x251_i2c_wait(cam, sensor);
619
620 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00, 0xc1,
621 0, 0x80, data, 8, ET61X251_CTRL_TIMEOUT);
622 if (res < 0)
623 err += res;
624
625 if (err)
626 DBG(3, "I2C read failed for %s image sensor", sensor->name);
627
628 PDBGG("I2C read: address 0x%02X, value: 0x%02X", address, data[0]);
629
630 return err ? -1 : (int)data[0];
631}
632
633
634static int et61x251_i2c_try_write(struct et61x251_device* cam,
635 const struct et61x251_sensor* sensor,
636 u8 address, u8 value)
637{
638 struct usb_device* udev = cam->usbdev;
639 u8* data = cam->control_buffer;
640 int err = 0, res;
641
642 data[0] = address;
643 data[1] = cam->sensor.i2c_slave_id;
644 data[2] = cam->sensor.rsta | 0x12;
645 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
646 0, 0x88, data, 3, ET61X251_CTRL_TIMEOUT);
647 if (res < 0)
648 err += res;
649
650 data[0] = value;
651 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, 0x41,
652 0, 0x80, data, 1, ET61X251_CTRL_TIMEOUT);
653 if (res < 0)
654 err += res;
655
656 err += et61x251_i2c_wait(cam, sensor);
657
658 if (err)
659 DBG(3, "I2C write failed for %s image sensor", sensor->name);
660
661 PDBGG("I2C write: address 0x%02X, value: 0x%02X", address, value);
662
663 return err ? -1 : 0;
664}
665
666static int et61x251_i2c_read(struct et61x251_device* cam, u8 address)
667{
668 return et61x251_i2c_try_read(cam, &cam->sensor, address);
669}
670
671static int et61x251_i2c_write(struct et61x251_device* cam,
672 u8 address, u8 value)
673{
674 return et61x251_i2c_try_write(cam, &cam->sensor, address, value);
675}
676
678static u8 et61x251_strtou8(const char* buff, size_t len, ssize_t* count) 677static u8 et61x251_strtou8(const char* buff, size_t len, ssize_t* count)
679{ 678{
680 char str[5]; 679 char str[5];
diff --git a/drivers/media/video/et61x251/et61x251_sensor.h b/drivers/media/video/et61x251/et61x251_sensor.h
index e14586330623..71a03148cb09 100644
--- a/drivers/media/video/et61x251/et61x251_sensor.h
+++ b/drivers/media/video/et61x251/et61x251_sensor.h
@@ -52,14 +52,6 @@ et61x251_attach_sensor(struct et61x251_device* cam,
52/*****************************************************************************/ 52/*****************************************************************************/
53 53
54extern int et61x251_write_reg(struct et61x251_device*, u8 value, u16 index); 54extern int et61x251_write_reg(struct et61x251_device*, u8 value, u16 index);
55extern int et61x251_read_reg(struct et61x251_device*, u16 index);
56extern int et61x251_i2c_write(struct et61x251_device*, u8 address, u8 value);
57extern int et61x251_i2c_read(struct et61x251_device*, u8 address);
58extern int et61x251_i2c_try_write(struct et61x251_device*,
59 const struct et61x251_sensor*, u8 address,
60 u8 value);
61extern int et61x251_i2c_try_read(struct et61x251_device*,
62 const struct et61x251_sensor*, u8 address);
63extern int et61x251_i2c_raw_write(struct et61x251_device*, u8 n, u8 data1, 55extern int et61x251_i2c_raw_write(struct et61x251_device*, u8 n, u8 data1,
64 u8 data2, u8 data3, u8 data4, u8 data5, 56 u8 data2, u8 data3, u8 data4, u8 data5,
65 u8 data6, u8 data7, u8 data8, u8 address); 57 u8 data6, u8 data7, u8 data8, u8 address);
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 29779d8bf7fb..9851987b95fb 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -398,6 +398,7 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
398 case 0x7a: 398 case 0x7a:
399 case 0x47: 399 case 0x47:
400 case 0x71: 400 case 0x71:
401 case 0x2d:
401 if (adap->id == I2C_HW_B_CX2388x) { 402 if (adap->id == I2C_HW_B_CX2388x) {
402 /* Handled by cx88-input */ 403 /* Handled by cx88-input */
403 name = "CX2388x remote"; 404 name = "CX2388x remote";
@@ -504,7 +505,7 @@ static int ir_probe(struct i2c_adapter *adap)
504 */ 505 */
505 506
506 static const int probe_bttv[] = { 0x1a, 0x18, 0x4b, 0x64, 0x30, -1}; 507 static const int probe_bttv[] = { 0x1a, 0x18, 0x4b, 0x64, 0x30, -1};
507 static const int probe_saa7134[] = { 0x7a, 0x47, 0x71, -1 }; 508 static const int probe_saa7134[] = { 0x7a, 0x47, 0x71, 0x2d, -1 };
508 static const int probe_em28XX[] = { 0x30, 0x47, -1 }; 509 static const int probe_em28XX[] = { 0x30, 0x47, -1 };
509 static const int probe_cx88[] = { 0x18, 0x6b, 0x71, -1 }; 510 static const int probe_cx88[] = { 0x18, 0x6b, 0x71, -1 };
510 static const int probe_cx23885[] = { 0x6b, -1 }; 511 static const int probe_cx23885[] = { 0x6b, -1 };
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index 854cc9c30ca9..270906fc3146 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -3,6 +3,7 @@ config VIDEO_IVTV
3 depends on VIDEO_V4L1 && VIDEO_V4L2 && PCI && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L1 && VIDEO_V4L2 && PCI && I2C && EXPERIMENTAL
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select FW_LOADER 5 select FW_LOADER
6 select VIDEO_IR
6 select VIDEO_TUNER 7 select VIDEO_TUNER
7 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
8 select VIDEO_CX2341X 9 select VIDEO_CX2341X
@@ -12,6 +13,7 @@ config VIDEO_IVTV
12 select VIDEO_SAA7127 13 select VIDEO_SAA7127
13 select VIDEO_TVAUDIO 14 select VIDEO_TVAUDIO
14 select VIDEO_CS53L32A 15 select VIDEO_CS53L32A
16 select VIDEO_M52790
15 select VIDEO_WM8775 17 select VIDEO_WM8775
16 select VIDEO_WM8739 18 select VIDEO_WM8739
17 select VIDEO_VP27SMPX 19 select VIDEO_VP27SMPX
diff --git a/drivers/media/video/ivtv/Makefile b/drivers/media/video/ivtv/Makefile
index e8eefd96d897..a0389014fa88 100644
--- a/drivers/media/video/ivtv/Makefile
+++ b/drivers/media/video/ivtv/Makefile
@@ -6,3 +6,8 @@ ivtv-objs := ivtv-routing.o ivtv-cards.o ivtv-controls.o \
6 6
7obj-$(CONFIG_VIDEO_IVTV) += ivtv.o 7obj-$(CONFIG_VIDEO_IVTV) += ivtv.o
8obj-$(CONFIG_VIDEO_FB_IVTV) += ivtvfb.o 8obj-$(CONFIG_VIDEO_FB_IVTV) += ivtvfb.o
9
10EXTRA_CFLAGS += -Idrivers/media/video
11EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
12EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
13
diff --git a/drivers/media/video/ivtv/ivtv-cards.c b/drivers/media/video/ivtv/ivtv-cards.c
index b6a8be622d3c..f23c6b8d6911 100644
--- a/drivers/media/video/ivtv/ivtv-cards.c
+++ b/drivers/media/video/ivtv/ivtv-cards.c
@@ -23,6 +23,7 @@
23#include "ivtv-i2c.h" 23#include "ivtv-i2c.h"
24 24
25#include <media/msp3400.h> 25#include <media/msp3400.h>
26#include <media/m52790.h>
26#include <media/wm8775.h> 27#include <media/wm8775.h>
27#include <media/cs53l32a.h> 28#include <media/cs53l32a.h>
28#include <media/cx25840.h> 29#include <media/cx25840.h>
@@ -39,6 +40,27 @@
39#define MSP_MONO MSP_INPUT(MSP_IN_MONO, MSP_IN_TUNER1, \ 40#define MSP_MONO MSP_INPUT(MSP_IN_MONO, MSP_IN_TUNER1, \
40 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART) 41 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART)
41 42
43/* usual i2c tuner addresses to probe */
44static struct ivtv_card_tuner_i2c ivtv_i2c_std = {
45 .radio = { I2C_CLIENT_END },
46 .demod = { 0x43, I2C_CLIENT_END },
47 .tv = { 0x61, 0x60, I2C_CLIENT_END },
48};
49
50/* as above, but with possible radio tuner */
51static struct ivtv_card_tuner_i2c ivtv_i2c_radio = {
52 .radio = { 0x60, I2C_CLIENT_END },
53 .demod = { 0x43, I2C_CLIENT_END },
54 .tv = { 0x61, I2C_CLIENT_END },
55};
56
57/* using the tda8290+75a combo */
58static struct ivtv_card_tuner_i2c ivtv_i2c_tda8290 = {
59 .radio = { I2C_CLIENT_END },
60 .demod = { I2C_CLIENT_END },
61 .tv = { 0x4b, I2C_CLIENT_END },
62};
63
42/********************** card configuration *******************************/ 64/********************** card configuration *******************************/
43 65
44/* Please add new PCI IDs to: http://pci-ids.ucw.cz/iii 66/* Please add new PCI IDs to: http://pci-ids.ucw.cz/iii
@@ -72,6 +94,7 @@ static const struct ivtv_card ivtv_card_pvr250 = {
72 { IVTV_CARD_INPUT_LINE_IN2, MSP_SCART3 }, 94 { IVTV_CARD_INPUT_LINE_IN2, MSP_SCART3 },
73 }, 95 },
74 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, MSP_SCART2 }, 96 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, MSP_SCART2 },
97 .i2c = &ivtv_i2c_std,
75}; 98};
76 99
77/* ------------------------------------------------------------------------- */ 100/* ------------------------------------------------------------------------- */
@@ -126,6 +149,7 @@ static const struct ivtv_card ivtv_card_pvr350 = {
126 { IVTV_CARD_INPUT_LINE_IN2, MSP_SCART3 }, 149 { IVTV_CARD_INPUT_LINE_IN2, MSP_SCART3 },
127 }, 150 },
128 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, MSP_SCART2 }, 151 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, MSP_SCART2 },
152 .i2c = &ivtv_i2c_std,
129}; 153};
130 154
131/* PVR-350 V1 boards have a different audio tuner input and use a 155/* PVR-350 V1 boards have a different audio tuner input and use a
@@ -157,6 +181,7 @@ static const struct ivtv_card ivtv_card_pvr350_v1 = {
157 { IVTV_CARD_INPUT_LINE_IN2, MSP_SCART3 }, 181 { IVTV_CARD_INPUT_LINE_IN2, MSP_SCART3 },
158 }, 182 },
159 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, MSP_SCART2 }, 183 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, MSP_SCART2 },
184 .i2c = &ivtv_i2c_std,
160}; 185};
161 186
162/* ------------------------------------------------------------------------- */ 187/* ------------------------------------------------------------------------- */
@@ -192,6 +217,7 @@ static const struct ivtv_card ivtv_card_pvr150 = {
192 CX25840_AUDIO_SERIAL, WM8775_AIN4 }, 217 CX25840_AUDIO_SERIAL, WM8775_AIN4 },
193 /* apparently needed for the IR blaster */ 218 /* apparently needed for the IR blaster */
194 .gpio_init = { .direction = 0x1f01, .initial_value = 0x26f3 }, 219 .gpio_init = { .direction = 0x1f01, .initial_value = 0x26f3 },
220 .i2c = &ivtv_i2c_std,
195}; 221};
196 222
197/* ------------------------------------------------------------------------- */ 223/* ------------------------------------------------------------------------- */
@@ -234,6 +260,7 @@ static const struct ivtv_card ivtv_card_m179 = {
234 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_NTSC }, 260 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_NTSC },
235 }, 261 },
236 .pci_list = ivtv_pci_m179, 262 .pci_list = ivtv_pci_m179,
263 .i2c = &ivtv_i2c_std,
237}; 264};
238 265
239/* ------------------------------------------------------------------------- */ 266/* ------------------------------------------------------------------------- */
@@ -275,6 +302,7 @@ static const struct ivtv_card ivtv_card_mpg600 = {
275 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FQ1286 }, 302 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FQ1286 },
276 }, 303 },
277 .pci_list = ivtv_pci_mpg600, 304 .pci_list = ivtv_pci_mpg600,
305 .i2c = &ivtv_i2c_std,
278}; 306};
279 307
280/* ------------------------------------------------------------------------- */ 308/* ------------------------------------------------------------------------- */
@@ -315,6 +343,7 @@ static const struct ivtv_card ivtv_card_mpg160 = {
315 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FQ1286 }, 343 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FQ1286 },
316 }, 344 },
317 .pci_list = ivtv_pci_mpg160, 345 .pci_list = ivtv_pci_mpg160,
346 .i2c = &ivtv_i2c_std,
318}; 347};
319 348
320/* ------------------------------------------------------------------------- */ 349/* ------------------------------------------------------------------------- */
@@ -350,6 +379,7 @@ static const struct ivtv_card ivtv_card_pg600 = {
350 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FQ1286 }, 379 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FQ1286 },
351 }, 380 },
352 .pci_list = ivtv_pci_pg600, 381 .pci_list = ivtv_pci_pg600,
382 .i2c = &ivtv_i2c_std,
353}; 383};
354 384
355/* ------------------------------------------------------------------------- */ 385/* ------------------------------------------------------------------------- */
@@ -393,6 +423,7 @@ static const struct ivtv_card ivtv_card_avc2410 = {
393 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FM1236_MK3 }, 423 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FM1236_MK3 },
394 }, 424 },
395 .pci_list = ivtv_pci_avc2410, 425 .pci_list = ivtv_pci_avc2410,
426 .i2c = &ivtv_i2c_std,
396}; 427};
397 428
398/* ------------------------------------------------------------------------- */ 429/* ------------------------------------------------------------------------- */
@@ -463,6 +494,7 @@ static const struct ivtv_card ivtv_card_tg5000tv = {
463 { .std = V4L2_STD_525_60, .tuner = TUNER_PHILIPS_FQ1286 }, 494 { .std = V4L2_STD_525_60, .tuner = TUNER_PHILIPS_FQ1286 },
464 }, 495 },
465 .pci_list = ivtv_pci_tg5000tv, 496 .pci_list = ivtv_pci_tg5000tv,
497 .i2c = &ivtv_i2c_std,
466}; 498};
467 499
468/* ------------------------------------------------------------------------- */ 500/* ------------------------------------------------------------------------- */
@@ -493,6 +525,7 @@ static const struct ivtv_card ivtv_card_va2000 = {
493 { .std = V4L2_STD_525_60, .tuner = TUNER_PHILIPS_FQ1286 }, 525 { .std = V4L2_STD_525_60, .tuner = TUNER_PHILIPS_FQ1286 },
494 }, 526 },
495 .pci_list = ivtv_pci_va2000, 527 .pci_list = ivtv_pci_va2000,
528 .i2c = &ivtv_i2c_std,
496}; 529};
497 530
498/* ------------------------------------------------------------------------- */ 531/* ------------------------------------------------------------------------- */
@@ -537,6 +570,7 @@ static const struct ivtv_card ivtv_card_cx23416gyc = {
537 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FM1236_MK3 }, 570 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FM1236_MK3 },
538 }, 571 },
539 .pci_list = ivtv_pci_cx23416gyc, 572 .pci_list = ivtv_pci_cx23416gyc,
573 .i2c = &ivtv_i2c_std,
540}; 574};
541 575
542static const struct ivtv_card ivtv_card_cx23416gyc_nogr = { 576static const struct ivtv_card ivtv_card_cx23416gyc_nogr = {
@@ -567,6 +601,7 @@ static const struct ivtv_card ivtv_card_cx23416gyc_nogr = {
567 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 }, 601 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 },
568 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FM1236_MK3 }, 602 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FM1236_MK3 },
569 }, 603 },
604 .i2c = &ivtv_i2c_std,
570}; 605};
571 606
572static const struct ivtv_card ivtv_card_cx23416gyc_nogrycs = { 607static const struct ivtv_card ivtv_card_cx23416gyc_nogrycs = {
@@ -596,6 +631,7 @@ static const struct ivtv_card ivtv_card_cx23416gyc_nogrycs = {
596 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 }, 631 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 },
597 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FM1236_MK3 }, 632 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FM1236_MK3 },
598 }, 633 },
634 .i2c = &ivtv_i2c_std,
599}; 635};
600 636
601/* ------------------------------------------------------------------------- */ 637/* ------------------------------------------------------------------------- */
@@ -635,6 +671,7 @@ static const struct ivtv_card ivtv_card_gv_mvprx = {
635 { .std = V4L2_STD_525_60, .tuner = TUNER_PANASONIC_VP27 }, 671 { .std = V4L2_STD_525_60, .tuner = TUNER_PANASONIC_VP27 },
636 }, 672 },
637 .pci_list = ivtv_pci_gv_mvprx, 673 .pci_list = ivtv_pci_gv_mvprx,
674 .i2c = &ivtv_i2c_std,
638}; 675};
639 676
640/* ------------------------------------------------------------------------- */ 677/* ------------------------------------------------------------------------- */
@@ -671,6 +708,7 @@ static const struct ivtv_card ivtv_card_gv_mvprx2e = {
671 { .std = V4L2_STD_525_60, .tuner = TUNER_PANASONIC_VP27 }, 708 { .std = V4L2_STD_525_60, .tuner = TUNER_PANASONIC_VP27 },
672 }, 709 },
673 .pci_list = ivtv_pci_gv_mvprx2e, 710 .pci_list = ivtv_pci_gv_mvprx2e,
711 .i2c = &ivtv_i2c_std,
674}; 712};
675 713
676/* ------------------------------------------------------------------------- */ 714/* ------------------------------------------------------------------------- */
@@ -705,6 +743,7 @@ static const struct ivtv_card ivtv_card_gotview_pci_dvd = {
705 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 }, 743 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 },
706 }, 744 },
707 .pci_list = ivtv_pci_gotview_pci_dvd, 745 .pci_list = ivtv_pci_gotview_pci_dvd,
746 .i2c = &ivtv_i2c_std,
708}; 747};
709 748
710/* ------------------------------------------------------------------------- */ 749/* ------------------------------------------------------------------------- */
@@ -743,6 +782,7 @@ static const struct ivtv_card ivtv_card_gotview_pci_dvd2 = {
743 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 }, 782 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 },
744 }, 783 },
745 .pci_list = ivtv_pci_gotview_pci_dvd2, 784 .pci_list = ivtv_pci_gotview_pci_dvd2,
785 .i2c = &ivtv_i2c_std,
746}; 786};
747 787
748/* ------------------------------------------------------------------------- */ 788/* ------------------------------------------------------------------------- */
@@ -778,6 +818,7 @@ static const struct ivtv_card ivtv_card_yuan_mpc622 = {
778 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_TDA8290 }, 818 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_TDA8290 },
779 }, 819 },
780 .pci_list = ivtv_pci_yuan_mpc622, 820 .pci_list = ivtv_pci_yuan_mpc622,
821 .i2c = &ivtv_i2c_tda8290,
781}; 822};
782 823
783/* ------------------------------------------------------------------------- */ 824/* ------------------------------------------------------------------------- */
@@ -819,6 +860,7 @@ static const struct ivtv_card ivtv_card_dctmvtvp1 = {
819 { .std = V4L2_STD_525_60, .tuner = TUNER_PHILIPS_FQ1286 }, 860 { .std = V4L2_STD_525_60, .tuner = TUNER_PHILIPS_FQ1286 },
820 }, 861 },
821 .pci_list = ivtv_pci_dctmvtvp1, 862 .pci_list = ivtv_pci_dctmvtvp1,
863 .i2c = &ivtv_i2c_std,
822}; 864};
823 865
824/* ------------------------------------------------------------------------- */ 866/* ------------------------------------------------------------------------- */
@@ -838,7 +880,7 @@ static const struct ivtv_card ivtv_card_pg600v2 = {
838 .hw_video = IVTV_HW_CX25840, 880 .hw_video = IVTV_HW_CX25840,
839 .hw_audio = IVTV_HW_CX25840, 881 .hw_audio = IVTV_HW_CX25840,
840 .hw_audio_ctrl = IVTV_HW_CX25840, 882 .hw_audio_ctrl = IVTV_HW_CX25840,
841 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER, 883 .hw_all = IVTV_HW_CX25840,
842 .video_inputs = { 884 .video_inputs = {
843 { IVTV_CARD_INPUT_SVIDEO1, 0, 885 { IVTV_CARD_INPUT_SVIDEO1, 0,
844 CX25840_SVIDEO_LUMA3 | CX25840_SVIDEO_CHROMA4 }, 886 CX25840_SVIDEO_LUMA3 | CX25840_SVIDEO_CHROMA4 },
@@ -847,10 +889,8 @@ static const struct ivtv_card ivtv_card_pg600v2 = {
847 .audio_inputs = { 889 .audio_inputs = {
848 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL }, 890 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL },
849 }, 891 },
850 .tuners = {
851 { .std = V4L2_STD_ALL, .tuner = TUNER_XCEIVE_XC3028 },
852 },
853 .pci_list = ivtv_pci_pg600v2, 892 .pci_list = ivtv_pci_pg600v2,
893 .i2c = &ivtv_i2c_std,
854}; 894};
855 895
856/* ------------------------------------------------------------------------- */ 896/* ------------------------------------------------------------------------- */
@@ -871,17 +911,22 @@ static const struct ivtv_card ivtv_card_club3d = {
871 .hw_audio_ctrl = IVTV_HW_CX25840, 911 .hw_audio_ctrl = IVTV_HW_CX25840,
872 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER, 912 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER,
873 .video_inputs = { 913 .video_inputs = {
874 { IVTV_CARD_INPUT_SVIDEO1, 0, 914 { IVTV_CARD_INPUT_VID_TUNER, 0, CX25840_COMPOSITE2 },
915 { IVTV_CARD_INPUT_SVIDEO1, 1,
875 CX25840_SVIDEO_LUMA3 | CX25840_SVIDEO_CHROMA4 }, 916 CX25840_SVIDEO_LUMA3 | CX25840_SVIDEO_CHROMA4 },
876 { IVTV_CARD_INPUT_COMPOSITE1, 0, CX25840_COMPOSITE3 }, 917 { IVTV_CARD_INPUT_COMPOSITE1, 1, CX25840_COMPOSITE3 },
877 }, 918 },
878 .audio_inputs = { 919 .audio_inputs = {
920 { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO5 },
879 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL }, 921 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL },
880 }, 922 },
923 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO5 },
924 .gpio_init = { .direction = 0x1000, .initial_value = 0x1000 }, /* tuner reset */
881 .tuners = { 925 .tuners = {
882 { .std = V4L2_STD_ALL, .tuner = TUNER_XCEIVE_XC3028 }, 926 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
883 }, 927 },
884 .pci_list = ivtv_pci_club3d, 928 .pci_list = ivtv_pci_club3d,
929 .i2c = &ivtv_i2c_std,
885}; 930};
886 931
887/* ------------------------------------------------------------------------- */ 932/* ------------------------------------------------------------------------- */
@@ -900,7 +945,7 @@ static const struct ivtv_card ivtv_card_avertv_mce116 = {
900 .hw_video = IVTV_HW_CX25840, 945 .hw_video = IVTV_HW_CX25840,
901 .hw_audio = IVTV_HW_CX25840, 946 .hw_audio = IVTV_HW_CX25840,
902 .hw_audio_ctrl = IVTV_HW_CX25840, 947 .hw_audio_ctrl = IVTV_HW_CX25840,
903 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER | IVTV_HW_WM8739, 948 .hw_all = IVTV_HW_CX25840 | IVTV_HW_WM8739,
904 .video_inputs = { 949 .video_inputs = {
905 { IVTV_CARD_INPUT_SVIDEO1, 0, CX25840_SVIDEO3 }, 950 { IVTV_CARD_INPUT_SVIDEO1, 0, CX25840_SVIDEO3 },
906 { IVTV_CARD_INPUT_COMPOSITE1, 0, CX25840_COMPOSITE1 }, 951 { IVTV_CARD_INPUT_COMPOSITE1, 0, CX25840_COMPOSITE1 },
@@ -909,10 +954,115 @@ static const struct ivtv_card ivtv_card_avertv_mce116 = {
909 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL, 1 }, 954 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL, 1 },
910 }, 955 },
911 .gpio_init = { .direction = 0xe000, .initial_value = 0x4000 }, /* enable line-in */ 956 .gpio_init = { .direction = 0xe000, .initial_value = 0x4000 }, /* enable line-in */
957 .pci_list = ivtv_pci_avertv_mce116,
958 .i2c = &ivtv_i2c_std,
959};
960
961/* ------------------------------------------------------------------------- */
962
963/* AVerMedia PVR-150 Plus (M113) card */
964
965static const struct ivtv_card_pci_info ivtv_pci_aver_pvr150[] = {
966 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_AVERMEDIA, 0xc035 },
967 { 0, 0, 0 }
968};
969
970static const struct ivtv_card ivtv_card_aver_pvr150 = {
971 .type = IVTV_CARD_AVER_PVR150PLUS,
972 .name = "AVerMedia PVR-150 Plus",
973 .v4l2_capabilities = IVTV_CAP_ENCODER,
974 .hw_video = IVTV_HW_CX25840,
975 .hw_audio = IVTV_HW_CX25840,
976 .hw_audio_ctrl = IVTV_HW_CX25840,
977 .hw_muxer = IVTV_HW_GPIO,
978 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER,
979 .video_inputs = {
980 { IVTV_CARD_INPUT_VID_TUNER, 0, CX25840_COMPOSITE2 },
981 { IVTV_CARD_INPUT_SVIDEO1, 1,
982 CX25840_SVIDEO_LUMA3 | CX25840_SVIDEO_CHROMA4 },
983 { IVTV_CARD_INPUT_COMPOSITE1, 1, CX25840_COMPOSITE1 },
984 },
985 .audio_inputs = {
986 { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO5, 0 },
987 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL, 1 },
988 },
989 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO_SERIAL, 2 },
990 .gpio_init = { .direction = 0x0800, .initial_value = 0 },
991 .gpio_audio_input = { .mask = 0x0800, .tuner = 0, .linein = 0, .radio = 0x0800 },
912 .tuners = { 992 .tuners = {
913 { .std = V4L2_STD_ALL, .tuner = TUNER_XCEIVE_XC3028 }, 993 /* This card has a Partsnic PTI-5NF05 tuner */
994 { .std = V4L2_STD_525_60, .tuner = TUNER_TCL_2002N },
914 }, 995 },
915 .pci_list = ivtv_pci_avertv_mce116, 996 .pci_list = ivtv_pci_aver_pvr150,
997 .i2c = &ivtv_i2c_radio,
998};
999
1000/* ------------------------------------------------------------------------- */
1001
1002/* AVerMedia EZMaker PCI Deluxe card */
1003
1004static const struct ivtv_card_pci_info ivtv_pci_aver_ezmaker[] = {
1005 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_AVERMEDIA, 0xc03f },
1006 { 0, 0, 0 }
1007};
1008
1009static const struct ivtv_card ivtv_card_aver_ezmaker = {
1010 .type = IVTV_CARD_AVER_EZMAKER,
1011 .name = "AVerMedia EZMaker PCI Deluxe",
1012 .v4l2_capabilities = IVTV_CAP_ENCODER,
1013 .hw_video = IVTV_HW_CX25840,
1014 .hw_audio = IVTV_HW_CX25840,
1015 .hw_audio_ctrl = IVTV_HW_CX25840,
1016 .hw_all = IVTV_HW_CX25840 | IVTV_HW_WM8739,
1017 .video_inputs = {
1018 { IVTV_CARD_INPUT_SVIDEO1, 0, CX25840_SVIDEO3 },
1019 { IVTV_CARD_INPUT_COMPOSITE1, 0, CX25840_COMPOSITE1 },
1020 },
1021 .audio_inputs = {
1022 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL, 0 },
1023 },
1024 .gpio_init = { .direction = 0x4000, .initial_value = 0x4000 },
1025 /* Does not have a tuner */
1026 .pci_list = ivtv_pci_aver_ezmaker,
1027};
1028
1029/* ------------------------------------------------------------------------- */
1030
1031/* ASUS Falcon2 */
1032
1033static const struct ivtv_card_pci_info ivtv_pci_asus_falcon2[] = {
1034 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_ASUSTEK, 0x4b66 },
1035 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_ASUSTEK, 0x462e },
1036 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_ASUSTEK, 0x4b2e },
1037 { 0, 0, 0 }
1038};
1039
1040static const struct ivtv_card ivtv_card_asus_falcon2 = {
1041 .type = IVTV_CARD_ASUS_FALCON2,
1042 .name = "ASUS Falcon2",
1043 .v4l2_capabilities = IVTV_CAP_ENCODER,
1044 .hw_video = IVTV_HW_CX25840,
1045 .hw_audio = IVTV_HW_CX25840,
1046 .hw_audio_ctrl = IVTV_HW_CX25840,
1047 .hw_muxer = IVTV_HW_M52790,
1048 .hw_all = IVTV_HW_CX25840 | IVTV_HW_M52790 | IVTV_HW_TUNER,
1049 .video_inputs = {
1050 { IVTV_CARD_INPUT_VID_TUNER, 0, CX25840_COMPOSITE2 },
1051 { IVTV_CARD_INPUT_SVIDEO1, 1, CX25840_SVIDEO3 },
1052 { IVTV_CARD_INPUT_COMPOSITE1, 2, CX25840_COMPOSITE2 },
1053 },
1054 .audio_inputs = {
1055 { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO5, M52790_IN_TUNER },
1056 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL,
1057 M52790_IN_V2 | M52790_SW1_YCMIX | M52790_SW2_YCMIX },
1058 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL, M52790_IN_V2 },
1059 },
1060 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO_SERIAL, M52790_IN_TUNER },
1061 .tuners = {
1062 { .std = V4L2_STD_525_60, .tuner = TUNER_PHILIPS_FM1236_MK3 },
1063 },
1064 .pci_list = ivtv_pci_asus_falcon2,
1065 .i2c = &ivtv_i2c_std,
916}; 1066};
917 1067
918static const struct ivtv_card *ivtv_card_list[] = { 1068static const struct ivtv_card *ivtv_card_list[] = {
@@ -937,6 +1087,9 @@ static const struct ivtv_card *ivtv_card_list[] = {
937 &ivtv_card_pg600v2, 1087 &ivtv_card_pg600v2,
938 &ivtv_card_club3d, 1088 &ivtv_card_club3d,
939 &ivtv_card_avertv_mce116, 1089 &ivtv_card_avertv_mce116,
1090 &ivtv_card_asus_falcon2,
1091 &ivtv_card_aver_pvr150,
1092 &ivtv_card_aver_ezmaker,
940 1093
941 /* Variations of standard cards but with the same PCI IDs. 1094 /* Variations of standard cards but with the same PCI IDs.
942 These cards must come last in this list. */ 1095 These cards must come last in this list. */
diff --git a/drivers/media/video/ivtv/ivtv-cards.h b/drivers/media/video/ivtv/ivtv-cards.h
index ff46e5ae8653..191aafdd9968 100644
--- a/drivers/media/video/ivtv/ivtv-cards.h
+++ b/drivers/media/video/ivtv/ivtv-cards.h
@@ -45,7 +45,10 @@
45#define IVTV_CARD_PG600V2 18 /* Yuan PG600V2/GotView PCI DVD Lite */ 45#define IVTV_CARD_PG600V2 18 /* Yuan PG600V2/GotView PCI DVD Lite */
46#define IVTV_CARD_CLUB3D 19 /* Club3D ZAP-TV1x01 */ 46#define IVTV_CARD_CLUB3D 19 /* Club3D ZAP-TV1x01 */
47#define IVTV_CARD_AVERTV_MCE116 20 /* AVerTV MCE 116 Plus */ 47#define IVTV_CARD_AVERTV_MCE116 20 /* AVerTV MCE 116 Plus */
48#define IVTV_CARD_LAST 20 48#define IVTV_CARD_ASUS_FALCON2 21 /* ASUS Falcon2 */
49#define IVTV_CARD_AVER_PVR150PLUS 22 /* AVerMedia PVR-150 Plus */
50#define IVTV_CARD_AVER_EZMAKER 23 /* AVerMedia EZMaker PCI Deluxe */
51#define IVTV_CARD_LAST 23
49 52
50/* Variants of existing cards but with the same PCI IDs. The driver 53/* Variants of existing cards but with the same PCI IDs. The driver
51 detects these based on other device information. 54 detects these based on other device information.
@@ -69,6 +72,7 @@
69#define IVTV_PCI_ID_HAUPPAUGE_ALT1 0x0270 72#define IVTV_PCI_ID_HAUPPAUGE_ALT1 0x0270
70#define IVTV_PCI_ID_HAUPPAUGE_ALT2 0x4070 73#define IVTV_PCI_ID_HAUPPAUGE_ALT2 0x4070
71#define IVTV_PCI_ID_ADAPTEC 0x9005 74#define IVTV_PCI_ID_ADAPTEC 0x9005
75#define IVTV_PCI_ID_ASUSTEK 0x1043
72#define IVTV_PCI_ID_AVERMEDIA 0x1461 76#define IVTV_PCI_ID_AVERMEDIA 0x1461
73#define IVTV_PCI_ID_YUAN1 0x12ab 77#define IVTV_PCI_ID_YUAN1 0x12ab
74#define IVTV_PCI_ID_YUAN2 0xff01 78#define IVTV_PCI_ID_YUAN2 0xff01
@@ -80,7 +84,7 @@
80#define IVTV_PCI_ID_GOTVIEW1 0xffac 84#define IVTV_PCI_ID_GOTVIEW1 0xffac
81#define IVTV_PCI_ID_GOTVIEW2 0xffad 85#define IVTV_PCI_ID_GOTVIEW2 0xffad
82 86
83/* hardware flags */ 87/* hardware flags, no gaps allowed, IVTV_HW_GPIO must always be last */
84#define IVTV_HW_CX25840 (1 << 0) 88#define IVTV_HW_CX25840 (1 << 0)
85#define IVTV_HW_SAA7115 (1 << 1) 89#define IVTV_HW_SAA7115 (1 << 1)
86#define IVTV_HW_SAA7127 (1 << 2) 90#define IVTV_HW_SAA7127 (1 << 2)
@@ -90,12 +94,12 @@
90#define IVTV_HW_CS53L32A (1 << 6) 94#define IVTV_HW_CS53L32A (1 << 6)
91#define IVTV_HW_TVEEPROM (1 << 7) 95#define IVTV_HW_TVEEPROM (1 << 7)
92#define IVTV_HW_SAA7114 (1 << 8) 96#define IVTV_HW_SAA7114 (1 << 8)
93#define IVTV_HW_TVAUDIO (1 << 9) 97#define IVTV_HW_UPD64031A (1 << 9)
94#define IVTV_HW_UPD64031A (1 << 10) 98#define IVTV_HW_UPD6408X (1 << 10)
95#define IVTV_HW_UPD6408X (1 << 11) 99#define IVTV_HW_SAA717X (1 << 11)
96#define IVTV_HW_SAA717X (1 << 12) 100#define IVTV_HW_WM8739 (1 << 12)
97#define IVTV_HW_WM8739 (1 << 13) 101#define IVTV_HW_VP27SMPX (1 << 13)
98#define IVTV_HW_VP27SMPX (1 << 14) 102#define IVTV_HW_M52790 (1 << 14)
99#define IVTV_HW_GPIO (1 << 15) 103#define IVTV_HW_GPIO (1 << 15)
100 104
101#define IVTV_HW_SAA711X (IVTV_HW_SAA7115 | IVTV_HW_SAA7114) 105#define IVTV_HW_SAA711X (IVTV_HW_SAA7115 | IVTV_HW_SAA7114)
@@ -230,6 +234,12 @@ struct ivtv_card_tuner {
230 int tuner; /* tuner ID (from tuner.h) */ 234 int tuner; /* tuner ID (from tuner.h) */
231}; 235};
232 236
237struct ivtv_card_tuner_i2c {
238 unsigned short radio[2];/* radio tuner i2c address to probe */
239 unsigned short demod[2];/* demodulator i2c address to probe */
240 unsigned short tv[4]; /* tv tuner i2c addresses to probe */
241};
242
233/* for card information/parameters */ 243/* for card information/parameters */
234struct ivtv_card { 244struct ivtv_card {
235 int type; 245 int type;
@@ -257,6 +267,7 @@ struct ivtv_card {
257 struct ivtv_gpio_audio_detect gpio_audio_detect; 267 struct ivtv_gpio_audio_detect gpio_audio_detect;
258 268
259 struct ivtv_card_tuner tuners[IVTV_CARD_MAX_TUNERS]; 269 struct ivtv_card_tuner tuners[IVTV_CARD_MAX_TUNERS];
270 struct ivtv_card_tuner_i2c *i2c;
260 271
261 /* list of device and subsystem vendor/devices that 272 /* list of device and subsystem vendor/devices that
262 correspond to this card type. */ 273 correspond to this card type. */
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 6d2dd8764f81..d42f120354e5 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -59,6 +59,7 @@
59#include <media/tveeprom.h> 59#include <media/tveeprom.h>
60#include <media/saa7115.h> 60#include <media/saa7115.h>
61#include <media/v4l2-chip-ident.h> 61#include <media/v4l2-chip-ident.h>
62#include "tuner-xc2028.h"
62 63
63/* var to keep track of the number of array elements in use */ 64/* var to keep track of the number of array elements in use */
64int ivtv_cards_active = 0; 65int ivtv_cards_active = 0;
@@ -185,6 +186,9 @@ MODULE_PARM_DESC(cardtype,
185 "\t\t\t19 = Yuan PG600V2/GotView PCI DVD Lite\n" 186 "\t\t\t19 = Yuan PG600V2/GotView PCI DVD Lite\n"
186 "\t\t\t20 = Club3D ZAP-TV1x01\n" 187 "\t\t\t20 = Club3D ZAP-TV1x01\n"
187 "\t\t\t21 = AverTV MCE 116 Plus\n" 188 "\t\t\t21 = AverTV MCE 116 Plus\n"
189 "\t\t\t22 = ASUS Falcon2\n"
190 "\t\t\t23 = AverMedia PVR-150 Plus\n"
191 "\t\t\t24 = AverMedia EZMaker PCI Deluxe\n"
188 "\t\t\t 0 = Autodetect (default)\n" 192 "\t\t\t 0 = Autodetect (default)\n"
189 "\t\t\t-1 = Ignore this card\n\t\t"); 193 "\t\t\t-1 = Ignore this card\n\t\t");
190MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60"); 194MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60");
@@ -397,6 +401,7 @@ static void ivtv_process_eeprom(struct ivtv *itv)
397 401
398 itv->v4l2_cap = itv->card->v4l2_capabilities; 402 itv->v4l2_cap = itv->card->v4l2_capabilities;
399 itv->card_name = itv->card->name; 403 itv->card_name = itv->card->name;
404 itv->card_i2c = itv->card->i2c;
400 405
401 /* If this is a PVR500 then it should be possible to detect whether it is the 406 /* If this is a PVR500 then it should be possible to detect whether it is the
402 first or second unit by looking at the subsystem device ID: is bit 4 is 407 first or second unit by looking at the subsystem device ID: is bit 4 is
@@ -414,7 +419,14 @@ static void ivtv_process_eeprom(struct ivtv *itv)
414 This detection is needed since the eeprom reports incorrectly that a radio is 419 This detection is needed since the eeprom reports incorrectly that a radio is
415 present on the second unit. */ 420 present on the second unit. */
416 if (tv.model / 1000 == 23) { 421 if (tv.model / 1000 == 23) {
422 static const struct ivtv_card_tuner_i2c ivtv_i2c_radio = {
423 .radio = { 0x60, I2C_CLIENT_END },
424 .demod = { 0x43, I2C_CLIENT_END },
425 .tv = { 0x61, I2C_CLIENT_END },
426 };
427
417 itv->card_name = "WinTV PVR 500"; 428 itv->card_name = "WinTV PVR 500";
429 itv->card_i2c = &ivtv_i2c_radio;
418 if (pci_slot == 8 || pci_slot == 9) { 430 if (pci_slot == 8 || pci_slot == 9) {
419 int is_first = (pci_slot & 1) == 0; 431 int is_first = (pci_slot & 1) == 0;
420 432
@@ -628,10 +640,11 @@ done:
628 IVTV_ERR("Defaulting to %s card\n", itv->card->name); 640 IVTV_ERR("Defaulting to %s card\n", itv->card->name);
629 IVTV_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n"); 641 IVTV_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n");
630 IVTV_ERR("card you have to the ivtv-devel mailinglist (www.ivtvdriver.org)\n"); 642 IVTV_ERR("card you have to the ivtv-devel mailinglist (www.ivtvdriver.org)\n");
631 IVTV_ERR("Prefix your subject line with [UNKNOWN CARD].\n"); 643 IVTV_ERR("Prefix your subject line with [UNKNOWN IVTV CARD].\n");
632 } 644 }
633 itv->v4l2_cap = itv->card->v4l2_capabilities; 645 itv->v4l2_cap = itv->card->v4l2_capabilities;
634 itv->card_name = itv->card->name; 646 itv->card_name = itv->card->name;
647 itv->card_i2c = itv->card->i2c;
635} 648}
636 649
637/* Precondition: the ivtv structure has been memset to 0. Only 650/* Precondition: the ivtv structure has been memset to 0. Only
@@ -695,6 +708,7 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
695 atomic_set(&itv->yuv_info.next_dma_frame, -1); 708 atomic_set(&itv->yuv_info.next_dma_frame, -1);
696 itv->yuv_info.lace_mode = ivtv_yuv_mode; 709 itv->yuv_info.lace_mode = ivtv_yuv_mode;
697 itv->yuv_info.lace_threshold = ivtv_yuv_threshold; 710 itv->yuv_info.lace_threshold = ivtv_yuv_threshold;
711 itv->yuv_info.max_frames_buffered = 3;
698 return 0; 712 return 0;
699} 713}
700 714
@@ -812,75 +826,61 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
812 return 0; 826 return 0;
813} 827}
814 828
815static void ivtv_request_module(struct ivtv *itv, const char *name) 829static u32 ivtv_request_module(struct ivtv *itv, u32 hw,
830 const char *name, u32 id)
816{ 831{
832 if ((hw & id) == 0)
833 return hw;
817 if (request_module(name) != 0) { 834 if (request_module(name) != 0) {
818 IVTV_ERR("Failed to load module %s\n", name); 835 IVTV_ERR("Failed to load module %s\n", name);
819 } else { 836 return hw & ~id;
820 IVTV_DEBUG_INFO("Loaded module %s\n", name);
821 } 837 }
838 IVTV_DEBUG_INFO("Loaded module %s\n", name);
839 return hw;
822} 840}
823 841
824static void ivtv_load_and_init_modules(struct ivtv *itv) 842static void ivtv_load_and_init_modules(struct ivtv *itv)
825{ 843{
826 u32 hw = itv->card->hw_all; 844 u32 hw = itv->card->hw_all;
827 int i; 845 unsigned i;
828 846
829 /* load modules */ 847 /* load modules */
830#ifndef CONFIG_VIDEO_TUNER 848#ifndef CONFIG_VIDEO_TUNER
831 if (hw & IVTV_HW_TUNER) { 849 hw = ivtv_request_module(itv, hw, "tuner", IVTV_HW_TUNER);
832 if (itv->options.tuner == TUNER_XCEIVE_XC3028) {
833 IVTV_INFO("Xceive tuner not yet supported, only composite and S-Video inputs will be available\n");
834 itv->tunerid = 1;
835 }
836 else {
837 ivtv_request_module(itv, "tuner");
838 }
839 }
840#endif 850#endif
841#ifndef CONFIG_VIDEO_CX25840 851#ifndef CONFIG_VIDEO_CX25840
842 if (hw & IVTV_HW_CX25840) 852 hw = ivtv_request_module(itv, hw, "cx25840", IVTV_HW_CX25840);
843 ivtv_request_module(itv, "cx25840");
844#endif 853#endif
845#ifndef CONFIG_VIDEO_SAA711X 854#ifndef CONFIG_VIDEO_SAA711X
846 if (hw & IVTV_HW_SAA711X) 855 hw = ivtv_request_module(itv, hw, "saa7115", IVTV_HW_SAA711X);
847 ivtv_request_module(itv, "saa7115");
848#endif 856#endif
849#ifndef CONFIG_VIDEO_SAA7127 857#ifndef CONFIG_VIDEO_SAA7127
850 if (hw & IVTV_HW_SAA7127) 858 hw = ivtv_request_module(itv, hw, "saa7127", IVTV_HW_SAA7127);
851 ivtv_request_module(itv, "saa7127");
852#endif 859#endif
853 if (hw & IVTV_HW_SAA717X) 860 hw = ivtv_request_module(itv, hw, "saa717x", IVTV_HW_SAA717X);
854 ivtv_request_module(itv, "saa717x");
855#ifndef CONFIG_VIDEO_UPD64031A 861#ifndef CONFIG_VIDEO_UPD64031A
856 if (hw & IVTV_HW_UPD64031A) 862 hw = ivtv_request_module(itv, hw, "upd64031a", IVTV_HW_UPD64031A);
857 ivtv_request_module(itv, "upd64031a");
858#endif 863#endif
859#ifndef CONFIG_VIDEO_UPD64083 864#ifndef CONFIG_VIDEO_UPD64083
860 if (hw & IVTV_HW_UPD6408X) 865 hw = ivtv_request_module(itv, hw, "upd64083", IVTV_HW_UPD6408X);
861 ivtv_request_module(itv, "upd64083");
862#endif 866#endif
863#ifndef CONFIG_VIDEO_MSP3400 867#ifndef CONFIG_VIDEO_MSP3400
864 if (hw & IVTV_HW_MSP34XX) 868 hw = ivtv_request_module(itv, hw, "msp3400", IVTV_HW_MSP34XX);
865 ivtv_request_module(itv, "msp3400");
866#endif 869#endif
867#ifndef CONFIG_VIDEO_VP27SMPX 870#ifndef CONFIG_VIDEO_VP27SMPX
868 if (hw & IVTV_HW_VP27SMPX) 871 hw = ivtv_request_module(itv, hw, "vp27smpx", IVTV_HW_VP27SMPX);
869 ivtv_request_module(itv, "vp27smpx");
870#endif 872#endif
871 if (hw & IVTV_HW_TVAUDIO)
872 ivtv_request_module(itv, "tvaudio");
873#ifndef CONFIG_VIDEO_WM8775 873#ifndef CONFIG_VIDEO_WM8775
874 if (hw & IVTV_HW_WM8775) 874 hw = ivtv_request_module(itv, hw, "wm8775", IVTV_HW_WM8775);
875 ivtv_request_module(itv, "wm8775");
876#endif 875#endif
877#ifndef CONFIG_VIDEO_WM8739 876#ifndef CONFIG_VIDEO_WM8739
878 if (hw & IVTV_HW_WM8739) 877 hw = ivtv_request_module(itv, hw, "wm8739", IVTV_HW_WM8739);
879 ivtv_request_module(itv, "wm8739");
880#endif 878#endif
881#ifndef CONFIG_VIDEO_CS53L32A 879#ifndef CONFIG_VIDEO_CS53L32A
882 if (hw & IVTV_HW_CS53L32A) 880 hw = ivtv_request_module(itv, hw, "cs53l32a", IVTV_HW_CS53L32A);
883 ivtv_request_module(itv, "cs53l32a"); 881#endif
882#ifndef CONFIG_VIDEO_M52790
883 hw = ivtv_request_module(itv, hw, "m52790", IVTV_HW_M52790);
884#endif 884#endif
885 885
886 /* check which i2c devices are actually found */ 886 /* check which i2c devices are actually found */
@@ -889,11 +889,12 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
889 889
890 if (!(device & hw)) 890 if (!(device & hw))
891 continue; 891 continue;
892 if (device == IVTV_HW_GPIO) { 892 if (device == IVTV_HW_GPIO || device == IVTV_HW_TVEEPROM) {
893 /* GPIO is always available */ 893 /* GPIO and TVEEPROM do not use i2c probing */
894 itv->hw_flags |= IVTV_HW_GPIO; 894 itv->hw_flags |= device;
895 continue; 895 continue;
896 } 896 }
897 ivtv_i2c_register(itv, i);
897 if (ivtv_i2c_hw_addr(itv, device) > 0) 898 if (ivtv_i2c_hw_addr(itv, device) > 0)
898 itv->hw_flags |= device; 899 itv->hw_flags |= device;
899 } 900 }
@@ -964,7 +965,6 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
964 const struct pci_device_id *pci_id) 965 const struct pci_device_id *pci_id)
965{ 966{
966 int retval = 0; 967 int retval = 0;
967 int yuv_buf_size;
968 int vbi_buf_size; 968 int vbi_buf_size;
969 struct ivtv *itv; 969 struct ivtv *itv;
970 970
@@ -979,7 +979,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
979 } 979 }
980 980
981 itv = kzalloc(sizeof(struct ivtv), GFP_ATOMIC); 981 itv = kzalloc(sizeof(struct ivtv), GFP_ATOMIC);
982 if (itv == 0) { 982 if (itv == NULL) {
983 spin_unlock(&ivtv_cards_lock); 983 spin_unlock(&ivtv_cards_lock);
984 return -ENOMEM; 984 return -ENOMEM;
985 } 985 }
@@ -1068,9 +1068,6 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1068 IVTV_DEBUG_INFO("Active card count: %d.\n", ivtv_cards_active); 1068 IVTV_DEBUG_INFO("Active card count: %d.\n", ivtv_cards_active);
1069 1069
1070 if (itv->card->hw_all & IVTV_HW_TVEEPROM) { 1070 if (itv->card->hw_all & IVTV_HW_TVEEPROM) {
1071#ifdef CONFIG_VIDEO_TVEEPROM_MODULE
1072 ivtv_request_module(itv, "tveeprom");
1073#endif
1074 /* Based on the model number the cardtype may be changed. 1071 /* Based on the model number the cardtype may be changed.
1075 The PCI IDs are not always reliable. */ 1072 The PCI IDs are not always reliable. */
1076 ivtv_process_eeprom(itv); 1073 ivtv_process_eeprom(itv);
@@ -1111,16 +1108,19 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1111 itv->is_50hz = 1; 1108 itv->is_50hz = 1;
1112 itv->is_out_50hz = 1; 1109 itv->is_out_50hz = 1;
1113 } 1110 }
1111
1112 itv->yuv_info.osd_full_w = 720;
1113 itv->yuv_info.osd_full_h = itv->is_out_50hz ? 576 : 480;
1114 itv->yuv_info.v4l2_src_w = itv->yuv_info.osd_full_w;
1115 itv->yuv_info.v4l2_src_h = itv->yuv_info.osd_full_h;
1116
1114 itv->params.video_gop_size = itv->is_60hz ? 15 : 12; 1117 itv->params.video_gop_size = itv->is_60hz ? 15 : 12;
1115 1118
1116 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_MPG] = 0x08000; 1119 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_MPG] = 0x08000;
1117 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_PCM] = 0x01200; 1120 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_PCM] = 0x01200;
1118 itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_MPG] = 0x10000; 1121 itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_MPG] = 0x10000;
1119 1122 itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_YUV] = 0x10000;
1120 /* 0x15180 == 720 * 480 / 4, 0x19500 == 720 * 576 / 4 */ 1123 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_YUV] = 0x08000;
1121 yuv_buf_size = itv->is_60hz ? 0x15180 : 0x19500;
1122 itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_YUV] = yuv_buf_size / 2;
1123 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_YUV] = yuv_buf_size / 8;
1124 1124
1125 /* Setup VBI Raw Size. Should be big enough to hold PAL. 1125 /* Setup VBI Raw Size. Should be big enough to hold PAL.
1126 It is possible to switch between PAL and NTSC, so we need to 1126 It is possible to switch between PAL and NTSC, so we need to
@@ -1140,13 +1140,26 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1140 if (itv->options.radio > 0) 1140 if (itv->options.radio > 0)
1141 itv->v4l2_cap |= V4L2_CAP_RADIO; 1141 itv->v4l2_cap |= V4L2_CAP_RADIO;
1142 1142
1143 if (itv->options.tuner > -1 && itv->tunerid == 0) { 1143 if (itv->options.tuner > -1) {
1144 struct tuner_setup setup; 1144 struct tuner_setup setup;
1145 1145
1146 setup.addr = ADDR_UNSET; 1146 setup.addr = ADDR_UNSET;
1147 setup.type = itv->options.tuner; 1147 setup.type = itv->options.tuner;
1148 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */ 1148 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
1149 setup.tuner_callback = (setup.type == TUNER_XC2028) ?
1150 ivtv_reset_tuner_gpio : NULL;
1149 ivtv_call_i2c_clients(itv, TUNER_SET_TYPE_ADDR, &setup); 1151 ivtv_call_i2c_clients(itv, TUNER_SET_TYPE_ADDR, &setup);
1152 if (setup.type == TUNER_XC2028) {
1153 static struct xc2028_ctrl ctrl = {
1154 .fname = XC2028_DEFAULT_FIRMWARE,
1155 .max_len = 64,
1156 };
1157 struct v4l2_priv_tun_config cfg = {
1158 .tuner = itv->options.tuner,
1159 .priv = &ctrl,
1160 };
1161 ivtv_call_i2c_clients(itv, TUNER_SET_CONFIG, &cfg);
1162 }
1150 } 1163 }
1151 1164
1152 /* The tuner is fixed to the standard. The other inputs (e.g. S-Video) 1165 /* The tuner is fixed to the standard. The other inputs (e.g. S-Video)
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 49ce14d14a54..536140f0c19e 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -65,7 +65,6 @@
65 65
66#include <linux/ivtv.h> 66#include <linux/ivtv.h>
67 67
68
69/* Memory layout */ 68/* Memory layout */
70#define IVTV_ENCODER_OFFSET 0x00000000 69#define IVTV_ENCODER_OFFSET 0x00000000
71#define IVTV_ENCODER_SIZE 0x00800000 /* Total size is 0x01000000, but only first half is used */ 70#define IVTV_ENCODER_SIZE 0x00800000 /* Total size is 0x01000000, but only first half is used */
@@ -392,6 +391,9 @@ struct yuv_frame_info
392 u32 tru_h; 391 u32 tru_h;
393 u32 offset_y; 392 u32 offset_y;
394 s32 lace_mode; 393 s32 lace_mode;
394 u32 sync_field;
395 u32 delay;
396 u32 interlaced;
395}; 397};
396 398
397#define IVTV_YUV_MODE_INTERLACED 0x00 399#define IVTV_YUV_MODE_INTERLACED 0x00
@@ -403,6 +405,8 @@ struct yuv_frame_info
403#define IVTV_YUV_SYNC_ODD 0x04 405#define IVTV_YUV_SYNC_ODD 0x04
404#define IVTV_YUV_SYNC_MASK 0x04 406#define IVTV_YUV_SYNC_MASK 0x04
405 407
408#define IVTV_YUV_BUFFERS 8
409
406struct yuv_playback_info 410struct yuv_playback_info
407{ 411{
408 u32 reg_2834; 412 u32 reg_2834;
@@ -461,9 +465,10 @@ struct yuv_playback_info
461 u32 osd_vis_w; 465 u32 osd_vis_w;
462 u32 osd_vis_h; 466 u32 osd_vis_h;
463 467
464 int decode_height; 468 u32 osd_full_w;
469 u32 osd_full_h;
465 470
466 int frame_interlaced; 471 int decode_height;
467 472
468 int lace_mode; 473 int lace_mode;
469 int lace_threshold; 474 int lace_threshold;
@@ -475,16 +480,23 @@ struct yuv_playback_info
475 u32 yuv_forced_update; 480 u32 yuv_forced_update;
476 int update_frame; 481 int update_frame;
477 482
478 int sync_field[4]; /* Field to sync on */
479 int field_delay[4]; /* Flag to extend duration of previous frame */
480 u8 fields_lapsed; /* Counter used when delaying a frame */ 483 u8 fields_lapsed; /* Counter used when delaying a frame */
481 484
482 struct yuv_frame_info new_frame_info[4]; 485 struct yuv_frame_info new_frame_info[IVTV_YUV_BUFFERS];
483 struct yuv_frame_info old_frame_info; 486 struct yuv_frame_info old_frame_info;
484 struct yuv_frame_info old_frame_info_args; 487 struct yuv_frame_info old_frame_info_args;
485 488
486 void *blanking_ptr; 489 void *blanking_ptr;
487 dma_addr_t blanking_dmaptr; 490 dma_addr_t blanking_dmaptr;
491
492 int stream_size;
493
494 u8 draw_frame; /* PVR350 buffer to draw into */
495 u8 max_frames_buffered; /* Maximum number of frames to buffer */
496
497 struct v4l2_rect main_rect;
498 u32 v4l2_src_w;
499 u32 v4l2_src_h;
488}; 500};
489 501
490#define IVTV_VBI_FRAMES 32 502#define IVTV_VBI_FRAMES 32
@@ -577,13 +589,13 @@ struct ivtv {
577 struct pci_dev *dev; /* PCI device */ 589 struct pci_dev *dev; /* PCI device */
578 const struct ivtv_card *card; /* card information */ 590 const struct ivtv_card *card; /* card information */
579 const char *card_name; /* full name of the card */ 591 const char *card_name; /* full name of the card */
592 const struct ivtv_card_tuner_i2c *card_i2c; /* i2c addresses to probe for tuner */
580 u8 has_cx23415; /* 1 if it is a cx23415 based card, 0 for cx23416 */ 593 u8 has_cx23415; /* 1 if it is a cx23415 based card, 0 for cx23416 */
581 u8 pvr150_workaround; /* 1 if the cx25840 needs to workaround a PVR150 bug */ 594 u8 pvr150_workaround; /* 1 if the cx25840 needs to workaround a PVR150 bug */
582 u8 nof_inputs; /* number of video inputs */ 595 u8 nof_inputs; /* number of video inputs */
583 u8 nof_audio_inputs; /* number of audio inputs */ 596 u8 nof_audio_inputs; /* number of audio inputs */
584 u32 v4l2_cap; /* V4L2 capabilities of card */ 597 u32 v4l2_cap; /* V4L2 capabilities of card */
585 u32 hw_flags; /* hardware description of the board */ 598 u32 hw_flags; /* hardware description of the board */
586 int tunerid; /* userspace tuner ID for experimental Xceive tuner support */
587 v4l2_std_id tuner_std; /* the norm of the card's tuner (fixed) */ 599 v4l2_std_id tuner_std; /* the norm of the card's tuner (fixed) */
588 /* controlling video decoder function */ 600 /* controlling video decoder function */
589 int (*video_dec_func)(struct ivtv *, unsigned int, void *); 601 int (*video_dec_func)(struct ivtv *, unsigned int, void *);
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index a200a8a95a2d..6fb96f19a866 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -542,6 +542,7 @@ ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t c
542 struct ivtv_open_id *id = filp->private_data; 542 struct ivtv_open_id *id = filp->private_data;
543 struct ivtv *itv = id->itv; 543 struct ivtv *itv = id->itv;
544 struct ivtv_stream *s = &itv->streams[id->type]; 544 struct ivtv_stream *s = &itv->streams[id->type];
545 struct yuv_playback_info *yi = &itv->yuv_info;
545 struct ivtv_buffer *buf; 546 struct ivtv_buffer *buf;
546 struct ivtv_queue q; 547 struct ivtv_queue q;
547 int bytes_written = 0; 548 int bytes_written = 0;
@@ -580,6 +581,24 @@ ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t c
580 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); 581 set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
581 582
582retry: 583retry:
584 /* If possible, just DMA the entire frame - Check the data transfer size
585 since we may get here before the stream has been fully set-up */
586 if (mode == OUT_YUV && s->q_full.length == 0 && itv->dma_data_req_size) {
587 while (count >= itv->dma_data_req_size) {
588 if (!ivtv_yuv_udma_stream_frame (itv, (void *)user_buf)) {
589 bytes_written += itv->dma_data_req_size;
590 user_buf += itv->dma_data_req_size;
591 count -= itv->dma_data_req_size;
592 } else {
593 break;
594 }
595 }
596 if (count == 0) {
597 IVTV_DEBUG_HI_FILE("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused);
598 return bytes_written;
599 }
600 }
601
583 for (;;) { 602 for (;;) {
584 /* Gather buffers */ 603 /* Gather buffers */
585 while (q.length - q.bytesused < count && (buf = ivtv_dequeue(s, &s->q_io))) 604 while (q.length - q.bytesused < count && (buf = ivtv_dequeue(s, &s->q_io)))
@@ -604,9 +623,16 @@ retry:
604 623
605 /* copy user data into buffers */ 624 /* copy user data into buffers */
606 while ((buf = ivtv_dequeue(s, &q))) { 625 while ((buf = ivtv_dequeue(s, &q))) {
607 /* Make sure we really got all the user data */ 626 /* yuv is a pain. Don't copy more data than needed for a single
608 rc = ivtv_buf_copy_from_user(s, buf, user_buf, count); 627 frame, otherwise we lose sync with the incoming stream */
628 if (s->type == IVTV_DEC_STREAM_TYPE_YUV &&
629 yi->stream_size + count > itv->dma_data_req_size)
630 rc = ivtv_buf_copy_from_user(s, buf, user_buf,
631 itv->dma_data_req_size - yi->stream_size);
632 else
633 rc = ivtv_buf_copy_from_user(s, buf, user_buf, count);
609 634
635 /* Make sure we really got all the user data */
610 if (rc < 0) { 636 if (rc < 0) {
611 ivtv_queue_move(s, &q, NULL, &s->q_free, 0); 637 ivtv_queue_move(s, &q, NULL, &s->q_free, 0);
612 return rc; 638 return rc;
@@ -615,6 +641,16 @@ retry:
615 count -= rc; 641 count -= rc;
616 bytes_written += rc; 642 bytes_written += rc;
617 643
644 if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
645 yi->stream_size += rc;
646 /* If we have a complete yuv frame, break loop now */
647 if (yi->stream_size == itv->dma_data_req_size) {
648 ivtv_enqueue(s, buf, &s->q_full);
649 yi->stream_size = 0;
650 break;
651 }
652 }
653
618 if (buf->bytesused != s->buf_size) { 654 if (buf->bytesused != s->buf_size) {
619 /* incomplete, leave in q_io for next time */ 655 /* incomplete, leave in q_io for next time */
620 ivtv_enqueue(s, buf, &s->q_io); 656 ivtv_enqueue(s, buf, &s->q_io);
@@ -642,6 +678,9 @@ retry:
642 if (s->q_full.length >= itv->dma_data_req_size) { 678 if (s->q_full.length >= itv->dma_data_req_size) {
643 int got_sig; 679 int got_sig;
644 680
681 if (mode == OUT_YUV)
682 ivtv_yuv_setup_stream_frame(itv);
683
645 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE); 684 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE);
646 while (!(got_sig = signal_pending(current)) && 685 while (!(got_sig = signal_pending(current)) &&
647 test_bit(IVTV_F_S_DMA_PENDING, &s->s_flags)) { 686 test_bit(IVTV_F_S_DMA_PENDING, &s->s_flags)) {
@@ -922,10 +961,15 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
922 } 961 }
923 962
924 /* YUV or MPG Decoding Mode? */ 963 /* YUV or MPG Decoding Mode? */
925 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) 964 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) {
926 clear_bit(IVTV_F_I_DEC_YUV, &itv->i_flags); 965 clear_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
927 else if (s->type == IVTV_DEC_STREAM_TYPE_YUV) 966 } else if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
928 set_bit(IVTV_F_I_DEC_YUV, &itv->i_flags); 967 set_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
968 /* For yuv, we need to know the dma size before we start */
969 itv->dma_data_req_size =
970 1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31);
971 itv->yuv_info.stream_size = 0;
972 }
929 return 0; 973 return 0;
930} 974}
931 975
diff --git a/drivers/media/video/ivtv/ivtv-gpio.c b/drivers/media/video/ivtv/ivtv-gpio.c
index 132fb5f71366..688cd3856685 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.c
+++ b/drivers/media/video/ivtv/ivtv-gpio.c
@@ -22,6 +22,7 @@
22#include "ivtv-driver.h" 22#include "ivtv-driver.h"
23#include "ivtv-cards.h" 23#include "ivtv-cards.h"
24#include "ivtv-gpio.h" 24#include "ivtv-gpio.h"
25#include "tuner-xc2028.h"
25#include <media/tuner.h> 26#include <media/tuner.h>
26 27
27/* 28/*
@@ -122,6 +123,29 @@ void ivtv_reset_ir_gpio(struct ivtv *itv)
122 write_reg(curdir, IVTV_REG_GPIO_DIR); 123 write_reg(curdir, IVTV_REG_GPIO_DIR);
123} 124}
124 125
126/* Xceive tuner reset function */
127int ivtv_reset_tuner_gpio(void *dev, int cmd, int value)
128{
129 struct i2c_algo_bit_data *algo = dev;
130 struct ivtv *itv = algo->data;
131 int curdir, curout;
132
133 if (cmd != XC2028_TUNER_RESET)
134 return 0;
135 IVTV_DEBUG_INFO("Resetting tuner\n");
136 curout = read_reg(IVTV_REG_GPIO_OUT);
137 curdir = read_reg(IVTV_REG_GPIO_DIR);
138 curdir |= (1 << 12); /* GPIO bit 12 */
139
140 curout &= ~(1 << 12);
141 write_reg(curout, IVTV_REG_GPIO_OUT);
142 schedule_timeout_interruptible(msecs_to_jiffies(1));
143
144 curout |= (1 << 12);
145 write_reg(curout, IVTV_REG_GPIO_OUT);
146 schedule_timeout_interruptible(msecs_to_jiffies(1));
147 return 0;
148}
125 149
126void ivtv_gpio_init(struct ivtv *itv) 150void ivtv_gpio_init(struct ivtv *itv)
127{ 151{
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index 36e54f78aa2a..fa5ab1eb1800 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -80,6 +80,7 @@
80#endif /* I2C_ADAP_CLASS_TV_ANALOG */ 80#endif /* I2C_ADAP_CLASS_TV_ANALOG */
81 81
82#define IVTV_CS53L32A_I2C_ADDR 0x11 82#define IVTV_CS53L32A_I2C_ADDR 0x11
83#define IVTV_M52790_I2C_ADDR 0x48
83#define IVTV_CX25840_I2C_ADDR 0x44 84#define IVTV_CX25840_I2C_ADDR 0x44
84#define IVTV_SAA7115_I2C_ADDR 0x21 85#define IVTV_SAA7115_I2C_ADDR 0x21
85#define IVTV_SAA7127_I2C_ADDR 0x44 86#define IVTV_SAA7127_I2C_ADDR 0x44
@@ -91,7 +92,8 @@
91#define IVTV_TEA5767_I2C_ADDR 0x60 92#define IVTV_TEA5767_I2C_ADDR 0x60
92#define IVTV_UPD64031A_I2C_ADDR 0x12 93#define IVTV_UPD64031A_I2C_ADDR 0x12
93#define IVTV_UPD64083_I2C_ADDR 0x5c 94#define IVTV_UPD64083_I2C_ADDR 0x5c
94#define IVTV_TDA985X_I2C_ADDR 0x5b 95#define IVTV_VP27SMPX_I2C_ADDR 0x5b
96#define IVTV_M52790_I2C_ADDR 0x48
95 97
96/* This array should match the IVTV_HW_ defines */ 98/* This array should match the IVTV_HW_ defines */
97static const u8 hw_driverids[] = { 99static const u8 hw_driverids[] = {
@@ -104,18 +106,38 @@ static const u8 hw_driverids[] = {
104 I2C_DRIVERID_CS53L32A, 106 I2C_DRIVERID_CS53L32A,
105 I2C_DRIVERID_TVEEPROM, 107 I2C_DRIVERID_TVEEPROM,
106 I2C_DRIVERID_SAA711X, 108 I2C_DRIVERID_SAA711X,
107 I2C_DRIVERID_TVAUDIO,
108 I2C_DRIVERID_UPD64031A, 109 I2C_DRIVERID_UPD64031A,
109 I2C_DRIVERID_UPD64083, 110 I2C_DRIVERID_UPD64083,
110 I2C_DRIVERID_SAA717X, 111 I2C_DRIVERID_SAA717X,
111 I2C_DRIVERID_WM8739, 112 I2C_DRIVERID_WM8739,
112 I2C_DRIVERID_VP27SMPX, 113 I2C_DRIVERID_VP27SMPX,
114 I2C_DRIVERID_M52790,
115 0 /* IVTV_HW_GPIO dummy driver ID */
116};
117
118/* This array should match the IVTV_HW_ defines */
119static const u8 hw_addrs[] = {
120 IVTV_CX25840_I2C_ADDR,
121 IVTV_SAA7115_I2C_ADDR,
122 IVTV_SAA7127_I2C_ADDR,
123 IVTV_MSP3400_I2C_ADDR,
124 0,
125 IVTV_WM8775_I2C_ADDR,
126 IVTV_CS53L32A_I2C_ADDR,
127 0,
128 IVTV_SAA7115_I2C_ADDR,
129 IVTV_UPD64031A_I2C_ADDR,
130 IVTV_UPD64083_I2C_ADDR,
131 IVTV_SAA717x_I2C_ADDR,
132 IVTV_WM8739_I2C_ADDR,
133 IVTV_VP27SMPX_I2C_ADDR,
134 IVTV_M52790_I2C_ADDR,
113 0 /* IVTV_HW_GPIO dummy driver ID */ 135 0 /* IVTV_HW_GPIO dummy driver ID */
114}; 136};
115 137
116/* This array should match the IVTV_HW_ defines */ 138/* This array should match the IVTV_HW_ defines */
117static const char * const hw_drivernames[] = { 139static const char * const hw_drivernames[] = {
118 "cx2584x", 140 "cx25840",
119 "saa7115", 141 "saa7115",
120 "saa7127", 142 "saa7127",
121 "msp3400", 143 "msp3400",
@@ -123,31 +145,67 @@ static const char * const hw_drivernames[] = {
123 "wm8775", 145 "wm8775",
124 "cs53l32a", 146 "cs53l32a",
125 "tveeprom", 147 "tveeprom",
126 "saa7114", 148 "saa7115",
127 "tvaudio",
128 "upd64031a", 149 "upd64031a",
129 "upd64083", 150 "upd64083",
130 "saa717x", 151 "saa717x",
131 "wm8739", 152 "wm8739",
132 "vp27smpx", 153 "vp27smpx",
154 "m52790",
133 "gpio", 155 "gpio",
134}; 156};
135 157
136static int attach_inform(struct i2c_client *client) 158int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
137{ 159{
138 struct ivtv *itv = (struct ivtv *)i2c_get_adapdata(client->adapter); 160 struct i2c_board_info info;
161 struct i2c_client *c;
162 u8 id;
139 int i; 163 int i;
140 164
141 IVTV_DEBUG_I2C("i2c client attach\n"); 165 IVTV_DEBUG_I2C("i2c client register\n");
142 for (i = 0; i < I2C_CLIENTS_MAX; i++) { 166 if (idx >= ARRAY_SIZE(hw_driverids) || hw_driverids[idx] == 0)
143 if (itv->i2c_clients[i] == NULL) { 167 return -1;
144 itv->i2c_clients[i] = client; 168 id = hw_driverids[idx];
145 break; 169 memset(&info, 0, sizeof(info));
146 } 170 strcpy(info.driver_name, hw_drivernames[idx]);
147 } 171 info.addr = hw_addrs[idx];
172 for (i = 0; itv->i2c_clients[i] && i < I2C_CLIENTS_MAX; i++) {}
173
148 if (i == I2C_CLIENTS_MAX) { 174 if (i == I2C_CLIENTS_MAX) {
149 IVTV_ERR("Insufficient room for new I2C client\n"); 175 IVTV_ERR("insufficient room for new I2C client!\n");
176 return -ENOMEM;
150 } 177 }
178
179 if (id != I2C_DRIVERID_TUNER) {
180 c = i2c_new_device(&itv->i2c_adap, &info);
181 if (c->driver == NULL)
182 i2c_unregister_device(c);
183 else
184 itv->i2c_clients[i] = c;
185 return itv->i2c_clients[i] ? 0 : -ENODEV;
186 }
187
188 /* special tuner handling */
189 c = i2c_new_probed_device(&itv->i2c_adap, &info, itv->card_i2c->radio);
190 if (c && c->driver == NULL)
191 i2c_unregister_device(c);
192 else if (c)
193 itv->i2c_clients[i++] = c;
194 c = i2c_new_probed_device(&itv->i2c_adap, &info, itv->card_i2c->demod);
195 if (c && c->driver == NULL)
196 i2c_unregister_device(c);
197 else if (c)
198 itv->i2c_clients[i++] = c;
199 c = i2c_new_probed_device(&itv->i2c_adap, &info, itv->card_i2c->tv);
200 if (c && c->driver == NULL)
201 i2c_unregister_device(c);
202 else if (c)
203 itv->i2c_clients[i++] = c;
204 return 0;
205}
206
207static int attach_inform(struct i2c_client *client)
208{
151 return 0; 209 return 0;
152} 210}
153 211
@@ -475,9 +533,6 @@ static struct i2c_adapter ivtv_i2c_adap_hw_template = {
475 .client_register = attach_inform, 533 .client_register = attach_inform,
476 .client_unregister = detach_inform, 534 .client_unregister = detach_inform,
477 .owner = THIS_MODULE, 535 .owner = THIS_MODULE,
478#ifdef I2C_ADAP_CLASS_TV_ANALOG
479 .class = I2C_ADAP_CLASS_TV_ANALOG,
480#endif
481}; 536};
482 537
483static void ivtv_setscl_old(void *data, int state) 538static void ivtv_setscl_old(void *data, int state)
@@ -525,15 +580,12 @@ static int ivtv_getsda_old(void *data)
525/* template for i2c-bit-algo */ 580/* template for i2c-bit-algo */
526static struct i2c_adapter ivtv_i2c_adap_template = { 581static struct i2c_adapter ivtv_i2c_adap_template = {
527 .name = "ivtv i2c driver", 582 .name = "ivtv i2c driver",
528 .id = I2C_HW_B_CX2341X, /* algo-bit is OR'd with this */ 583 .id = I2C_HW_B_CX2341X,
529 .algo = NULL, /* set by i2c-algo-bit */ 584 .algo = NULL, /* set by i2c-algo-bit */
530 .algo_data = NULL, /* filled from template */ 585 .algo_data = NULL, /* filled from template */
531 .client_register = attach_inform, 586 .client_register = attach_inform,
532 .client_unregister = detach_inform, 587 .client_unregister = detach_inform,
533 .owner = THIS_MODULE, 588 .owner = THIS_MODULE,
534#ifdef I2C_ADAP_CLASS_TV_ANALOG
535 .class = I2C_ADAP_CLASS_TV_ANALOG,
536#endif
537}; 589};
538 590
539static const struct i2c_algo_bit_data ivtv_i2c_algo_template = { 591static const struct i2c_algo_bit_data ivtv_i2c_algo_template = {
@@ -558,12 +610,9 @@ int ivtv_call_i2c_client(struct ivtv *itv, int addr, unsigned int cmd, void *arg
558 IVTV_DEBUG_I2C("call_i2c_client addr=%02x\n", addr); 610 IVTV_DEBUG_I2C("call_i2c_client addr=%02x\n", addr);
559 for (i = 0; i < I2C_CLIENTS_MAX; i++) { 611 for (i = 0; i < I2C_CLIENTS_MAX; i++) {
560 client = itv->i2c_clients[i]; 612 client = itv->i2c_clients[i];
561 if (client == NULL) { 613 if (client == NULL || client->driver == NULL ||
562 continue; 614 client->driver->command == NULL)
563 }
564 if (client->driver->command == NULL) {
565 continue; 615 continue;
566 }
567 if (addr == client->addr) { 616 if (addr == client->addr) {
568 retval = client->driver->command(client, cmd, arg); 617 retval = client->driver->command(client, cmd, arg);
569 return retval; 618 return retval;
@@ -584,7 +633,7 @@ static int ivtv_i2c_id_addr(struct ivtv *itv, u32 id)
584 633
585 for (i = 0; i < I2C_CLIENTS_MAX; i++) { 634 for (i = 0; i < I2C_CLIENTS_MAX; i++) {
586 client = itv->i2c_clients[i]; 635 client = itv->i2c_clients[i];
587 if (client == NULL) 636 if (client == NULL || client->driver == NULL)
588 continue; 637 continue;
589 if (id == client->driver->id) { 638 if (id == client->driver->id) {
590 retval = client->addr; 639 retval = client->addr;
@@ -710,6 +759,16 @@ int init_ivtv_i2c(struct ivtv *itv)
710{ 759{
711 IVTV_DEBUG_I2C("i2c init\n"); 760 IVTV_DEBUG_I2C("i2c init\n");
712 761
762 /* Sanity checks for the I2C hardware arrays. They must be the
763 * same size and GPIO must be the last entry.
764 */
765 if (ARRAY_SIZE(hw_driverids) != ARRAY_SIZE(hw_addrs) ||
766 ARRAY_SIZE(hw_drivernames) != ARRAY_SIZE(hw_addrs) ||
767 IVTV_HW_GPIO != (1 << (ARRAY_SIZE(hw_addrs) - 1)) ||
768 hw_driverids[ARRAY_SIZE(hw_addrs) - 1]) {
769 IVTV_ERR("Mismatched I2C hardware arrays\n");
770 return -ENODEV;
771 }
713 if (itv->options.newi2c > 0) { 772 if (itv->options.newi2c > 0) {
714 memcpy(&itv->i2c_adap, &ivtv_i2c_adap_hw_template, 773 memcpy(&itv->i2c_adap, &ivtv_i2c_adap_hw_template,
715 sizeof(struct i2c_adapter)); 774 sizeof(struct i2c_adapter));
@@ -718,9 +777,9 @@ int init_ivtv_i2c(struct ivtv *itv)
718 sizeof(struct i2c_adapter)); 777 sizeof(struct i2c_adapter));
719 memcpy(&itv->i2c_algo, &ivtv_i2c_algo_template, 778 memcpy(&itv->i2c_algo, &ivtv_i2c_algo_template,
720 sizeof(struct i2c_algo_bit_data)); 779 sizeof(struct i2c_algo_bit_data));
721 itv->i2c_algo.data = itv;
722 itv->i2c_adap.algo_data = &itv->i2c_algo;
723 } 780 }
781 itv->i2c_algo.data = itv;
782 itv->i2c_adap.algo_data = &itv->i2c_algo;
724 783
725 sprintf(itv->i2c_adap.name + strlen(itv->i2c_adap.name), " #%d", 784 sprintf(itv->i2c_adap.name + strlen(itv->i2c_adap.name), " #%d",
726 itv->num); 785 itv->num);
diff --git a/drivers/media/video/ivtv/ivtv-i2c.h b/drivers/media/video/ivtv/ivtv-i2c.h
index 987042c09b64..022978cf533d 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.h
+++ b/drivers/media/video/ivtv/ivtv-i2c.h
@@ -33,6 +33,7 @@ int ivtv_i2c_hw(struct ivtv *itv, u32 hw, unsigned int cmd, void *arg);
33int ivtv_i2c_id(struct ivtv *itv, u32 id, unsigned int cmd, void *arg); 33int ivtv_i2c_id(struct ivtv *itv, u32 id, unsigned int cmd, void *arg);
34int ivtv_call_i2c_client(struct ivtv *itv, int addr, unsigned int cmd, void *arg); 34int ivtv_call_i2c_client(struct ivtv *itv, int addr, unsigned int cmd, void *arg);
35void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg); 35void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg);
36int ivtv_i2c_register(struct ivtv *itv, unsigned idx);
36 37
37/* init + register i2c algo-bit adapter */ 38/* init + register i2c algo-bit adapter */
38int init_ivtv_i2c(struct ivtv *itv); 39int init_ivtv_i2c(struct ivtv *itv);
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index fd6826f472e3..edef2a579617 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -372,7 +372,7 @@ static int ivtv_get_fmt(struct ivtv *itv, int streamtype, struct v4l2_format *fm
372 fmt->fmt.pix.height = itv->main_rect.height; 372 fmt->fmt.pix.height = itv->main_rect.height;
373 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 373 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
374 fmt->fmt.pix.field = V4L2_FIELD_INTERLACED; 374 fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
375 if (itv->output_mode == OUT_UDMA_YUV) { 375 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
376 switch (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) { 376 switch (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) {
377 case IVTV_YUV_MODE_INTERLACED: 377 case IVTV_YUV_MODE_INTERLACED:
378 fmt->fmt.pix.field = (itv->yuv_info.lace_mode & IVTV_YUV_SYNC_MASK) ? 378 fmt->fmt.pix.field = (itv->yuv_info.lace_mode & IVTV_YUV_SYNC_MASK) ?
@@ -386,14 +386,13 @@ static int ivtv_get_fmt(struct ivtv *itv, int streamtype, struct v4l2_format *fm
386 break; 386 break;
387 } 387 }
388 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_HM12; 388 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_HM12;
389 fmt->fmt.pix.bytesperline = 720;
390 fmt->fmt.pix.width = itv->yuv_info.v4l2_src_w;
391 fmt->fmt.pix.height = itv->yuv_info.v4l2_src_h;
389 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */ 392 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
390 fmt->fmt.pix.sizeimage = 393 fmt->fmt.pix.sizeimage =
391 fmt->fmt.pix.height * fmt->fmt.pix.width + 394 1080 * ((fmt->fmt.pix.height + 31) & ~31);
392 fmt->fmt.pix.height * (fmt->fmt.pix.width / 2); 395 } else if (streamtype == IVTV_ENC_STREAM_TYPE_YUV) {
393 }
394 else if (itv->output_mode == OUT_YUV ||
395 streamtype == IVTV_ENC_STREAM_TYPE_YUV ||
396 streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
397 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_HM12; 396 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_HM12;
398 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */ 397 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
399 fmt->fmt.pix.sizeimage = 398 fmt->fmt.pix.sizeimage =
@@ -490,6 +489,7 @@ static int ivtv_get_fmt(struct ivtv *itv, int streamtype, struct v4l2_format *fm
490static int ivtv_try_or_set_fmt(struct ivtv *itv, int streamtype, 489static int ivtv_try_or_set_fmt(struct ivtv *itv, int streamtype,
491 struct v4l2_format *fmt, int set_fmt) 490 struct v4l2_format *fmt, int set_fmt)
492{ 491{
492 struct yuv_playback_info *yi = &itv->yuv_info;
493 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; 493 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
494 u16 set; 494 u16 set;
495 495
@@ -505,39 +505,52 @@ static int ivtv_try_or_set_fmt(struct ivtv *itv, int streamtype,
505 r.width = fmt->fmt.pix.width; 505 r.width = fmt->fmt.pix.width;
506 r.height = fmt->fmt.pix.height; 506 r.height = fmt->fmt.pix.height;
507 ivtv_get_fmt(itv, streamtype, fmt); 507 ivtv_get_fmt(itv, streamtype, fmt);
508 if (itv->output_mode != OUT_UDMA_YUV) { 508 fmt->fmt.pix.width = r.width;
509 /* TODO: would setting the rect also be valid for this mode? */ 509 fmt->fmt.pix.height = r.height;
510 fmt->fmt.pix.width = r.width; 510 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
511 fmt->fmt.pix.height = r.height;
512 }
513 if (itv->output_mode == OUT_UDMA_YUV) {
514 /* TODO: add checks for validity */
515 fmt->fmt.pix.field = field; 511 fmt->fmt.pix.field = field;
512 if (fmt->fmt.pix.width < 2)
513 fmt->fmt.pix.width = 2;
514 if (fmt->fmt.pix.width > 720)
515 fmt->fmt.pix.width = 720;
516 if (fmt->fmt.pix.height < 2)
517 fmt->fmt.pix.height = 2;
518 if (fmt->fmt.pix.height > 576)
519 fmt->fmt.pix.height = 576;
516 } 520 }
517 if (set_fmt) { 521 if (set_fmt && streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
518 if (itv->output_mode == OUT_UDMA_YUV) { 522 /* Return now if we already have some frame data */
519 switch (field) { 523 if (yi->stream_size)
520 case V4L2_FIELD_NONE: 524 return -EBUSY;
521 itv->yuv_info.lace_mode = IVTV_YUV_MODE_PROGRESSIVE;
522 break;
523 case V4L2_FIELD_ANY:
524 itv->yuv_info.lace_mode = IVTV_YUV_MODE_AUTO;
525 break;
526 case V4L2_FIELD_INTERLACED_BT:
527 itv->yuv_info.lace_mode =
528 IVTV_YUV_MODE_INTERLACED|IVTV_YUV_SYNC_ODD;
529 break;
530 case V4L2_FIELD_INTERLACED_TB:
531 default:
532 itv->yuv_info.lace_mode = IVTV_YUV_MODE_INTERLACED;
533 break;
534 }
535 itv->yuv_info.lace_sync_field = (itv->yuv_info.lace_mode & IVTV_YUV_SYNC_MASK) == IVTV_YUV_SYNC_EVEN ? 0 : 1;
536 525
537 /* Force update of yuv registers */ 526 yi->v4l2_src_w = r.width;
538 itv->yuv_info.yuv_forced_update = 1; 527 yi->v4l2_src_h = r.height;
539 return 0; 528
529 switch (field) {
530 case V4L2_FIELD_NONE:
531 yi->lace_mode = IVTV_YUV_MODE_PROGRESSIVE;
532 break;
533 case V4L2_FIELD_ANY:
534 yi->lace_mode = IVTV_YUV_MODE_AUTO;
535 break;
536 case V4L2_FIELD_INTERLACED_BT:
537 yi->lace_mode =
538 IVTV_YUV_MODE_INTERLACED|IVTV_YUV_SYNC_ODD;
539 break;
540 case V4L2_FIELD_INTERLACED_TB:
541 default:
542 yi->lace_mode = IVTV_YUV_MODE_INTERLACED;
543 break;
540 } 544 }
545 yi->lace_sync_field = (yi->lace_mode & IVTV_YUV_SYNC_MASK) == IVTV_YUV_SYNC_EVEN ? 0 : 1;
546
547 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags))
548 itv->dma_data_req_size =
549 1080 * ((yi->v4l2_src_h + 31) & ~31);
550
551 /* Force update of yuv registers */
552 yi->yuv_forced_update = 1;
553 return 0;
541 } 554 }
542 return 0; 555 return 0;
543 } 556 }
@@ -660,11 +673,8 @@ static int ivtv_debug_ioctls(struct file *filp, unsigned int cmd, void *arg)
660 chip->ident = V4L2_IDENT_NONE; 673 chip->ident = V4L2_IDENT_NONE;
661 chip->revision = 0; 674 chip->revision = 0;
662 if (reg->match_type == V4L2_CHIP_MATCH_HOST) { 675 if (reg->match_type == V4L2_CHIP_MATCH_HOST) {
663 if (v4l2_chip_match_host(reg->match_type, reg->match_chip)) { 676 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
664 struct v4l2_chip_ident *chip = arg;
665
666 chip->ident = itv->has_cx23415 ? V4L2_IDENT_CX23415 : V4L2_IDENT_CX23416; 677 chip->ident = itv->has_cx23415 ? V4L2_IDENT_CX23415 : V4L2_IDENT_CX23416;
667 }
668 return 0; 678 return 0;
669 } 679 }
670 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER) 680 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
@@ -688,7 +698,7 @@ static int ivtv_debug_ioctls(struct file *filp, unsigned int cmd, void *arg)
688 ivtv_reset_ir_gpio(itv); 698 ivtv_reset_ir_gpio(itv);
689 } 699 }
690 if (val & 0x02) { 700 if (val & 0x02) {
691 itv->video_dec_func(itv, cmd, 0); 701 itv->video_dec_func(itv, cmd, NULL);
692 } 702 }
693 break; 703 break;
694 } 704 }
@@ -703,8 +713,12 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
703{ 713{
704 struct ivtv_open_id *id = NULL; 714 struct ivtv_open_id *id = NULL;
705 u32 data[CX2341X_MBOX_MAX_DATA]; 715 u32 data[CX2341X_MBOX_MAX_DATA];
716 int streamtype = 0;
706 717
707 if (filp) id = (struct ivtv_open_id *)filp->private_data; 718 if (filp) {
719 id = (struct ivtv_open_id *)filp->private_data;
720 streamtype = id->type;
721 }
708 722
709 switch (cmd) { 723 switch (cmd) {
710 case VIDIOC_G_PRIORITY: 724 case VIDIOC_G_PRIORITY:
@@ -822,6 +836,11 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
822 cropcap->bounds.height = itv->is_50hz ? 576 : 480; 836 cropcap->bounds.height = itv->is_50hz ? 576 : 480;
823 cropcap->pixelaspect.numerator = itv->is_50hz ? 59 : 10; 837 cropcap->pixelaspect.numerator = itv->is_50hz ? 59 : 10;
824 cropcap->pixelaspect.denominator = itv->is_50hz ? 54 : 11; 838 cropcap->pixelaspect.denominator = itv->is_50hz ? 54 : 11;
839 } else if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
840 cropcap->bounds.width = itv->yuv_info.osd_full_w;
841 cropcap->bounds.height = itv->yuv_info.osd_full_h;
842 cropcap->pixelaspect.numerator = itv->is_out_50hz ? 59 : 10;
843 cropcap->pixelaspect.denominator = itv->is_out_50hz ? 54 : 11;
825 } else { 844 } else {
826 cropcap->bounds.height = itv->is_out_50hz ? 576 : 480; 845 cropcap->bounds.height = itv->is_out_50hz ? 576 : 480;
827 cropcap->pixelaspect.numerator = itv->is_out_50hz ? 59 : 10; 846 cropcap->pixelaspect.numerator = itv->is_out_50hz ? 59 : 10;
@@ -836,10 +855,15 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
836 855
837 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && 856 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
838 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { 857 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
839 if (!ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4, 858 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
840 crop->c.width, crop->c.height, crop->c.left, crop->c.top)) { 859 itv->yuv_info.main_rect = crop->c;
841 itv->main_rect = crop->c;
842 return 0; 860 return 0;
861 } else {
862 if (!ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
863 crop->c.width, crop->c.height, crop->c.left, crop->c.top)) {
864 itv->main_rect = crop->c;
865 return 0;
866 }
843 } 867 }
844 return -EINVAL; 868 return -EINVAL;
845 } 869 }
@@ -853,7 +877,10 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
853 877
854 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && 878 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
855 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { 879 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
856 crop->c = itv->main_rect; 880 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV)
881 crop->c = itv->yuv_info.main_rect;
882 else
883 crop->c = itv->main_rect;
857 return 0; 884 return 0;
858 } 885 }
859 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 886 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -864,7 +891,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
864 case VIDIOC_ENUM_FMT: { 891 case VIDIOC_ENUM_FMT: {
865 static struct v4l2_fmtdesc formats[] = { 892 static struct v4l2_fmtdesc formats[] = {
866 { 0, 0, 0, 893 { 0, 0, 0,
867 "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, 894 "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12,
868 { 0, 0, 0, 0 } 895 { 0, 0, 0, 0 }
869 }, 896 },
870 { 1, 0, V4L2_FMT_FLAG_COMPRESSED, 897 { 1, 0, V4L2_FMT_FLAG_COMPRESSED,
@@ -1043,6 +1070,12 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1043 itv->main_rect.height = itv->params.height; 1070 itv->main_rect.height = itv->params.height;
1044 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4, 1071 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
1045 720, itv->main_rect.height, 0, 0); 1072 720, itv->main_rect.height, 0, 0);
1073 itv->yuv_info.main_rect = itv->main_rect;
1074 if (!itv->osd_info) {
1075 itv->yuv_info.osd_full_w = 720;
1076 itv->yuv_info.osd_full_h =
1077 itv->is_out_50hz ? 576 : 480;
1078 }
1046 } 1079 }
1047 break; 1080 break;
1048 } 1081 }
diff --git a/drivers/media/video/ivtv/ivtv-irq.c b/drivers/media/video/ivtv/ivtv-irq.c
index fd1688e4757d..65604dde9726 100644
--- a/drivers/media/video/ivtv/ivtv-irq.c
+++ b/drivers/media/video/ivtv/ivtv-irq.c
@@ -204,7 +204,7 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
204 s->sg_pending[idx].dst = buf->dma_handle; 204 s->sg_pending[idx].dst = buf->dma_handle;
205 s->sg_pending[idx].src = offset; 205 s->sg_pending[idx].src = offset;
206 s->sg_pending[idx].size = s->buf_size; 206 s->sg_pending[idx].size = s->buf_size;
207 buf->bytesused = (size < s->buf_size) ? size : s->buf_size; 207 buf->bytesused = min(size, s->buf_size);
208 buf->dma_xfer_cnt = s->dma_xfer_cnt; 208 buf->dma_xfer_cnt = s->dma_xfer_cnt;
209 209
210 s->q_predma.bytesused += buf->bytesused; 210 s->q_predma.bytesused += buf->bytesused;
@@ -302,8 +302,11 @@ static void dma_post(struct ivtv_stream *s)
302void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock) 302void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
303{ 303{
304 struct ivtv *itv = s->itv; 304 struct ivtv *itv = s->itv;
305 struct yuv_playback_info *yi = &itv->yuv_info;
306 u8 frame = yi->draw_frame;
307 struct yuv_frame_info *f = &yi->new_frame_info[frame];
305 struct ivtv_buffer *buf; 308 struct ivtv_buffer *buf;
306 u32 y_size = itv->params.height * itv->params.width; 309 u32 y_size = 720 * ((f->src_h + 31) & ~31);
307 u32 uv_offset = offset + IVTV_YUV_BUFFER_UV_OFFSET; 310 u32 uv_offset = offset + IVTV_YUV_BUFFER_UV_OFFSET;
308 int y_done = 0; 311 int y_done = 0;
309 int bytes_written = 0; 312 int bytes_written = 0;
@@ -311,17 +314,42 @@ void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
311 int idx = 0; 314 int idx = 0;
312 315
313 IVTV_DEBUG_HI_DMA("DEC PREPARE DMA %s: %08x %08x\n", s->name, s->q_predma.bytesused, offset); 316 IVTV_DEBUG_HI_DMA("DEC PREPARE DMA %s: %08x %08x\n", s->name, s->q_predma.bytesused, offset);
317
318 /* Insert buffer block for YUV if needed */
319 if (s->type == IVTV_DEC_STREAM_TYPE_YUV && f->offset_y) {
320 if (yi->blanking_dmaptr) {
321 s->sg_pending[idx].src = yi->blanking_dmaptr;
322 s->sg_pending[idx].dst = offset;
323 s->sg_pending[idx].size = 720 * 16;
324 }
325 offset += 720 * 16;
326 idx++;
327 }
328
314 list_for_each_entry(buf, &s->q_predma.list, list) { 329 list_for_each_entry(buf, &s->q_predma.list, list) {
315 /* YUV UV Offset from Y Buffer */ 330 /* YUV UV Offset from Y Buffer */
316 if (s->type == IVTV_DEC_STREAM_TYPE_YUV && !y_done && bytes_written >= y_size) { 331 if (s->type == IVTV_DEC_STREAM_TYPE_YUV && !y_done &&
332 (bytes_written + buf->bytesused) >= y_size) {
333 s->sg_pending[idx].src = buf->dma_handle;
334 s->sg_pending[idx].dst = offset;
335 s->sg_pending[idx].size = y_size - bytes_written;
317 offset = uv_offset; 336 offset = uv_offset;
337 if (s->sg_pending[idx].size != buf->bytesused) {
338 idx++;
339 s->sg_pending[idx].src =
340 buf->dma_handle + s->sg_pending[idx - 1].size;
341 s->sg_pending[idx].dst = offset;
342 s->sg_pending[idx].size =
343 buf->bytesused - s->sg_pending[idx - 1].size;
344 offset += s->sg_pending[idx].size;
345 }
318 y_done = 1; 346 y_done = 1;
347 } else {
348 s->sg_pending[idx].src = buf->dma_handle;
349 s->sg_pending[idx].dst = offset;
350 s->sg_pending[idx].size = buf->bytesused;
351 offset += buf->bytesused;
319 } 352 }
320 s->sg_pending[idx].src = buf->dma_handle;
321 s->sg_pending[idx].dst = offset;
322 s->sg_pending[idx].size = buf->bytesused;
323
324 offset += buf->bytesused;
325 bytes_written += buf->bytesused; 353 bytes_written += buf->bytesused;
326 354
327 /* Sync SG buffers */ 355 /* Sync SG buffers */
@@ -408,7 +436,7 @@ static void ivtv_dma_enc_start(struct ivtv_stream *s)
408 s_vbi->sg_pending_size = 0; 436 s_vbi->sg_pending_size = 0;
409 s_vbi->dma_xfer_cnt++; 437 s_vbi->dma_xfer_cnt++;
410 set_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags); 438 set_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags);
411 IVTV_DEBUG_HI_DMA("include DMA for %s\n", s->name); 439 IVTV_DEBUG_HI_DMA("include DMA for %s\n", s_vbi->name);
412 } 440 }
413 441
414 s->dma_xfer_cnt++; 442 s->dma_xfer_cnt++;
@@ -700,12 +728,15 @@ static void ivtv_irq_dec_data_req(struct ivtv *itv)
700 ivtv_api_get_data(&itv->dec_mbox, IVTV_MBOX_DMA, data); 728 ivtv_api_get_data(&itv->dec_mbox, IVTV_MBOX_DMA, data);
701 729
702 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags)) { 730 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags)) {
703 itv->dma_data_req_size = itv->params.width * itv->params.height * 3 / 2; 731 itv->dma_data_req_size =
704 itv->dma_data_req_offset = data[1] ? data[1] : yuv_offset[0]; 732 1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31);
733 itv->dma_data_req_offset = data[1];
734 if (atomic_read(&itv->yuv_info.next_dma_frame) >= 0)
735 ivtv_yuv_frame_complete(itv);
705 s = &itv->streams[IVTV_DEC_STREAM_TYPE_YUV]; 736 s = &itv->streams[IVTV_DEC_STREAM_TYPE_YUV];
706 } 737 }
707 else { 738 else {
708 itv->dma_data_req_size = data[2] >= 0x10000 ? 0x10000 : data[2]; 739 itv->dma_data_req_size = min_t(u32, data[2], 0x10000);
709 itv->dma_data_req_offset = data[1]; 740 itv->dma_data_req_offset = data[1];
710 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG]; 741 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
711 } 742 }
@@ -715,6 +746,8 @@ static void ivtv_irq_dec_data_req(struct ivtv *itv)
715 set_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags); 746 set_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags);
716 } 747 }
717 else { 748 else {
749 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags))
750 ivtv_yuv_setup_stream_frame(itv);
718 clear_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags); 751 clear_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags);
719 ivtv_queue_move(s, &s->q_full, NULL, &s->q_predma, itv->dma_data_req_size); 752 ivtv_queue_move(s, &s->q_full, NULL, &s->q_predma, itv->dma_data_req_size);
720 ivtv_dma_stream_dec_prepare(s, itv->dma_data_req_offset + IVTV_DECODER_OFFSET, 0); 753 ivtv_dma_stream_dec_prepare(s, itv->dma_data_req_offset + IVTV_DECODER_OFFSET, 0);
@@ -731,24 +764,26 @@ static void ivtv_irq_vsync(struct ivtv *itv)
731 * one vsync per frame. 764 * one vsync per frame.
732 */ 765 */
733 unsigned int frame = read_reg(0x28c0) & 1; 766 unsigned int frame = read_reg(0x28c0) & 1;
767 struct yuv_playback_info *yi = &itv->yuv_info;
734 int last_dma_frame = atomic_read(&itv->yuv_info.next_dma_frame); 768 int last_dma_frame = atomic_read(&itv->yuv_info.next_dma_frame);
769 struct yuv_frame_info *f = &yi->new_frame_info[last_dma_frame];
735 770
736 if (0) IVTV_DEBUG_IRQ("DEC VSYNC\n"); 771 if (0) IVTV_DEBUG_IRQ("DEC VSYNC\n");
737 772
738 if (((frame ^ itv->yuv_info.sync_field[last_dma_frame]) == 0 && 773 if (((frame ^ f->sync_field) == 0 &&
739 ((itv->last_vsync_field & 1) ^ itv->yuv_info.sync_field[last_dma_frame])) || 774 ((itv->last_vsync_field & 1) ^ f->sync_field)) ||
740 (frame != (itv->last_vsync_field & 1) && !itv->yuv_info.frame_interlaced)) { 775 (frame != (itv->last_vsync_field & 1) && !f->interlaced)) {
741 int next_dma_frame = last_dma_frame; 776 int next_dma_frame = last_dma_frame;
742 777
743 if (!(itv->yuv_info.frame_interlaced && itv->yuv_info.field_delay[next_dma_frame] && itv->yuv_info.fields_lapsed < 1)) { 778 if (!(f->interlaced && f->delay && yi->fields_lapsed < 1)) {
744 if (next_dma_frame >= 0 && next_dma_frame != atomic_read(&itv->yuv_info.next_fill_frame)) { 779 if (next_dma_frame >= 0 && next_dma_frame != atomic_read(&yi->next_fill_frame)) {
745 write_reg(yuv_offset[next_dma_frame] >> 4, 0x82c); 780 write_reg(yuv_offset[next_dma_frame] >> 4, 0x82c);
746 write_reg((yuv_offset[next_dma_frame] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x830); 781 write_reg((yuv_offset[next_dma_frame] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x830);
747 write_reg(yuv_offset[next_dma_frame] >> 4, 0x834); 782 write_reg(yuv_offset[next_dma_frame] >> 4, 0x834);
748 write_reg((yuv_offset[next_dma_frame] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x838); 783 write_reg((yuv_offset[next_dma_frame] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x838);
749 next_dma_frame = (next_dma_frame + 1) & 0x3; 784 next_dma_frame = (next_dma_frame + 1) % IVTV_YUV_BUFFERS;
750 atomic_set(&itv->yuv_info.next_dma_frame, next_dma_frame); 785 atomic_set(&yi->next_dma_frame, next_dma_frame);
751 itv->yuv_info.fields_lapsed = -1; 786 yi->fields_lapsed = -1;
752 } 787 }
753 } 788 }
754 } 789 }
@@ -781,20 +816,22 @@ static void ivtv_irq_vsync(struct ivtv *itv)
781 } 816 }
782 817
783 /* Check if we need to update the yuv registers */ 818 /* Check if we need to update the yuv registers */
784 if ((itv->yuv_info.yuv_forced_update || itv->yuv_info.new_frame_info[last_dma_frame].update) && last_dma_frame != -1) { 819 if ((yi->yuv_forced_update || f->update) && last_dma_frame != -1) {
785 if (!itv->yuv_info.new_frame_info[last_dma_frame].update) 820 if (!f->update) {
786 last_dma_frame = (last_dma_frame - 1) & 3; 821 last_dma_frame = (u8)(last_dma_frame - 1) % IVTV_YUV_BUFFERS;
787 822 f = &yi->new_frame_info[last_dma_frame];
788 if (itv->yuv_info.new_frame_info[last_dma_frame].src_w) { 823 }
789 itv->yuv_info.update_frame = last_dma_frame; 824
790 itv->yuv_info.new_frame_info[last_dma_frame].update = 0; 825 if (f->src_w) {
791 itv->yuv_info.yuv_forced_update = 0; 826 yi->update_frame = last_dma_frame;
827 f->update = 0;
828 yi->yuv_forced_update = 0;
792 set_bit(IVTV_F_I_WORK_HANDLER_YUV, &itv->i_flags); 829 set_bit(IVTV_F_I_WORK_HANDLER_YUV, &itv->i_flags);
793 set_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags); 830 set_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags);
794 } 831 }
795 } 832 }
796 833
797 itv->yuv_info.fields_lapsed ++; 834 yi->fields_lapsed++;
798 } 835 }
799} 836}
800 837
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.c b/drivers/media/video/ivtv/ivtv-mailbox.c
index b05436da7136..13a6c374d2db 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.c
+++ b/drivers/media/video/ivtv/ivtv-mailbox.c
@@ -333,7 +333,7 @@ int ivtv_api(struct ivtv *itv, int cmd, int args, u32 data[])
333 return (res == -EBUSY) ? ivtv_api_call(itv, cmd, args, data) : res; 333 return (res == -EBUSY) ? ivtv_api_call(itv, cmd, args, data) : res;
334} 334}
335 335
336int ivtv_api_func(void *priv, int cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]) 336int ivtv_api_func(void *priv, u32 cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA])
337{ 337{
338 return ivtv_api(priv, cmd, in, data); 338 return ivtv_api(priv, cmd, in, data);
339} 339}
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.h b/drivers/media/video/ivtv/ivtv-mailbox.h
index 71a54eef8fc7..6ef12091e3f3 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.h
+++ b/drivers/media/video/ivtv/ivtv-mailbox.h
@@ -28,6 +28,6 @@ void ivtv_api_get_data(struct ivtv_mailbox_data *mbox, int mb, u32 data[]);
28int ivtv_api(struct ivtv *itv, int cmd, int args, u32 data[]); 28int ivtv_api(struct ivtv *itv, int cmd, int args, u32 data[]);
29int ivtv_vapi_result(struct ivtv *itv, u32 data[CX2341X_MBOX_MAX_DATA], int cmd, int args, ...); 29int ivtv_vapi_result(struct ivtv *itv, u32 data[CX2341X_MBOX_MAX_DATA], int cmd, int args, ...);
30int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...); 30int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...);
31int ivtv_api_func(void *priv, int cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]); 31int ivtv_api_func(void *priv, u32 cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]);
32 32
33#endif 33#endif
diff --git a/drivers/media/video/ivtv/ivtv-routing.c b/drivers/media/video/ivtv/ivtv-routing.c
index 398bd33033ed..05564919b57f 100644
--- a/drivers/media/video/ivtv/ivtv-routing.c
+++ b/drivers/media/video/ivtv/ivtv-routing.c
@@ -25,6 +25,7 @@
25#include "ivtv-routing.h" 25#include "ivtv-routing.h"
26 26
27#include <media/msp3400.h> 27#include <media/msp3400.h>
28#include <media/m52790.h>
28#include <media/upd64031a.h> 29#include <media/upd64031a.h>
29#include <media/upd64083.h> 30#include <media/upd64083.h>
30 31
@@ -32,28 +33,26 @@
32 settings. */ 33 settings. */
33void ivtv_audio_set_io(struct ivtv *itv) 34void ivtv_audio_set_io(struct ivtv *itv)
34{ 35{
36 const struct ivtv_card_audio_input *in;
35 struct v4l2_routing route; 37 struct v4l2_routing route;
36 u32 audio_input;
37 int mux_input;
38 38
39 /* Determine which input to use */ 39 /* Determine which input to use */
40 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) { 40 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags))
41 audio_input = itv->card->radio_input.audio_input; 41 in = &itv->card->radio_input;
42 mux_input = itv->card->radio_input.muxer_input; 42 else
43 } else { 43 in = &itv->card->audio_inputs[itv->audio_input];
44 audio_input = itv->card->audio_inputs[itv->audio_input].audio_input;
45 mux_input = itv->card->audio_inputs[itv->audio_input].muxer_input;
46 }
47 44
48 /* handle muxer chips */ 45 /* handle muxer chips */
49 route.input = mux_input; 46 route.input = in->muxer_input;
50 route.output = 0; 47 route.output = 0;
48 if (itv->card->hw_muxer & IVTV_HW_M52790)
49 route.output = M52790_OUT_STEREO;
51 ivtv_i2c_hw(itv, itv->card->hw_muxer, VIDIOC_INT_S_AUDIO_ROUTING, &route); 50 ivtv_i2c_hw(itv, itv->card->hw_muxer, VIDIOC_INT_S_AUDIO_ROUTING, &route);
52 51
53 route.input = audio_input; 52 route.input = in->audio_input;
54 if (itv->card->hw_audio & IVTV_HW_MSP34XX) { 53 route.output = 0;
54 if (itv->card->hw_audio & IVTV_HW_MSP34XX)
55 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); 55 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
56 }
57 ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, &route); 56 ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, &route);
58} 57}
59 58
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 74fb0e021979..24d98ecf35ad 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -43,7 +43,7 @@
43#include "ivtv-cards.h" 43#include "ivtv-cards.h"
44#include "ivtv-streams.h" 44#include "ivtv-streams.h"
45 45
46static struct file_operations ivtv_v4l2_enc_fops = { 46static const struct file_operations ivtv_v4l2_enc_fops = {
47 .owner = THIS_MODULE, 47 .owner = THIS_MODULE,
48 .read = ivtv_v4l2_read, 48 .read = ivtv_v4l2_read,
49 .write = ivtv_v4l2_write, 49 .write = ivtv_v4l2_write,
@@ -53,7 +53,7 @@ static struct file_operations ivtv_v4l2_enc_fops = {
53 .poll = ivtv_v4l2_enc_poll, 53 .poll = ivtv_v4l2_enc_poll,
54}; 54};
55 55
56static struct file_operations ivtv_v4l2_dec_fops = { 56static const struct file_operations ivtv_v4l2_dec_fops = {
57 .owner = THIS_MODULE, 57 .owner = THIS_MODULE,
58 .read = ivtv_v4l2_read, 58 .read = ivtv_v4l2_read,
59 .write = ivtv_v4l2_write, 59 .write = ivtv_v4l2_write,
@@ -572,10 +572,10 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
572 clear_bit(IVTV_F_I_EOS, &itv->i_flags); 572 clear_bit(IVTV_F_I_EOS, &itv->i_flags);
573 573
574 /* Initialize Digitizer for Capture */ 574 /* Initialize Digitizer for Capture */
575 itv->video_dec_func(itv, VIDIOC_STREAMOFF, 0); 575 itv->video_dec_func(itv, VIDIOC_STREAMOFF, NULL);
576 ivtv_msleep_timeout(300, 1); 576 ivtv_msleep_timeout(300, 1);
577 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0); 577 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0);
578 itv->video_dec_func(itv, VIDIOC_STREAMON, 0); 578 itv->video_dec_func(itv, VIDIOC_STREAMON, NULL);
579 } 579 }
580 580
581 /* begin_capture */ 581 /* begin_capture */
@@ -661,27 +661,12 @@ int ivtv_start_v4l2_decode_stream(struct ivtv_stream *s, int gop_offset)
661 661
662 IVTV_DEBUG_INFO("Starting decode stream %s (gop_offset %d)\n", s->name, gop_offset); 662 IVTV_DEBUG_INFO("Starting decode stream %s (gop_offset %d)\n", s->name, gop_offset);
663 663
664 /* Clear Streamoff */
665 if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
666 /* Initialize Decoder */
667 /* Reprogram Decoder YUV Buffers for YUV */
668 write_reg(yuv_offset[0] >> 4, 0x82c);
669 write_reg((yuv_offset[0] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x830);
670 write_reg(yuv_offset[0] >> 4, 0x834);
671 write_reg((yuv_offset[0] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x838);
672
673 write_reg_sync(0x00000000 | (0x0c << 16) | (0x0b << 8), 0x2d24);
674
675 write_reg_sync(0x00108080, 0x2898);
676 /* Enable YUV decoder output */
677 write_reg_sync(0x01, IVTV_REG_VDM);
678 }
679
680 ivtv_setup_v4l2_decode_stream(s); 664 ivtv_setup_v4l2_decode_stream(s);
681 665
682 /* set dma size to 65536 bytes */ 666 /* set dma size to 65536 bytes */
683 ivtv_vapi(itv, CX2341X_DEC_SET_DMA_BLOCK_SIZE, 1, 65536); 667 ivtv_vapi(itv, CX2341X_DEC_SET_DMA_BLOCK_SIZE, 1, 65536);
684 668
669 /* Clear Streamoff */
685 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); 670 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
686 671
687 /* Zero out decoder counters */ 672 /* Zero out decoder counters */
diff --git a/drivers/media/video/ivtv/ivtv-version.h b/drivers/media/video/ivtv/ivtv-version.h
index d050de2a7229..0f1d4cc4b4d9 100644
--- a/drivers/media/video/ivtv/ivtv-version.h
+++ b/drivers/media/video/ivtv/ivtv-version.h
@@ -22,7 +22,7 @@
22 22
23#define IVTV_DRIVER_NAME "ivtv" 23#define IVTV_DRIVER_NAME "ivtv"
24#define IVTV_DRIVER_VERSION_MAJOR 1 24#define IVTV_DRIVER_VERSION_MAJOR 1
25#define IVTV_DRIVER_VERSION_MINOR 1 25#define IVTV_DRIVER_VERSION_MINOR 2
26#define IVTV_DRIVER_VERSION_PATCHLEVEL 0 26#define IVTV_DRIVER_VERSION_PATCHLEVEL 0
27 27
28#define IVTV_VERSION __stringify(IVTV_DRIVER_VERSION_MAJOR) "." __stringify(IVTV_DRIVER_VERSION_MINOR) "." __stringify(IVTV_DRIVER_VERSION_PATCHLEVEL) 28#define IVTV_VERSION __stringify(IVTV_DRIVER_VERSION_MAJOR) "." __stringify(IVTV_DRIVER_VERSION_MINOR) "." __stringify(IVTV_DRIVER_VERSION_PATCHLEVEL)
diff --git a/drivers/media/video/ivtv/ivtv-yuv.c b/drivers/media/video/ivtv/ivtv-yuv.c
index 9091c4837bbc..85183480a225 100644
--- a/drivers/media/video/ivtv/ivtv-yuv.c
+++ b/drivers/media/video/ivtv/ivtv-yuv.c
@@ -22,32 +22,37 @@
22#include "ivtv-udma.h" 22#include "ivtv-udma.h"
23#include "ivtv-yuv.h" 23#include "ivtv-yuv.h"
24 24
25const u32 yuv_offset[4] = { 25/* YUV buffer offsets */
26 IVTV_YUV_BUFFER_OFFSET, 26const u32 yuv_offset[IVTV_YUV_BUFFERS] = {
27 IVTV_YUV_BUFFER_OFFSET_1, 27 0x001a8600,
28 IVTV_YUV_BUFFER_OFFSET_2, 28 0x00240400,
29 IVTV_YUV_BUFFER_OFFSET_3 29 0x002d8200,
30 0x00370000,
31 0x00029000,
32 0x000C0E00,
33 0x006B0400,
34 0x00748200
30}; 35};
31 36
32static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma, 37static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
33 struct ivtv_dma_frame *args) 38 struct ivtv_dma_frame *args)
34{ 39{
35 struct ivtv_dma_page_info y_dma; 40 struct ivtv_dma_page_info y_dma;
36 struct ivtv_dma_page_info uv_dma; 41 struct ivtv_dma_page_info uv_dma;
37 42 struct yuv_playback_info *yi = &itv->yuv_info;
43 u8 frame = yi->draw_frame;
44 struct yuv_frame_info *f = &yi->new_frame_info[frame];
38 int i; 45 int i;
39 int y_pages, uv_pages; 46 int y_pages, uv_pages;
40
41 unsigned long y_buffer_offset, uv_buffer_offset; 47 unsigned long y_buffer_offset, uv_buffer_offset;
42 int y_decode_height, uv_decode_height, y_size; 48 int y_decode_height, uv_decode_height, y_size;
43 int frame = atomic_read(&itv->yuv_info.next_fill_frame);
44 49
45 y_buffer_offset = IVTV_DECODER_OFFSET + yuv_offset[frame]; 50 y_buffer_offset = IVTV_DECODER_OFFSET + yuv_offset[frame];
46 uv_buffer_offset = y_buffer_offset + IVTV_YUV_BUFFER_UV_OFFSET; 51 uv_buffer_offset = y_buffer_offset + IVTV_YUV_BUFFER_UV_OFFSET;
47 52
48 y_decode_height = uv_decode_height = args->src.height + args->src.top; 53 y_decode_height = uv_decode_height = f->src_h + f->src_y;
49 54
50 if (y_decode_height < 512-16) 55 if (f->offset_y)
51 y_buffer_offset += 720 * 16; 56 y_buffer_offset += 720 * 16;
52 57
53 if (y_decode_height & 15) 58 if (y_decode_height & 15)
@@ -60,8 +65,9 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
60 65
61 /* Still in USE */ 66 /* Still in USE */
62 if (dma->SG_length || dma->page_count) { 67 if (dma->SG_length || dma->page_count) {
63 IVTV_DEBUG_WARN("prep_user_dma: SG_length %d page_count %d still full?\n", 68 IVTV_DEBUG_WARN
64 dma->SG_length, dma->page_count); 69 ("prep_user_dma: SG_length %d page_count %d still full?\n",
70 dma->SG_length, dma->page_count);
65 return -EBUSY; 71 return -EBUSY;
66 } 72 }
67 73
@@ -77,8 +83,9 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
77 dma->page_count = y_dma.page_count + uv_dma.page_count; 83 dma->page_count = y_dma.page_count + uv_dma.page_count;
78 84
79 if (y_pages + uv_pages != dma->page_count) { 85 if (y_pages + uv_pages != dma->page_count) {
80 IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n", 86 IVTV_DEBUG_WARN
81 y_pages + uv_pages, dma->page_count); 87 ("failed to map user pages, returned %d instead of %d\n",
88 y_pages + uv_pages, dma->page_count);
82 89
83 for (i = 0; i < dma->page_count; i++) { 90 for (i = 0; i < dma->page_count; i++) {
84 put_page(dma->map[i]); 91 put_page(dma->map[i]);
@@ -99,16 +106,14 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
99 dma->SG_length = pci_map_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE); 106 dma->SG_length = pci_map_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE);
100 107
101 /* Fill SG Array with new values */ 108 /* Fill SG Array with new values */
102 ivtv_udma_fill_sg_array (dma, y_buffer_offset, uv_buffer_offset, y_size); 109 ivtv_udma_fill_sg_array(dma, y_buffer_offset, uv_buffer_offset, y_size);
103 110
104 /* If we've offset the y plane, ensure top area is blanked */ 111 /* If we've offset the y plane, ensure top area is blanked */
105 if (args->src.height + args->src.top < 512-16) { 112 if (f->offset_y && yi->blanking_dmaptr) {
106 if (itv->yuv_info.blanking_dmaptr) { 113 dma->SGarray[dma->SG_length].size = cpu_to_le32(720*16);
107 dma->SGarray[dma->SG_length].size = cpu_to_le32(720*16); 114 dma->SGarray[dma->SG_length].src = cpu_to_le32(yi->blanking_dmaptr);
108 dma->SGarray[dma->SG_length].src = cpu_to_le32(itv->yuv_info.blanking_dmaptr); 115 dma->SGarray[dma->SG_length].dst = cpu_to_le32(IVTV_DECODER_OFFSET + yuv_offset[frame]);
109 dma->SGarray[dma->SG_length].dst = cpu_to_le32(IVTV_DECODER_OFFSET + yuv_offset[frame]); 116 dma->SG_length++;
110 dma->SG_length++;
111 }
112 } 117 }
113 118
114 /* Tag SG Array with Interrupt Bit */ 119 /* Tag SG Array with Interrupt Bit */
@@ -121,11 +126,11 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
121/* We rely on a table held in the firmware - Quick check. */ 126/* We rely on a table held in the firmware - Quick check. */
122int ivtv_yuv_filter_check(struct ivtv *itv) 127int ivtv_yuv_filter_check(struct ivtv *itv)
123{ 128{
124 int i, offset_y, offset_uv; 129 int i, y, uv;
125 130
126 for (i=0, offset_y = 16, offset_uv = 4; i<16; i++, offset_y += 24, offset_uv += 12) { 131 for (i = 0, y = 16, uv = 4; i < 16; i++, y += 24, uv += 12) {
127 if ((read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + offset_y) != i << 16) || 132 if ((read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + y) != i << 16) ||
128 (read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + offset_uv) != i << 16)) { 133 (read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + uv) != i << 16)) {
129 IVTV_WARN ("YUV filter table not found in firmware.\n"); 134 IVTV_WARN ("YUV filter table not found in firmware.\n");
130 return -1; 135 return -1;
131 } 136 }
@@ -135,69 +140,67 @@ int ivtv_yuv_filter_check(struct ivtv *itv)
135 140
136static void ivtv_yuv_filter(struct ivtv *itv, int h_filter, int v_filter_1, int v_filter_2) 141static void ivtv_yuv_filter(struct ivtv *itv, int h_filter, int v_filter_1, int v_filter_2)
137{ 142{
138 int filter_index, filter_line; 143 u32 i, line;
139 144
140 /* If any filter is -1, then don't update it */ 145 /* If any filter is -1, then don't update it */
141 if (h_filter > -1) { 146 if (h_filter > -1) {
142 if (h_filter > 4) h_filter = 4; 147 if (h_filter > 4)
143 filter_index = h_filter * 384; 148 h_filter = 4;
144 filter_line = 0; 149 i = IVTV_YUV_HORIZONTAL_FILTER_OFFSET + (h_filter * 384);
145 while (filter_line < 16) { 150 for (line = 0; line < 16; line++) {
146 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02804); 151 write_reg(read_dec(i), 0x02804);
147 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x0281c); 152 write_reg(read_dec(i), 0x0281c);
148 filter_index += 4; 153 i += 4;
149 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02808); 154 write_reg(read_dec(i), 0x02808);
150 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02820); 155 write_reg(read_dec(i), 0x02820);
151 filter_index += 4; 156 i += 4;
152 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x0280c); 157 write_reg(read_dec(i), 0x0280c);
153 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02824); 158 write_reg(read_dec(i), 0x02824);
154 filter_index += 4; 159 i += 4;
155 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02810); 160 write_reg(read_dec(i), 0x02810);
156 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02828); 161 write_reg(read_dec(i), 0x02828);
157 filter_index += 4; 162 i += 4;
158 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02814); 163 write_reg(read_dec(i), 0x02814);
159 write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x0282c); 164 write_reg(read_dec(i), 0x0282c);
160 filter_index += 8; 165 i += 8;
161 write_reg(0, 0x02818); 166 write_reg(0, 0x02818);
162 write_reg(0, 0x02830); 167 write_reg(0, 0x02830);
163 filter_line ++;
164 } 168 }
165 IVTV_DEBUG_YUV("h_filter -> %d\n",h_filter); 169 IVTV_DEBUG_YUV("h_filter -> %d\n", h_filter);
166 } 170 }
167 171
168 if (v_filter_1 > -1) { 172 if (v_filter_1 > -1) {
169 if (v_filter_1 > 4) v_filter_1 = 4; 173 if (v_filter_1 > 4)
170 filter_index = v_filter_1 * 192; 174 v_filter_1 = 4;
171 filter_line = 0; 175 i = IVTV_YUV_VERTICAL_FILTER_OFFSET + (v_filter_1 * 192);
172 while (filter_line < 16) { 176 for (line = 0; line < 16; line++) {
173 write_reg(read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + filter_index), 0x02900); 177 write_reg(read_dec(i), 0x02900);
174 filter_index += 4; 178 i += 4;
175 write_reg(read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + filter_index), 0x02904); 179 write_reg(read_dec(i), 0x02904);
176 filter_index += 8; 180 i += 8;
177 write_reg(0, 0x02908); 181 write_reg(0, 0x02908);
178 filter_line ++;
179 } 182 }
180 IVTV_DEBUG_YUV("v_filter_1 -> %d\n",v_filter_1); 183 IVTV_DEBUG_YUV("v_filter_1 -> %d\n", v_filter_1);
181 } 184 }
182 185
183 if (v_filter_2 > -1) { 186 if (v_filter_2 > -1) {
184 if (v_filter_2 > 4) v_filter_2 = 4; 187 if (v_filter_2 > 4)
185 filter_index = v_filter_2 * 192; 188 v_filter_2 = 4;
186 filter_line = 0; 189 i = IVTV_YUV_VERTICAL_FILTER_OFFSET + (v_filter_2 * 192);
187 while (filter_line < 16) { 190 for (line = 0; line < 16; line++) {
188 write_reg(read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + filter_index), 0x0290c); 191 write_reg(read_dec(i), 0x0290c);
189 filter_index += 4; 192 i += 4;
190 write_reg(read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + filter_index), 0x02910); 193 write_reg(read_dec(i), 0x02910);
191 filter_index += 8; 194 i += 8;
192 write_reg(0, 0x02914); 195 write_reg(0, 0x02914);
193 filter_line ++;
194 } 196 }
195 IVTV_DEBUG_YUV("v_filter_2 -> %d\n",v_filter_2); 197 IVTV_DEBUG_YUV("v_filter_2 -> %d\n", v_filter_2);
196 } 198 }
197} 199}
198 200
199static void ivtv_yuv_handle_horizontal(struct ivtv *itv, struct yuv_frame_info *window) 201static void ivtv_yuv_handle_horizontal(struct ivtv *itv, struct yuv_frame_info *f)
200{ 202{
203 struct yuv_playback_info *yi = &itv->yuv_info;
201 u32 reg_2834, reg_2838, reg_283c; 204 u32 reg_2834, reg_2838, reg_283c;
202 u32 reg_2844, reg_2854, reg_285c; 205 u32 reg_2844, reg_2854, reg_285c;
203 u32 reg_2864, reg_2874, reg_2890; 206 u32 reg_2864, reg_2874, reg_2890;
@@ -206,18 +209,19 @@ static void ivtv_yuv_handle_horizontal(struct ivtv *itv, struct yuv_frame_info *
206 int h_filter; 209 int h_filter;
207 u32 master_width; 210 u32 master_width;
208 211
209 IVTV_DEBUG_WARN( "Need to adjust to width %d src_w %d dst_w %d src_x %d dst_x %d\n", 212 IVTV_DEBUG_WARN
210 window->tru_w, window->src_w, window->dst_w,window->src_x, window->dst_x); 213 ("Adjust to width %d src_w %d dst_w %d src_x %d dst_x %d\n",
214 f->tru_w, f->src_w, f->dst_w, f->src_x, f->dst_x);
211 215
212 /* How wide is the src image */ 216 /* How wide is the src image */
213 x_cutoff = window->src_w + window->src_x; 217 x_cutoff = f->src_w + f->src_x;
214 218
215 /* Set the display width */ 219 /* Set the display width */
216 reg_2834 = window->dst_w; 220 reg_2834 = f->dst_w;
217 reg_2838 = reg_2834; 221 reg_2838 = reg_2834;
218 222
219 /* Set the display position */ 223 /* Set the display position */
220 reg_2890 = window->dst_x; 224 reg_2890 = f->dst_x;
221 225
222 /* Index into the image horizontally */ 226 /* Index into the image horizontally */
223 reg_2870 = 0; 227 reg_2870 = 0;
@@ -228,32 +232,31 @@ static void ivtv_yuv_handle_horizontal(struct ivtv *itv, struct yuv_frame_info *
228 Gradually adjust the offset to avoid the video 'snapping' 232 Gradually adjust the offset to avoid the video 'snapping'
229 left/right if it gets dragged through this region. 233 left/right if it gets dragged through this region.
230 Only do this if osd is full width. */ 234 Only do this if osd is full width. */
231 if (window->vis_w == 720) { 235 if (f->vis_w == 720) {
232 if ((window->tru_x - window->pan_x > -1) && (window->tru_x - window->pan_x <= 40) && (window->dst_w >= 680)){ 236 if ((f->tru_x - f->pan_x > -1) && (f->tru_x - f->pan_x <= 40) && (f->dst_w >= 680))
233 reg_2870 = 10 - (window->tru_x - window->pan_x) / 4; 237 reg_2870 = 10 - (f->tru_x - f->pan_x) / 4;
234 } 238 else if ((f->tru_x - f->pan_x < 0) && (f->tru_x - f->pan_x >= -20) && (f->dst_w >= 660))
235 else if ((window->tru_x - window->pan_x < 0) && (window->tru_x - window->pan_x >= -20) && (window->dst_w >= 660)) { 239 reg_2870 = (10 + (f->tru_x - f->pan_x) / 2);
236 reg_2870 = (10 + (window->tru_x - window->pan_x) / 2);
237 }
238 240
239 if (window->dst_w >= window->src_w) 241 if (f->dst_w >= f->src_w)
240 reg_2870 = reg_2870 << 16 | reg_2870; 242 reg_2870 = reg_2870 << 16 | reg_2870;
241 else 243 else
242 reg_2870 = ((reg_2870 & ~1) << 15) | (reg_2870 & ~1); 244 reg_2870 = ((reg_2870 & ~1) << 15) | (reg_2870 & ~1);
243 } 245 }
244 246
245 if (window->dst_w < window->src_w) 247 if (f->dst_w < f->src_w)
246 reg_2870 = 0x000d000e - reg_2870; 248 reg_2870 = 0x000d000e - reg_2870;
247 else 249 else
248 reg_2870 = 0x0012000e - reg_2870; 250 reg_2870 = 0x0012000e - reg_2870;
249 251
250 /* We're also using 2870 to shift the image left (src_x & negative dst_x) */ 252 /* We're also using 2870 to shift the image left (src_x & negative dst_x) */
251 reg_2870_offset = (window->src_x*((window->dst_w << 21)/window->src_w))>>19; 253 reg_2870_offset = (f->src_x * ((f->dst_w << 21) / f->src_w)) >> 19;
252 254
253 if (window->dst_w >= window->src_w) { 255 if (f->dst_w >= f->src_w) {
254 x_cutoff &= ~1; 256 x_cutoff &= ~1;
255 master_width = (window->src_w * 0x00200000) / (window->dst_w); 257 master_width = (f->src_w * 0x00200000) / (f->dst_w);
256 if (master_width * window->dst_w != window->src_w * 0x00200000) master_width ++; 258 if (master_width * f->dst_w != f->src_w * 0x00200000)
259 master_width++;
257 reg_2834 = (reg_2834 << 16) | x_cutoff; 260 reg_2834 = (reg_2834 << 16) | x_cutoff;
258 reg_2838 = (reg_2838 << 16) | x_cutoff; 261 reg_2838 = (reg_2838 << 16) | x_cutoff;
259 reg_283c = master_width >> 2; 262 reg_283c = master_width >> 2;
@@ -264,17 +267,17 @@ static void ivtv_yuv_handle_horizontal(struct ivtv *itv, struct yuv_frame_info *
264 267
265 /* We also need to factor in the scaling 268 /* We also need to factor in the scaling
266 (src_w - dst_w) / (src_w / 4) */ 269 (src_w - dst_w) / (src_w / 4) */
267 if (window->dst_w > window->src_w) 270 if (f->dst_w > f->src_w)
268 reg_2870_base = ((window->dst_w - window->src_w)<<16) / (window->src_w <<14); 271 reg_2870_base = ((f->dst_w - f->src_w)<<16) / (f->src_w <<14);
269 else 272 else
270 reg_2870_base = 0; 273 reg_2870_base = 0;
271 274
272 reg_2870 += (((reg_2870_offset << 14) & 0xFFFF0000) | reg_2870_offset >> 2) + (reg_2870_base << 17 | reg_2870_base); 275 reg_2870 += (((reg_2870_offset << 14) & 0xFFFF0000) | reg_2870_offset >> 2) + (reg_2870_base << 17 | reg_2870_base);
273 reg_2874 = 0; 276 reg_2874 = 0;
274 } 277 } else if (f->dst_w < f->src_w / 2) {
275 else if (window->dst_w < window->src_w / 2) { 278 master_width = (f->src_w * 0x00080000) / f->dst_w;
276 master_width = (window->src_w * 0x00080000) / window->dst_w; 279 if (master_width * f->dst_w != f->src_w * 0x00080000)
277 if (master_width * window->dst_w != window->src_w * 0x00080000) master_width ++; 280 master_width++;
278 reg_2834 = (reg_2834 << 16) | x_cutoff; 281 reg_2834 = (reg_2834 << 16) | x_cutoff;
279 reg_2838 = (reg_2838 << 16) | x_cutoff; 282 reg_2838 = (reg_2838 << 16) | x_cutoff;
280 reg_283c = master_width >> 2; 283 reg_283c = master_width >> 2;
@@ -282,13 +285,13 @@ static void ivtv_yuv_handle_horizontal(struct ivtv *itv, struct yuv_frame_info *
282 reg_2854 = master_width; 285 reg_2854 = master_width;
283 reg_285c = master_width >> 1; 286 reg_285c = master_width >> 1;
284 reg_2864 = master_width >> 1; 287 reg_2864 = master_width >> 1;
285 reg_2870 += (((reg_2870_offset << 15) & 0xFFFF0000) | reg_2870_offset); 288 reg_2870 += ((reg_2870_offset << 15) & 0xFFFF0000) | reg_2870_offset;
286 reg_2870 += (5 - (((window->src_w + window->src_w / 2) - 1) / window->dst_w)) << 16; 289 reg_2870 += (5 - (((f->src_w + f->src_w / 2) - 1) / f->dst_w)) << 16;
287 reg_2874 = 0x00000012; 290 reg_2874 = 0x00000012;
288 } 291 } else {
289 else { 292 master_width = (f->src_w * 0x00100000) / f->dst_w;
290 master_width = (window->src_w * 0x00100000) / window->dst_w; 293 if (master_width * f->dst_w != f->src_w * 0x00100000)
291 if (master_width * window->dst_w != window->src_w * 0x00100000) master_width ++; 294 master_width++;
292 reg_2834 = (reg_2834 << 16) | x_cutoff; 295 reg_2834 = (reg_2834 << 16) | x_cutoff;
293 reg_2838 = (reg_2838 << 16) | x_cutoff; 296 reg_2838 = (reg_2838 << 16) | x_cutoff;
294 reg_283c = master_width >> 2; 297 reg_283c = master_width >> 2;
@@ -296,62 +299,70 @@ static void ivtv_yuv_handle_horizontal(struct ivtv *itv, struct yuv_frame_info *
296 reg_2854 = master_width; 299 reg_2854 = master_width;
297 reg_285c = master_width >> 1; 300 reg_285c = master_width >> 1;
298 reg_2864 = master_width >> 1; 301 reg_2864 = master_width >> 1;
299 reg_2870 += (((reg_2870_offset << 14) & 0xFFFF0000) | reg_2870_offset >> 1); 302 reg_2870 += ((reg_2870_offset << 14) & 0xFFFF0000) | reg_2870_offset >> 1;
300 reg_2870 += (5 - (((window->src_w * 3) - 1) / window->dst_w)) << 16; 303 reg_2870 += (5 - (((f->src_w * 3) - 1) / f->dst_w)) << 16;
301 reg_2874 = 0x00000001; 304 reg_2874 = 0x00000001;
302 } 305 }
303 306
304 /* Select the horizontal filter */ 307 /* Select the horizontal filter */
305 if (window->src_w == window->dst_w) { 308 if (f->src_w == f->dst_w) {
306 /* An exact size match uses filter 0 */ 309 /* An exact size match uses filter 0 */
307 h_filter = 0; 310 h_filter = 0;
308 } 311 } else {
309 else {
310 /* Figure out which filter to use */ 312 /* Figure out which filter to use */
311 h_filter = ((window->src_w << 16) / window->dst_w) >> 15; 313 h_filter = ((f->src_w << 16) / f->dst_w) >> 15;
312 h_filter = (h_filter >> 1) + (h_filter & 1); 314 h_filter = (h_filter >> 1) + (h_filter & 1);
313 /* Only an exact size match can use filter 0 */ 315 /* Only an exact size match can use filter 0 */
314 if (h_filter == 0) h_filter = 1; 316 h_filter += !h_filter;
315 } 317 }
316 318
317 write_reg(reg_2834, 0x02834); 319 write_reg(reg_2834, 0x02834);
318 write_reg(reg_2838, 0x02838); 320 write_reg(reg_2838, 0x02838);
319 IVTV_DEBUG_YUV("Update reg 0x2834 %08x->%08x 0x2838 %08x->%08x\n",itv->yuv_info.reg_2834, reg_2834, itv->yuv_info.reg_2838, reg_2838); 321 IVTV_DEBUG_YUV("Update reg 0x2834 %08x->%08x 0x2838 %08x->%08x\n",
322 yi->reg_2834, reg_2834, yi->reg_2838, reg_2838);
320 323
321 write_reg(reg_283c, 0x0283c); 324 write_reg(reg_283c, 0x0283c);
322 write_reg(reg_2844, 0x02844); 325 write_reg(reg_2844, 0x02844);
323 326
324 IVTV_DEBUG_YUV("Update reg 0x283c %08x->%08x 0x2844 %08x->%08x\n",itv->yuv_info.reg_283c, reg_283c, itv->yuv_info.reg_2844, reg_2844); 327 IVTV_DEBUG_YUV("Update reg 0x283c %08x->%08x 0x2844 %08x->%08x\n",
328 yi->reg_283c, reg_283c, yi->reg_2844, reg_2844);
325 329
326 write_reg(0x00080514, 0x02840); 330 write_reg(0x00080514, 0x02840);
327 write_reg(0x00100514, 0x02848); 331 write_reg(0x00100514, 0x02848);
328 IVTV_DEBUG_YUV("Update reg 0x2840 %08x->%08x 0x2848 %08x->%08x\n",itv->yuv_info.reg_2840, 0x00080514, itv->yuv_info.reg_2848, 0x00100514); 332 IVTV_DEBUG_YUV("Update reg 0x2840 %08x->%08x 0x2848 %08x->%08x\n",
333 yi->reg_2840, 0x00080514, yi->reg_2848, 0x00100514);
329 334
330 write_reg(reg_2854, 0x02854); 335 write_reg(reg_2854, 0x02854);
331 IVTV_DEBUG_YUV("Update reg 0x2854 %08x->%08x \n",itv->yuv_info.reg_2854, reg_2854); 336 IVTV_DEBUG_YUV("Update reg 0x2854 %08x->%08x \n",
337 yi->reg_2854, reg_2854);
332 338
333 write_reg(reg_285c, 0x0285c); 339 write_reg(reg_285c, 0x0285c);
334 write_reg(reg_2864, 0x02864); 340 write_reg(reg_2864, 0x02864);
335 IVTV_DEBUG_YUV("Update reg 0x285c %08x->%08x 0x2864 %08x->%08x\n",itv->yuv_info.reg_285c, reg_285c, itv->yuv_info.reg_2864, reg_2864); 341 IVTV_DEBUG_YUV("Update reg 0x285c %08x->%08x 0x2864 %08x->%08x\n",
342 yi->reg_285c, reg_285c, yi->reg_2864, reg_2864);
336 343
337 write_reg(reg_2874, 0x02874); 344 write_reg(reg_2874, 0x02874);
338 IVTV_DEBUG_YUV("Update reg 0x2874 %08x->%08x\n",itv->yuv_info.reg_2874, reg_2874); 345 IVTV_DEBUG_YUV("Update reg 0x2874 %08x->%08x\n",
346 yi->reg_2874, reg_2874);
339 347
340 write_reg(reg_2870, 0x02870); 348 write_reg(reg_2870, 0x02870);
341 IVTV_DEBUG_YUV("Update reg 0x2870 %08x->%08x\n",itv->yuv_info.reg_2870, reg_2870); 349 IVTV_DEBUG_YUV("Update reg 0x2870 %08x->%08x\n",
350 yi->reg_2870, reg_2870);
342 351
343 write_reg( reg_2890,0x02890); 352 write_reg(reg_2890, 0x02890);
344 IVTV_DEBUG_YUV("Update reg 0x2890 %08x->%08x\n",itv->yuv_info.reg_2890, reg_2890); 353 IVTV_DEBUG_YUV("Update reg 0x2890 %08x->%08x\n",
354 yi->reg_2890, reg_2890);
345 355
346 /* Only update the filter if we really need to */ 356 /* Only update the filter if we really need to */
347 if (h_filter != itv->yuv_info.h_filter) { 357 if (h_filter != yi->h_filter) {
348 ivtv_yuv_filter (itv,h_filter,-1,-1); 358 ivtv_yuv_filter(itv, h_filter, -1, -1);
349 itv->yuv_info.h_filter = h_filter; 359 yi->h_filter = h_filter;
350 } 360 }
351} 361}
352 362
353static void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *window) 363static void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *f)
354{ 364{
365 struct yuv_playback_info *yi = &itv->yuv_info;
355 u32 master_height; 366 u32 master_height;
356 u32 reg_2918, reg_291c, reg_2920, reg_2928; 367 u32 reg_2918, reg_291c, reg_2920, reg_2928;
357 u32 reg_2930, reg_2934, reg_293c; 368 u32 reg_2930, reg_2934, reg_293c;
@@ -359,69 +370,59 @@ static void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *wi
359 u32 reg_2950, reg_2954, reg_2958, reg_295c; 370 u32 reg_2950, reg_2954, reg_2958, reg_295c;
360 u32 reg_2960, reg_2964, reg_2968, reg_296c; 371 u32 reg_2960, reg_2964, reg_2968, reg_296c;
361 u32 reg_289c; 372 u32 reg_289c;
362 u32 src_y_major_y, src_y_minor_y; 373 u32 src_major_y, src_minor_y;
363 u32 src_y_major_uv, src_y_minor_uv; 374 u32 src_major_uv, src_minor_uv;
364 u32 reg_2964_base, reg_2968_base; 375 u32 reg_2964_base, reg_2968_base;
365 int v_filter_1, v_filter_2; 376 int v_filter_1, v_filter_2;
366 377
367 IVTV_DEBUG_WARN("Need to adjust to height %d src_h %d dst_h %d src_y %d dst_y %d\n", 378 IVTV_DEBUG_WARN
368 window->tru_h, window->src_h, window->dst_h,window->src_y, window->dst_y); 379 ("Adjust to height %d src_h %d dst_h %d src_y %d dst_y %d\n",
380 f->tru_h, f->src_h, f->dst_h, f->src_y, f->dst_y);
369 381
370 /* What scaling mode is being used... */ 382 /* What scaling mode is being used... */
371 if (window->interlaced_y) { 383 IVTV_DEBUG_YUV("Scaling mode Y: %s\n",
372 IVTV_DEBUG_YUV("Scaling mode Y: Interlaced\n"); 384 f->interlaced_y ? "Interlaced" : "Progressive");
373 }
374 else {
375 IVTV_DEBUG_YUV("Scaling mode Y: Progressive\n");
376 }
377 385
378 if (window->interlaced_uv) { 386 IVTV_DEBUG_YUV("Scaling mode UV: %s\n",
379 IVTV_DEBUG_YUV("Scaling mode UV: Interlaced\n"); 387 f->interlaced_uv ? "Interlaced" : "Progressive");
380 }
381 else {
382 IVTV_DEBUG_YUV("Scaling mode UV: Progressive\n");
383 }
384 388
385 /* What is the source video being treated as... */ 389 /* What is the source video being treated as... */
386 if (itv->yuv_info.frame_interlaced) { 390 IVTV_DEBUG_WARN("Source video: %s\n",
387 IVTV_DEBUG_WARN("Source video: Interlaced\n"); 391 f->interlaced ? "Interlaced" : "Progressive");
388 }
389 else {
390 IVTV_DEBUG_WARN("Source video: Non-interlaced\n");
391 }
392 392
393 /* We offset into the image using two different index methods, so split 393 /* We offset into the image using two different index methods, so split
394 the y source coord into two parts. */ 394 the y source coord into two parts. */
395 if (window->src_y < 8) { 395 if (f->src_y < 8) {
396 src_y_minor_uv = window->src_y; 396 src_minor_uv = f->src_y;
397 src_y_major_uv = 0; 397 src_major_uv = 0;
398 } 398 } else {
399 else { 399 src_minor_uv = 8;
400 src_y_minor_uv = 8; 400 src_major_uv = f->src_y - 8;
401 src_y_major_uv = window->src_y - 8;
402 } 401 }
403 402
404 src_y_minor_y = src_y_minor_uv; 403 src_minor_y = src_minor_uv;
405 src_y_major_y = src_y_major_uv; 404 src_major_y = src_major_uv;
406 405
407 if (window->offset_y) src_y_minor_y += 16; 406 if (f->offset_y)
407 src_minor_y += 16;
408 408
409 if (window->interlaced_y) 409 if (f->interlaced_y)
410 reg_2918 = (window->dst_h << 16) | (window->src_h + src_y_minor_y); 410 reg_2918 = (f->dst_h << 16) | (f->src_h + src_minor_y);
411 else 411 else
412 reg_2918 = (window->dst_h << 16) | ((window->src_h + src_y_minor_y) << 1); 412 reg_2918 = (f->dst_h << 16) | ((f->src_h + src_minor_y) << 1);
413 413
414 if (window->interlaced_uv) 414 if (f->interlaced_uv)
415 reg_291c = (window->dst_h << 16) | ((window->src_h + src_y_minor_uv) >> 1); 415 reg_291c = (f->dst_h << 16) | ((f->src_h + src_minor_uv) >> 1);
416 else 416 else
417 reg_291c = (window->dst_h << 16) | (window->src_h + src_y_minor_uv); 417 reg_291c = (f->dst_h << 16) | (f->src_h + src_minor_uv);
418 418
419 reg_2964_base = (src_y_minor_y * ((window->dst_h << 16)/window->src_h)) >> 14; 419 reg_2964_base = (src_minor_y * ((f->dst_h << 16) / f->src_h)) >> 14;
420 reg_2968_base = (src_y_minor_uv * ((window->dst_h << 16)/window->src_h)) >> 14; 420 reg_2968_base = (src_minor_uv * ((f->dst_h << 16) / f->src_h)) >> 14;
421 421
422 if (window->dst_h / 2 >= window->src_h && !window->interlaced_y) { 422 if (f->dst_h / 2 >= f->src_h && !f->interlaced_y) {
423 master_height = (window->src_h * 0x00400000) / window->dst_h; 423 master_height = (f->src_h * 0x00400000) / f->dst_h;
424 if ((window->src_h * 0x00400000) - (master_height * window->dst_h) >= window->dst_h / 2) master_height ++; 424 if ((f->src_h * 0x00400000) - (master_height * f->dst_h) >= f->dst_h / 2)
425 master_height++;
425 reg_2920 = master_height >> 2; 426 reg_2920 = master_height >> 2;
426 reg_2928 = master_height >> 3; 427 reg_2928 = master_height >> 3;
427 reg_2930 = master_height; 428 reg_2930 = master_height;
@@ -429,45 +430,42 @@ static void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *wi
429 reg_2964_base >>= 3; 430 reg_2964_base >>= 3;
430 reg_2968_base >>= 3; 431 reg_2968_base >>= 3;
431 reg_296c = 0x00000000; 432 reg_296c = 0x00000000;
432 } 433 } else if (f->dst_h >= f->src_h) {
433 else if (window->dst_h >= window->src_h) { 434 master_height = (f->src_h * 0x00400000) / f->dst_h;
434 master_height = (window->src_h * 0x00400000) / window->dst_h;
435 master_height = (master_height >> 1) + (master_height & 1); 435 master_height = (master_height >> 1) + (master_height & 1);
436 reg_2920 = master_height >> 2; 436 reg_2920 = master_height >> 2;
437 reg_2928 = master_height >> 2; 437 reg_2928 = master_height >> 2;
438 reg_2930 = master_height; 438 reg_2930 = master_height;
439 reg_2940 = master_height >> 1; 439 reg_2940 = master_height >> 1;
440 reg_296c = 0x00000000; 440 reg_296c = 0x00000000;
441 if (window->interlaced_y) { 441 if (f->interlaced_y) {
442 reg_2964_base >>= 3; 442 reg_2964_base >>= 3;
443 } 443 } else {
444 else { 444 reg_296c++;
445 reg_296c ++;
446 reg_2964_base >>= 2; 445 reg_2964_base >>= 2;
447 } 446 }
448 if (window->interlaced_uv) reg_2928 >>= 1; 447 if (f->interlaced_uv)
448 reg_2928 >>= 1;
449 reg_2968_base >>= 3; 449 reg_2968_base >>= 3;
450 } 450 } else if (f->dst_h >= f->src_h / 2) {
451 else if (window->dst_h >= window->src_h / 2) { 451 master_height = (f->src_h * 0x00200000) / f->dst_h;
452 master_height = (window->src_h * 0x00200000) / window->dst_h;
453 master_height = (master_height >> 1) + (master_height & 1); 452 master_height = (master_height >> 1) + (master_height & 1);
454 reg_2920 = master_height >> 2; 453 reg_2920 = master_height >> 2;
455 reg_2928 = master_height >> 2; 454 reg_2928 = master_height >> 2;
456 reg_2930 = master_height; 455 reg_2930 = master_height;
457 reg_2940 = master_height; 456 reg_2940 = master_height;
458 reg_296c = 0x00000101; 457 reg_296c = 0x00000101;
459 if (window->interlaced_y) { 458 if (f->interlaced_y) {
460 reg_2964_base >>= 2; 459 reg_2964_base >>= 2;
461 } 460 } else {
462 else { 461 reg_296c++;
463 reg_296c ++;
464 reg_2964_base >>= 1; 462 reg_2964_base >>= 1;
465 } 463 }
466 if (window->interlaced_uv) reg_2928 >>= 1; 464 if (f->interlaced_uv)
465 reg_2928 >>= 1;
467 reg_2968_base >>= 2; 466 reg_2968_base >>= 2;
468 } 467 } else {
469 else { 468 master_height = (f->src_h * 0x00100000) / f->dst_h;
470 master_height = (window->src_h * 0x00100000) / window->dst_h;
471 master_height = (master_height >> 1) + (master_height & 1); 469 master_height = (master_height >> 1) + (master_height & 1);
472 reg_2920 = master_height >> 2; 470 reg_2920 = master_height >> 2;
473 reg_2928 = master_height >> 2; 471 reg_2928 = master_height >> 2;
@@ -480,13 +478,12 @@ static void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *wi
480 478
481 /* FIXME These registers change depending on scaled / unscaled output 479 /* FIXME These registers change depending on scaled / unscaled output
482 We really need to work out what they should be */ 480 We really need to work out what they should be */
483 if (window->src_h == window->dst_h){ 481 if (f->src_h == f->dst_h) {
484 reg_2934 = 0x00020000; 482 reg_2934 = 0x00020000;
485 reg_293c = 0x00100000; 483 reg_293c = 0x00100000;
486 reg_2944 = 0x00040000; 484 reg_2944 = 0x00040000;
487 reg_294c = 0x000b0000; 485 reg_294c = 0x000b0000;
488 } 486 } else {
489 else {
490 reg_2934 = 0x00000FF0; 487 reg_2934 = 0x00000FF0;
491 reg_293c = 0x00000FF0; 488 reg_293c = 0x00000FF0;
492 reg_2944 = 0x00000FF0; 489 reg_2944 = 0x00000FF0;
@@ -494,34 +491,36 @@ static void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *wi
494 } 491 }
495 492
496 /* The first line to be displayed */ 493 /* The first line to be displayed */
497 reg_2950 = 0x00010000 + src_y_major_y; 494 reg_2950 = 0x00010000 + src_major_y;
498 if (window->interlaced_y) reg_2950 += 0x00010000; 495 if (f->interlaced_y)
496 reg_2950 += 0x00010000;
499 reg_2954 = reg_2950 + 1; 497 reg_2954 = reg_2950 + 1;
500 498
501 reg_2958 = 0x00010000 + (src_y_major_y >> 1); 499 reg_2958 = 0x00010000 + (src_major_y >> 1);
502 if (window->interlaced_uv) reg_2958 += 0x00010000; 500 if (f->interlaced_uv)
501 reg_2958 += 0x00010000;
503 reg_295c = reg_2958 + 1; 502 reg_295c = reg_2958 + 1;
504 503
505 if (itv->yuv_info.decode_height == 480) 504 if (yi->decode_height == 480)
506 reg_289c = 0x011e0017; 505 reg_289c = 0x011e0017;
507 else 506 else
508 reg_289c = 0x01500017; 507 reg_289c = 0x01500017;
509 508
510 if (window->dst_y < 0) 509 if (f->dst_y < 0)
511 reg_289c = (reg_289c - ((window->dst_y & ~1)<<15))-(window->dst_y >>1); 510 reg_289c = (reg_289c - ((f->dst_y & ~1)<<15))-(f->dst_y >>1);
512 else 511 else
513 reg_289c = (reg_289c + ((window->dst_y & ~1)<<15))+(window->dst_y >>1); 512 reg_289c = (reg_289c + ((f->dst_y & ~1)<<15))+(f->dst_y >>1);
514 513
515 /* How much of the source to decode. 514 /* How much of the source to decode.
516 Take into account the source offset */ 515 Take into account the source offset */
517 reg_2960 = ((src_y_minor_y + window->src_h + src_y_major_y) - 1 ) | 516 reg_2960 = ((src_minor_y + f->src_h + src_major_y) - 1) |
518 ((((src_y_minor_uv + window->src_h + src_y_major_uv) - 1) & ~1) << 15); 517 (((src_minor_uv + f->src_h + src_major_uv - 1) & ~1) << 15);
519 518
520 /* Calculate correct value for register 2964 */ 519 /* Calculate correct value for register 2964 */
521 if (window->src_h == window->dst_h) 520 if (f->src_h == f->dst_h) {
522 reg_2964 = 1; 521 reg_2964 = 1;
523 else { 522 } else {
524 reg_2964 = 2 + ((window->dst_h << 1) / window->src_h); 523 reg_2964 = 2 + ((f->dst_h << 1) / f->src_h);
525 reg_2964 = (reg_2964 >> 1) + (reg_2964 & 1); 524 reg_2964 = (reg_2964 >> 1) + (reg_2964 & 1);
526 } 525 }
527 reg_2968 = (reg_2964 << 16) + reg_2964 + (reg_2964 >> 1); 526 reg_2968 = (reg_2964 << 16) + reg_2964 + (reg_2964 >> 1);
@@ -536,283 +535,246 @@ static void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *wi
536 /* Deviate further from what it should be. I find the flicker headache 535 /* Deviate further from what it should be. I find the flicker headache
537 inducing so try to reduce it slightly. Leave 2968 as-is otherwise 536 inducing so try to reduce it slightly. Leave 2968 as-is otherwise
538 colours foul. */ 537 colours foul. */
539 if ((reg_2964 != 0x00010001) && (window->dst_h / 2 <= window->src_h)) 538 if ((reg_2964 != 0x00010001) && (f->dst_h / 2 <= f->src_h))
540 reg_2964 = (reg_2964 & 0xFFFF0000) + ((reg_2964 & 0x0000FFFF)/2); 539 reg_2964 = (reg_2964 & 0xFFFF0000) + ((reg_2964 & 0x0000FFFF) / 2);
541 540
542 if (!window->interlaced_y) reg_2964 -= 0x00010001; 541 if (!f->interlaced_y)
543 if (!window->interlaced_uv) reg_2968 -= 0x00010001; 542 reg_2964 -= 0x00010001;
543 if (!f->interlaced_uv)
544 reg_2968 -= 0x00010001;
544 545
545 reg_2964 += ((reg_2964_base << 16) | reg_2964_base); 546 reg_2964 += ((reg_2964_base << 16) | reg_2964_base);
546 reg_2968 += ((reg_2968_base << 16) | reg_2968_base); 547 reg_2968 += ((reg_2968_base << 16) | reg_2968_base);
547 548
548 /* Select the vertical filter */ 549 /* Select the vertical filter */
549 if (window->src_h == window->dst_h) { 550 if (f->src_h == f->dst_h) {
550 /* An exact size match uses filter 0/1 */ 551 /* An exact size match uses filter 0/1 */
551 v_filter_1 = 0; 552 v_filter_1 = 0;
552 v_filter_2 = 1; 553 v_filter_2 = 1;
553 } 554 } else {
554 else {
555 /* Figure out which filter to use */ 555 /* Figure out which filter to use */
556 v_filter_1 = ((window->src_h << 16) / window->dst_h) >> 15; 556 v_filter_1 = ((f->src_h << 16) / f->dst_h) >> 15;
557 v_filter_1 = (v_filter_1 >> 1) + (v_filter_1 & 1); 557 v_filter_1 = (v_filter_1 >> 1) + (v_filter_1 & 1);
558 /* Only an exact size match can use filter 0 */ 558 /* Only an exact size match can use filter 0 */
559 if (v_filter_1 == 0) v_filter_1 = 1; 559 v_filter_1 += !v_filter_1;
560 v_filter_2 = v_filter_1; 560 v_filter_2 = v_filter_1;
561 } 561 }
562 562
563 write_reg(reg_2934, 0x02934); 563 write_reg(reg_2934, 0x02934);
564 write_reg(reg_293c, 0x0293c); 564 write_reg(reg_293c, 0x0293c);
565 IVTV_DEBUG_YUV("Update reg 0x2934 %08x->%08x 0x293c %08x->%08x\n",itv->yuv_info.reg_2934, reg_2934, itv->yuv_info.reg_293c, reg_293c); 565 IVTV_DEBUG_YUV("Update reg 0x2934 %08x->%08x 0x293c %08x->%08x\n",
566 yi->reg_2934, reg_2934, yi->reg_293c, reg_293c);
566 write_reg(reg_2944, 0x02944); 567 write_reg(reg_2944, 0x02944);
567 write_reg(reg_294c, 0x0294c); 568 write_reg(reg_294c, 0x0294c);
568 IVTV_DEBUG_YUV("Update reg 0x2944 %08x->%08x 0x294c %08x->%08x\n",itv->yuv_info.reg_2944, reg_2944, itv->yuv_info.reg_294c, reg_294c); 569 IVTV_DEBUG_YUV("Update reg 0x2944 %08x->%08x 0x294c %08x->%08x\n",
570 yi->reg_2944, reg_2944, yi->reg_294c, reg_294c);
569 571
570 /* Ensure 2970 is 0 (does it ever change ?) */ 572 /* Ensure 2970 is 0 (does it ever change ?) */
571/* write_reg(0,0x02970); */ 573/* write_reg(0,0x02970); */
572/* IVTV_DEBUG_YUV("Update reg 0x2970 %08x->%08x\n",itv->yuv_info.reg_2970, 0); */ 574/* IVTV_DEBUG_YUV("Update reg 0x2970 %08x->%08x\n", yi->reg_2970, 0); */
573 575
574 write_reg(reg_2930, 0x02938); 576 write_reg(reg_2930, 0x02938);
575 write_reg(reg_2930, 0x02930); 577 write_reg(reg_2930, 0x02930);
576 IVTV_DEBUG_YUV("Update reg 0x2930 %08x->%08x 0x2938 %08x->%08x\n",itv->yuv_info.reg_2930, reg_2930, itv->yuv_info.reg_2938, reg_2930); 578 IVTV_DEBUG_YUV("Update reg 0x2930 %08x->%08x 0x2938 %08x->%08x\n",
579 yi->reg_2930, reg_2930, yi->reg_2938, reg_2930);
577 580
578 write_reg(reg_2928, 0x02928); 581 write_reg(reg_2928, 0x02928);
579 write_reg(reg_2928+0x514, 0x0292C); 582 write_reg(reg_2928 + 0x514, 0x0292C);
580 IVTV_DEBUG_YUV("Update reg 0x2928 %08x->%08x 0x292c %08x->%08x\n",itv->yuv_info.reg_2928, reg_2928, itv->yuv_info.reg_292c, reg_2928+0x514); 583 IVTV_DEBUG_YUV("Update reg 0x2928 %08x->%08x 0x292c %08x->%08x\n",
584 yi->reg_2928, reg_2928, yi->reg_292c, reg_2928 + 0x514);
581 585
582 write_reg(reg_2920, 0x02920); 586 write_reg(reg_2920, 0x02920);
583 write_reg(reg_2920+0x514, 0x02924); 587 write_reg(reg_2920 + 0x514, 0x02924);
584 IVTV_DEBUG_YUV("Update reg 0x2920 %08x->%08x 0x2924 %08x->%08x\n",itv->yuv_info.reg_2920, reg_2920, itv->yuv_info.reg_2924, 0x514+reg_2920); 588 IVTV_DEBUG_YUV("Update reg 0x2920 %08x->%08x 0x2924 %08x->%08x\n",
589 yi->reg_2920, reg_2920, yi->reg_2924, reg_2920 + 0x514);
585 590
586 write_reg (reg_2918,0x02918); 591 write_reg(reg_2918, 0x02918);
587 write_reg (reg_291c,0x0291C); 592 write_reg(reg_291c, 0x0291C);
588 IVTV_DEBUG_YUV("Update reg 0x2918 %08x->%08x 0x291C %08x->%08x\n",itv->yuv_info.reg_2918,reg_2918,itv->yuv_info.reg_291c,reg_291c); 593 IVTV_DEBUG_YUV("Update reg 0x2918 %08x->%08x 0x291C %08x->%08x\n",
594 yi->reg_2918, reg_2918, yi->reg_291c, reg_291c);
589 595
590 write_reg(reg_296c, 0x0296c); 596 write_reg(reg_296c, 0x0296c);
591 IVTV_DEBUG_YUV("Update reg 0x296c %08x->%08x\n",itv->yuv_info.reg_296c, reg_296c); 597 IVTV_DEBUG_YUV("Update reg 0x296c %08x->%08x\n",
598 yi->reg_296c, reg_296c);
592 599
593 write_reg(reg_2940, 0x02948); 600 write_reg(reg_2940, 0x02948);
594 write_reg(reg_2940, 0x02940); 601 write_reg(reg_2940, 0x02940);
595 IVTV_DEBUG_YUV("Update reg 0x2940 %08x->%08x 0x2948 %08x->%08x\n",itv->yuv_info.reg_2940, reg_2940, itv->yuv_info.reg_2948, reg_2940); 602 IVTV_DEBUG_YUV("Update reg 0x2940 %08x->%08x 0x2948 %08x->%08x\n",
603 yi->reg_2940, reg_2940, yi->reg_2948, reg_2940);
596 604
597 write_reg(reg_2950, 0x02950); 605 write_reg(reg_2950, 0x02950);
598 write_reg(reg_2954, 0x02954); 606 write_reg(reg_2954, 0x02954);
599 IVTV_DEBUG_YUV("Update reg 0x2950 %08x->%08x 0x2954 %08x->%08x\n",itv->yuv_info.reg_2950, reg_2950, itv->yuv_info.reg_2954, reg_2954); 607 IVTV_DEBUG_YUV("Update reg 0x2950 %08x->%08x 0x2954 %08x->%08x\n",
608 yi->reg_2950, reg_2950, yi->reg_2954, reg_2954);
600 609
601 write_reg(reg_2958, 0x02958); 610 write_reg(reg_2958, 0x02958);
602 write_reg(reg_295c, 0x0295C); 611 write_reg(reg_295c, 0x0295C);
603 IVTV_DEBUG_YUV("Update reg 0x2958 %08x->%08x 0x295C %08x->%08x\n",itv->yuv_info.reg_2958, reg_2958, itv->yuv_info.reg_295c, reg_295c); 612 IVTV_DEBUG_YUV("Update reg 0x2958 %08x->%08x 0x295C %08x->%08x\n",
613 yi->reg_2958, reg_2958, yi->reg_295c, reg_295c);
604 614
605 write_reg(reg_2960, 0x02960); 615 write_reg(reg_2960, 0x02960);
606 IVTV_DEBUG_YUV("Update reg 0x2960 %08x->%08x \n",itv->yuv_info.reg_2960, reg_2960); 616 IVTV_DEBUG_YUV("Update reg 0x2960 %08x->%08x \n",
617 yi->reg_2960, reg_2960);
607 618
608 write_reg(reg_2964, 0x02964); 619 write_reg(reg_2964, 0x02964);
609 write_reg(reg_2968, 0x02968); 620 write_reg(reg_2968, 0x02968);
610 IVTV_DEBUG_YUV("Update reg 0x2964 %08x->%08x 0x2968 %08x->%08x\n",itv->yuv_info.reg_2964, reg_2964, itv->yuv_info.reg_2968, reg_2968); 621 IVTV_DEBUG_YUV("Update reg 0x2964 %08x->%08x 0x2968 %08x->%08x\n",
622 yi->reg_2964, reg_2964, yi->reg_2968, reg_2968);
611 623
612 write_reg( reg_289c,0x0289c); 624 write_reg(reg_289c, 0x0289c);
613 IVTV_DEBUG_YUV("Update reg 0x289c %08x->%08x\n",itv->yuv_info.reg_289c, reg_289c); 625 IVTV_DEBUG_YUV("Update reg 0x289c %08x->%08x\n",
626 yi->reg_289c, reg_289c);
614 627
615 /* Only update filter 1 if we really need to */ 628 /* Only update filter 1 if we really need to */
616 if (v_filter_1 != itv->yuv_info.v_filter_1) { 629 if (v_filter_1 != yi->v_filter_1) {
617 ivtv_yuv_filter (itv,-1,v_filter_1,-1); 630 ivtv_yuv_filter(itv, -1, v_filter_1, -1);
618 itv->yuv_info.v_filter_1 = v_filter_1; 631 yi->v_filter_1 = v_filter_1;
619 } 632 }
620 633
621 /* Only update filter 2 if we really need to */ 634 /* Only update filter 2 if we really need to */
622 if (v_filter_2 != itv->yuv_info.v_filter_2) { 635 if (v_filter_2 != yi->v_filter_2) {
623 ivtv_yuv_filter (itv,-1,-1,v_filter_2); 636 ivtv_yuv_filter(itv, -1, -1, v_filter_2);
624 itv->yuv_info.v_filter_2 = v_filter_2; 637 yi->v_filter_2 = v_filter_2;
625 } 638 }
626
627} 639}
628 640
629/* Modify the supplied coordinate information to fit the visible osd area */ 641/* Modify the supplied coordinate information to fit the visible osd area */
630static u32 ivtv_yuv_window_setup (struct ivtv *itv, struct yuv_frame_info *window) 642static u32 ivtv_yuv_window_setup(struct ivtv *itv, struct yuv_frame_info *f)
631{ 643{
632 int osd_crop, lace_threshold; 644 struct yuv_frame_info *of = &itv->yuv_info.old_frame_info;
645 int osd_crop;
633 u32 osd_scale; 646 u32 osd_scale;
634 u32 yuv_update = 0; 647 u32 yuv_update = 0;
635 648
636 lace_threshold = itv->yuv_info.lace_threshold;
637 if (lace_threshold < 0)
638 lace_threshold = itv->yuv_info.decode_height - 1;
639
640 /* Work out the lace settings */
641 switch (itv->yuv_info.lace_mode) {
642 case IVTV_YUV_MODE_PROGRESSIVE: /* Progressive mode */
643 itv->yuv_info.frame_interlaced = 0;
644 if (window->tru_h < 512 || (window->tru_h > 576 && window->tru_h < 1021))
645 window->interlaced_y = 0;
646 else
647 window->interlaced_y = 1;
648
649 if (window->tru_h < 1021 && (window->dst_h >= window->src_h /2))
650 window->interlaced_uv = 0;
651 else
652 window->interlaced_uv = 1;
653 break;
654
655 case IVTV_YUV_MODE_AUTO:
656 if (window->tru_h <= lace_threshold || window->tru_h > 576 || window->tru_w > 720){
657 itv->yuv_info.frame_interlaced = 0;
658 if ((window->tru_h < 512) ||
659 (window->tru_h > 576 && window->tru_h < 1021) ||
660 (window->tru_w > 720 && window->tru_h < 1021))
661 window->interlaced_y = 0;
662 else
663 window->interlaced_y = 1;
664
665 if (window->tru_h < 1021 && (window->dst_h >= window->src_h /2))
666 window->interlaced_uv = 0;
667 else
668 window->interlaced_uv = 1;
669 }
670 else {
671 itv->yuv_info.frame_interlaced = 1;
672 window->interlaced_y = 1;
673 window->interlaced_uv = 1;
674 }
675 break;
676
677 case IVTV_YUV_MODE_INTERLACED: /* Interlace mode */
678 default:
679 itv->yuv_info.frame_interlaced = 1;
680 window->interlaced_y = 1;
681 window->interlaced_uv = 1;
682 break;
683 }
684
685 /* Sorry, but no negative coords for src */ 649 /* Sorry, but no negative coords for src */
686 if (window->src_x < 0) window->src_x = 0; 650 if (f->src_x < 0)
687 if (window->src_y < 0) window->src_y = 0; 651 f->src_x = 0;
652 if (f->src_y < 0)
653 f->src_y = 0;
688 654
689 /* Can only reduce width down to 1/4 original size */ 655 /* Can only reduce width down to 1/4 original size */
690 if ((osd_crop = window->src_w - ( 4 * window->dst_w )) > 0) { 656 if ((osd_crop = f->src_w - 4 * f->dst_w) > 0) {
691 window->src_x += osd_crop / 2; 657 f->src_x += osd_crop / 2;
692 window->src_w = (window->src_w - osd_crop) & ~3; 658 f->src_w = (f->src_w - osd_crop) & ~3;
693 window->dst_w = window->src_w / 4; 659 f->dst_w = f->src_w / 4;
694 window->dst_w += window->dst_w & 1; 660 f->dst_w += f->dst_w & 1;
695 } 661 }
696 662
697 /* Can only reduce height down to 1/4 original size */ 663 /* Can only reduce height down to 1/4 original size */
698 if (window->src_h / window->dst_h >= 2) { 664 if (f->src_h / f->dst_h >= 2) {
699 /* Overflow may be because we're running progressive, so force mode switch */ 665 /* Overflow may be because we're running progressive,
700 window->interlaced_y = 1; 666 so force mode switch */
667 f->interlaced_y = 1;
701 /* Make sure we're still within limits for interlace */ 668 /* Make sure we're still within limits for interlace */
702 if ((osd_crop = window->src_h - ( 4 * window->dst_h )) > 0) { 669 if ((osd_crop = f->src_h - 4 * f->dst_h) > 0) {
703 /* If we reach here we'll have to force the height. */ 670 /* If we reach here we'll have to force the height. */
704 window->src_y += osd_crop / 2; 671 f->src_y += osd_crop / 2;
705 window->src_h = (window->src_h - osd_crop) & ~3; 672 f->src_h = (f->src_h - osd_crop) & ~3;
706 window->dst_h = window->src_h / 4; 673 f->dst_h = f->src_h / 4;
707 window->dst_h += window->dst_h & 1; 674 f->dst_h += f->dst_h & 1;
708 } 675 }
709 } 676 }
710 677
711 /* If there's nothing to safe to display, we may as well stop now */ 678 /* If there's nothing to safe to display, we may as well stop now */
712 if ((int)window->dst_w <= 2 || (int)window->dst_h <= 2 || (int)window->src_w <= 2 || (int)window->src_h <= 2) { 679 if ((int)f->dst_w <= 2 || (int)f->dst_h <= 2 ||
680 (int)f->src_w <= 2 || (int)f->src_h <= 2) {
713 return IVTV_YUV_UPDATE_INVALID; 681 return IVTV_YUV_UPDATE_INVALID;
714 } 682 }
715 683
716 /* Ensure video remains inside OSD area */ 684 /* Ensure video remains inside OSD area */
717 osd_scale = (window->src_h << 16) / window->dst_h; 685 osd_scale = (f->src_h << 16) / f->dst_h;
718 686
719 if ((osd_crop = window->pan_y - window->dst_y) > 0) { 687 if ((osd_crop = f->pan_y - f->dst_y) > 0) {
720 /* Falls off the upper edge - crop */ 688 /* Falls off the upper edge - crop */
721 window->src_y += (osd_scale * osd_crop) >> 16; 689 f->src_y += (osd_scale * osd_crop) >> 16;
722 window->src_h -= (osd_scale * osd_crop) >> 16; 690 f->src_h -= (osd_scale * osd_crop) >> 16;
723 window->dst_h -= osd_crop; 691 f->dst_h -= osd_crop;
724 window->dst_y = 0; 692 f->dst_y = 0;
725 } 693 } else {
726 else { 694 f->dst_y -= f->pan_y;
727 window->dst_y -= window->pan_y;
728 } 695 }
729 696
730 if ((osd_crop = window->dst_h + window->dst_y - window->vis_h) > 0) { 697 if ((osd_crop = f->dst_h + f->dst_y - f->vis_h) > 0) {
731 /* Falls off the lower edge - crop */ 698 /* Falls off the lower edge - crop */
732 window->dst_h -= osd_crop; 699 f->dst_h -= osd_crop;
733 window->src_h -= (osd_scale * osd_crop) >> 16; 700 f->src_h -= (osd_scale * osd_crop) >> 16;
734 } 701 }
735 702
736 osd_scale = (window->src_w << 16) / window->dst_w; 703 osd_scale = (f->src_w << 16) / f->dst_w;
737 704
738 if ((osd_crop = window->pan_x - window->dst_x) > 0) { 705 if ((osd_crop = f->pan_x - f->dst_x) > 0) {
739 /* Fall off the left edge - crop */ 706 /* Fall off the left edge - crop */
740 window->src_x += (osd_scale * osd_crop) >> 16; 707 f->src_x += (osd_scale * osd_crop) >> 16;
741 window->src_w -= (osd_scale * osd_crop) >> 16; 708 f->src_w -= (osd_scale * osd_crop) >> 16;
742 window->dst_w -= osd_crop; 709 f->dst_w -= osd_crop;
743 window->dst_x = 0; 710 f->dst_x = 0;
744 } 711 } else {
745 else { 712 f->dst_x -= f->pan_x;
746 window->dst_x -= window->pan_x;
747 } 713 }
748 714
749 if ((osd_crop = window->dst_w + window->dst_x - window->vis_w) > 0) { 715 if ((osd_crop = f->dst_w + f->dst_x - f->vis_w) > 0) {
750 /* Falls off the right edge - crop */ 716 /* Falls off the right edge - crop */
751 window->dst_w -= osd_crop; 717 f->dst_w -= osd_crop;
752 window->src_w -= (osd_scale * osd_crop) >> 16; 718 f->src_w -= (osd_scale * osd_crop) >> 16;
753 } 719 }
754 720
755 /* The OSD can be moved. Track to it */ 721 /* The OSD can be moved. Track to it */
756 window->dst_x += itv->yuv_info.osd_x_offset; 722 f->dst_x += itv->yuv_info.osd_x_offset;
757 window->dst_y += itv->yuv_info.osd_y_offset; 723 f->dst_y += itv->yuv_info.osd_y_offset;
758 724
759 /* Width & height for both src & dst must be even. 725 /* Width & height for both src & dst must be even.
760 Same for coordinates. */ 726 Same for coordinates. */
761 window->dst_w &= ~1; 727 f->dst_w &= ~1;
762 window->dst_x &= ~1; 728 f->dst_x &= ~1;
763 729
764 window->src_w += window->src_x & 1; 730 f->src_w += f->src_x & 1;
765 window->src_x &= ~1; 731 f->src_x &= ~1;
766 732
767 window->src_w &= ~1; 733 f->src_w &= ~1;
768 window->dst_w &= ~1; 734 f->dst_w &= ~1;
769 735
770 window->dst_h &= ~1; 736 f->dst_h &= ~1;
771 window->dst_y &= ~1; 737 f->dst_y &= ~1;
772 738
773 window->src_h += window->src_y & 1; 739 f->src_h += f->src_y & 1;
774 window->src_y &= ~1; 740 f->src_y &= ~1;
775 741
776 window->src_h &= ~1; 742 f->src_h &= ~1;
777 window->dst_h &= ~1; 743 f->dst_h &= ~1;
778 744
779 /* Due to rounding, we may have reduced the output size to <1/4 of the source 745 /* Due to rounding, we may have reduced the output size to <1/4 of
780 Check again, but this time just resize. Don't change source coordinates */ 746 the source. Check again, but this time just resize. Don't change
781 if (window->dst_w < window->src_w / 4) { 747 source coordinates */
782 window->src_w &= ~3; 748 if (f->dst_w < f->src_w / 4) {
783 window->dst_w = window->src_w / 4; 749 f->src_w &= ~3;
784 window->dst_w += window->dst_w & 1; 750 f->dst_w = f->src_w / 4;
751 f->dst_w += f->dst_w & 1;
785 } 752 }
786 if (window->dst_h < window->src_h / 4) { 753 if (f->dst_h < f->src_h / 4) {
787 window->src_h &= ~3; 754 f->src_h &= ~3;
788 window->dst_h = window->src_h / 4; 755 f->dst_h = f->src_h / 4;
789 window->dst_h += window->dst_h & 1; 756 f->dst_h += f->dst_h & 1;
790 } 757 }
791 758
792 /* Check again. If there's nothing to safe to display, stop now */ 759 /* Check again. If there's nothing to safe to display, stop now */
793 if ((int)window->dst_w <= 2 || (int)window->dst_h <= 2 || (int)window->src_w <= 2 || (int)window->src_h <= 2) { 760 if ((int)f->dst_w <= 2 || (int)f->dst_h <= 2 ||
761 (int)f->src_w <= 2 || (int)f->src_h <= 2) {
794 return IVTV_YUV_UPDATE_INVALID; 762 return IVTV_YUV_UPDATE_INVALID;
795 } 763 }
796 764
797 /* Both x offset & width are linked, so they have to be done together */ 765 /* Both x offset & width are linked, so they have to be done together */
798 if ((itv->yuv_info.old_frame_info.dst_w != window->dst_w) || 766 if ((of->dst_w != f->dst_w) || (of->src_w != f->src_w) ||
799 (itv->yuv_info.old_frame_info.src_w != window->src_w) || 767 (of->dst_x != f->dst_x) || (of->src_x != f->src_x) ||
800 (itv->yuv_info.old_frame_info.dst_x != window->dst_x) || 768 (of->pan_x != f->pan_x) || (of->vis_w != f->vis_w)) {
801 (itv->yuv_info.old_frame_info.src_x != window->src_x) ||
802 (itv->yuv_info.old_frame_info.pan_x != window->pan_x) ||
803 (itv->yuv_info.old_frame_info.vis_w != window->vis_w)) {
804 yuv_update |= IVTV_YUV_UPDATE_HORIZONTAL; 769 yuv_update |= IVTV_YUV_UPDATE_HORIZONTAL;
805 } 770 }
806 771
807 if ((itv->yuv_info.old_frame_info.src_h != window->src_h) || 772 if ((of->src_h != f->src_h) || (of->dst_h != f->dst_h) ||
808 (itv->yuv_info.old_frame_info.dst_h != window->dst_h) || 773 (of->dst_y != f->dst_y) || (of->src_y != f->src_y) ||
809 (itv->yuv_info.old_frame_info.dst_y != window->dst_y) || 774 (of->pan_y != f->pan_y) || (of->vis_h != f->vis_h) ||
810 (itv->yuv_info.old_frame_info.src_y != window->src_y) || 775 (of->lace_mode != f->lace_mode) ||
811 (itv->yuv_info.old_frame_info.pan_y != window->pan_y) || 776 (of->interlaced_y != f->interlaced_y) ||
812 (itv->yuv_info.old_frame_info.vis_h != window->vis_h) || 777 (of->interlaced_uv != f->interlaced_uv)) {
813 (itv->yuv_info.old_frame_info.lace_mode != window->lace_mode) ||
814 (itv->yuv_info.old_frame_info.interlaced_y != window->interlaced_y) ||
815 (itv->yuv_info.old_frame_info.interlaced_uv != window->interlaced_uv)) {
816 yuv_update |= IVTV_YUV_UPDATE_VERTICAL; 778 yuv_update |= IVTV_YUV_UPDATE_VERTICAL;
817 } 779 }
818 780
@@ -820,24 +782,24 @@ static u32 ivtv_yuv_window_setup (struct ivtv *itv, struct yuv_frame_info *windo
820} 782}
821 783
822/* Update the scaling register to the requested value */ 784/* Update the scaling register to the requested value */
823void ivtv_yuv_work_handler (struct ivtv *itv) 785void ivtv_yuv_work_handler(struct ivtv *itv)
824{ 786{
825 struct yuv_frame_info window; 787 struct yuv_playback_info *yi = &itv->yuv_info;
788 struct yuv_frame_info f;
789 int frame = yi->update_frame;
826 u32 yuv_update; 790 u32 yuv_update;
827 791
828 int frame = itv->yuv_info.update_frame; 792 IVTV_DEBUG_YUV("Update yuv registers for frame %d\n", frame);
829 793 f = yi->new_frame_info[frame];
830/* IVTV_DEBUG_YUV("Update yuv registers for frame %d\n",frame); */
831 memcpy(&window, &itv->yuv_info.new_frame_info[frame], sizeof (window));
832 794
833 /* Update the osd pan info */ 795 /* Update the osd pan info */
834 window.pan_x = itv->yuv_info.osd_x_pan; 796 f.pan_x = yi->osd_x_pan;
835 window.pan_y = itv->yuv_info.osd_y_pan; 797 f.pan_y = yi->osd_y_pan;
836 window.vis_w = itv->yuv_info.osd_vis_w; 798 f.vis_w = yi->osd_vis_w;
837 window.vis_h = itv->yuv_info.osd_vis_h; 799 f.vis_h = yi->osd_vis_h;
838 800
839 /* Calculate the display window coordinates. Exit if nothing left */ 801 /* Calculate the display window coordinates. Exit if nothing left */
840 if (!(yuv_update = ivtv_yuv_window_setup (itv, &window))) 802 if (!(yuv_update = ivtv_yuv_window_setup(itv, &f)))
841 return; 803 return;
842 804
843 if (yuv_update & IVTV_YUV_UPDATE_INVALID) { 805 if (yuv_update & IVTV_YUV_UPDATE_INVALID) {
@@ -846,16 +808,15 @@ void ivtv_yuv_work_handler (struct ivtv *itv)
846 write_reg(0x00108080, 0x2898); 808 write_reg(0x00108080, 0x2898);
847 809
848 if (yuv_update & IVTV_YUV_UPDATE_HORIZONTAL) 810 if (yuv_update & IVTV_YUV_UPDATE_HORIZONTAL)
849 ivtv_yuv_handle_horizontal(itv, &window); 811 ivtv_yuv_handle_horizontal(itv, &f);
850 812
851 if (yuv_update & IVTV_YUV_UPDATE_VERTICAL) 813 if (yuv_update & IVTV_YUV_UPDATE_VERTICAL)
852 ivtv_yuv_handle_vertical(itv, &window); 814 ivtv_yuv_handle_vertical(itv, &f);
853 } 815 }
854 816 yi->old_frame_info = f;
855 memcpy(&itv->yuv_info.old_frame_info, &window, sizeof (itv->yuv_info.old_frame_info));
856} 817}
857 818
858static void ivtv_yuv_init (struct ivtv *itv) 819static void ivtv_yuv_init(struct ivtv *itv)
859{ 820{
860 struct yuv_playback_info *yi = &itv->yuv_info; 821 struct yuv_playback_info *yi = &itv->yuv_info;
861 822
@@ -924,25 +885,23 @@ static void ivtv_yuv_init (struct ivtv *itv)
924 if (!yi->osd_vis_w) 885 if (!yi->osd_vis_w)
925 yi->osd_vis_w = 720 - yi->osd_x_offset; 886 yi->osd_vis_w = 720 - yi->osd_x_offset;
926 887
927 if (!yi->osd_vis_h) 888 if (!yi->osd_vis_h) {
928 yi->osd_vis_h = yi->decode_height - yi->osd_y_offset; 889 yi->osd_vis_h = yi->decode_height - yi->osd_y_offset;
929 else { 890 } else if (yi->osd_vis_h + yi->osd_y_offset > yi->decode_height) {
930 /* If output video standard has changed, requested height may 891 /* If output video standard has changed, requested height may
931 not be legal */ 892 not be legal */
932 if (yi->osd_vis_h + yi->osd_y_offset > yi->decode_height) { 893 IVTV_DEBUG_WARN("Clipping yuv output - fb size (%d) exceeds video standard limit (%d)\n",
933 IVTV_DEBUG_WARN("Clipping yuv output - fb size (%d) exceeds video standard limit (%d)\n", 894 yi->osd_vis_h + yi->osd_y_offset,
934 yi->osd_vis_h + yi->osd_y_offset, 895 yi->decode_height);
935 yi->decode_height); 896 yi->osd_vis_h = yi->decode_height - yi->osd_y_offset;
936 yi->osd_vis_h = yi->decode_height - yi->osd_y_offset;
937 }
938 } 897 }
939 } 898 }
940 899
941 /* We need a buffer for blanking when Y plane is offset - non-fatal if we can't get one */ 900 /* We need a buffer for blanking when Y plane is offset - non-fatal if we can't get one */
942 yi->blanking_ptr = kzalloc(720*16, GFP_KERNEL); 901 yi->blanking_ptr = kzalloc(720 * 16, GFP_KERNEL);
943 if (yi->blanking_ptr) 902 if (yi->blanking_ptr) {
944 yi->blanking_dmaptr = pci_map_single(itv->dev, yi->blanking_ptr, 720*16, PCI_DMA_TODEVICE); 903 yi->blanking_dmaptr = pci_map_single(itv->dev, yi->blanking_ptr, 720*16, PCI_DMA_TODEVICE);
945 else { 904 } else {
946 yi->blanking_dmaptr = 0; 905 yi->blanking_dmaptr = 0;
947 IVTV_DEBUG_WARN("Failed to allocate yuv blanking buffer\n"); 906 IVTV_DEBUG_WARN("Failed to allocate yuv blanking buffer\n");
948 } 907 }
@@ -954,77 +913,140 @@ static void ivtv_yuv_init (struct ivtv *itv)
954 atomic_set(&yi->next_dma_frame, 0); 913 atomic_set(&yi->next_dma_frame, 0);
955} 914}
956 915
957int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args) 916/* Get next available yuv buffer on PVR350 */
917void ivtv_yuv_next_free(struct ivtv *itv)
958{ 918{
959 DEFINE_WAIT(wait); 919 int draw, display;
960 int rc = 0; 920 struct yuv_playback_info *yi = &itv->yuv_info;
961 int got_sig = 0;
962 int frame, next_fill_frame, last_fill_frame;
963 int register_update = 0;
964 921
965 IVTV_DEBUG_INFO("yuv_prep_frame\n"); 922 if (atomic_read(&yi->next_dma_frame) == -1)
923 ivtv_yuv_init(itv);
966 924
967 if (atomic_read(&itv->yuv_info.next_dma_frame) == -1) ivtv_yuv_init(itv); 925 draw = atomic_read(&yi->next_fill_frame);
926 display = atomic_read(&yi->next_dma_frame);
968 927
969 frame = atomic_read(&itv->yuv_info.next_fill_frame); 928 if (display > draw)
970 next_fill_frame = (frame + 1) & 0x3; 929 display -= IVTV_YUV_BUFFERS;
971 last_fill_frame = (atomic_read(&itv->yuv_info.next_dma_frame)+1) & 0x3;
972 930
973 if (next_fill_frame != last_fill_frame && last_fill_frame != frame) { 931 if (draw - display >= yi->max_frames_buffered)
974 /* Buffers are full - Overwrite the last frame */ 932 draw = (u8)(draw - 1) % IVTV_YUV_BUFFERS;
975 next_fill_frame = frame; 933 else
976 frame = (frame - 1) & 3; 934 yi->new_frame_info[draw].update = 0;
977 register_update = itv->yuv_info.new_frame_info[frame].update; 935
978 } 936 yi->draw_frame = draw;
937}
938
939/* Set up frame according to ivtv_dma_frame parameters */
940void ivtv_yuv_setup_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
941{
942 struct yuv_playback_info *yi = &itv->yuv_info;
943 u8 frame = yi->draw_frame;
944 u8 last_frame = (u8)(frame - 1) % IVTV_YUV_BUFFERS;
945 struct yuv_frame_info *nf = &yi->new_frame_info[frame];
946 struct yuv_frame_info *of = &yi->new_frame_info[last_frame];
947 int lace_threshold = yi->lace_threshold;
948
949 /* Preserve old update flag in case we're overwriting a queued frame */
950 int update = nf->update;
979 951
980 /* Take a snapshot of the yuv coordinate information */ 952 /* Take a snapshot of the yuv coordinate information */
981 itv->yuv_info.new_frame_info[frame].src_x = args->src.left; 953 nf->src_x = args->src.left;
982 itv->yuv_info.new_frame_info[frame].src_y = args->src.top; 954 nf->src_y = args->src.top;
983 itv->yuv_info.new_frame_info[frame].src_w = args->src.width; 955 nf->src_w = args->src.width;
984 itv->yuv_info.new_frame_info[frame].src_h = args->src.height; 956 nf->src_h = args->src.height;
985 itv->yuv_info.new_frame_info[frame].dst_x = args->dst.left; 957 nf->dst_x = args->dst.left;
986 itv->yuv_info.new_frame_info[frame].dst_y = args->dst.top; 958 nf->dst_y = args->dst.top;
987 itv->yuv_info.new_frame_info[frame].dst_w = args->dst.width; 959 nf->dst_w = args->dst.width;
988 itv->yuv_info.new_frame_info[frame].dst_h = args->dst.height; 960 nf->dst_h = args->dst.height;
989 itv->yuv_info.new_frame_info[frame].tru_x = args->dst.left; 961 nf->tru_x = args->dst.left;
990 itv->yuv_info.new_frame_info[frame].tru_w = args->src_width; 962 nf->tru_w = args->src_width;
991 itv->yuv_info.new_frame_info[frame].tru_h = args->src_height; 963 nf->tru_h = args->src_height;
992
993 /* Snapshot field order */
994 itv->yuv_info.sync_field[frame] = itv->yuv_info.lace_sync_field;
995 964
996 /* Are we going to offset the Y plane */ 965 /* Are we going to offset the Y plane */
997 if (args->src.height + args->src.top < 512-16) 966 nf->offset_y = (nf->tru_h + nf->src_x < 512 - 16) ? 1 : 0;
998 itv->yuv_info.new_frame_info[frame].offset_y = 1;
999 else
1000 itv->yuv_info.new_frame_info[frame].offset_y = 0;
1001 967
1002 /* Snapshot the osd pan info */ 968 /* Snapshot the osd pan info */
1003 itv->yuv_info.new_frame_info[frame].pan_x = itv->yuv_info.osd_x_pan; 969 nf->pan_x = yi->osd_x_pan;
1004 itv->yuv_info.new_frame_info[frame].pan_y = itv->yuv_info.osd_y_pan; 970 nf->pan_y = yi->osd_y_pan;
1005 itv->yuv_info.new_frame_info[frame].vis_w = itv->yuv_info.osd_vis_w; 971 nf->vis_w = yi->osd_vis_w;
1006 itv->yuv_info.new_frame_info[frame].vis_h = itv->yuv_info.osd_vis_h; 972 nf->vis_h = yi->osd_vis_h;
1007 973
1008 itv->yuv_info.new_frame_info[frame].update = 0; 974 nf->update = 0;
1009 itv->yuv_info.new_frame_info[frame].interlaced_y = 0; 975 nf->interlaced_y = 0;
1010 itv->yuv_info.new_frame_info[frame].interlaced_uv = 0; 976 nf->interlaced_uv = 0;
1011 itv->yuv_info.new_frame_info[frame].lace_mode = itv->yuv_info.lace_mode; 977 nf->delay = 0;
1012 978 nf->sync_field = 0;
1013 if (memcmp (&itv->yuv_info.old_frame_info_args, &itv->yuv_info.new_frame_info[frame], 979 nf->lace_mode = yi->lace_mode & IVTV_YUV_MODE_MASK;
1014 sizeof (itv->yuv_info.new_frame_info[frame]))) { 980
1015 memcpy(&itv->yuv_info.old_frame_info_args, &itv->yuv_info.new_frame_info[frame], sizeof (itv->yuv_info.old_frame_info_args)); 981 if (lace_threshold < 0)
1016 itv->yuv_info.new_frame_info[frame].update = 1; 982 lace_threshold = yi->decode_height - 1;
1017/* IVTV_DEBUG_YUV ("Requesting register update for frame %d\n",frame); */ 983
984 /* Work out the lace settings */
985 switch (nf->lace_mode) {
986 case IVTV_YUV_MODE_PROGRESSIVE: /* Progressive mode */
987 nf->interlaced = 0;
988 if (nf->tru_h < 512 || (nf->tru_h > 576 && nf->tru_h < 1021))
989 nf->interlaced_y = 0;
990 else
991 nf->interlaced_y = 1;
992
993 if (nf->tru_h < 1021 && (nf->dst_h >= nf->src_h / 2))
994 nf->interlaced_uv = 0;
995 else
996 nf->interlaced_uv = 1;
997 break;
998
999 case IVTV_YUV_MODE_AUTO:
1000 if (nf->tru_h <= lace_threshold || nf->tru_h > 576 || nf->tru_w > 720) {
1001 nf->interlaced = 0;
1002 if ((nf->tru_h < 512) ||
1003 (nf->tru_h > 576 && nf->tru_h < 1021) ||
1004 (nf->tru_w > 720 && nf->tru_h < 1021))
1005 nf->interlaced_y = 0;
1006 else
1007 nf->interlaced_y = 1;
1008 if (nf->tru_h < 1021 && (nf->dst_h >= nf->src_h / 2))
1009 nf->interlaced_uv = 0;
1010 else
1011 nf->interlaced_uv = 1;
1012 } else {
1013 nf->interlaced = 1;
1014 nf->interlaced_y = 1;
1015 nf->interlaced_uv = 1;
1016 }
1017 break;
1018
1019 case IVTV_YUV_MODE_INTERLACED: /* Interlace mode */
1020 default:
1021 nf->interlaced = 1;
1022 nf->interlaced_y = 1;
1023 nf->interlaced_uv = 1;
1024 break;
1018 } 1025 }
1019 1026
1020 itv->yuv_info.new_frame_info[frame].update |= register_update; 1027 if (memcmp(&yi->old_frame_info_args, nf, sizeof(*nf))) {
1028 yi->old_frame_info_args = *nf;
1029 nf->update = 1;
1030 IVTV_DEBUG_YUV("Requesting reg update for frame %d\n", frame);
1031 }
1021 1032
1022 /* Should this frame be delayed ? */ 1033 nf->update |= update;
1023 if (itv->yuv_info.sync_field[frame] != itv->yuv_info.sync_field[(frame - 1) & 3]) 1034 nf->sync_field = yi->lace_sync_field;
1024 itv->yuv_info.field_delay[frame] = 1; 1035 nf->delay = nf->sync_field != of->sync_field;
1025 else 1036}
1026 itv->yuv_info.field_delay[frame] = 0;
1027 1037
1038/* Frame is complete & ready for display */
1039void ivtv_yuv_frame_complete(struct ivtv *itv)
1040{
1041 atomic_set(&itv->yuv_info.next_fill_frame,
1042 (itv->yuv_info.draw_frame + 1) % IVTV_YUV_BUFFERS);
1043}
1044
1045int ivtv_yuv_udma_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
1046{
1047 DEFINE_WAIT(wait);
1048 int rc = 0;
1049 int got_sig = 0;
1028 /* DMA the frame */ 1050 /* DMA the frame */
1029 mutex_lock(&itv->udma.lock); 1051 mutex_lock(&itv->udma.lock);
1030 1052
@@ -1036,10 +1058,10 @@ int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
1036 ivtv_udma_prepare(itv); 1058 ivtv_udma_prepare(itv);
1037 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE); 1059 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE);
1038 /* if no UDMA is pending and no UDMA is in progress, then the DMA 1060 /* if no UDMA is pending and no UDMA is in progress, then the DMA
1039 is finished */ 1061 is finished */
1040 while (itv->i_flags & (IVTV_F_I_UDMA_PENDING | IVTV_F_I_UDMA)) { 1062 while (itv->i_flags & (IVTV_F_I_UDMA_PENDING | IVTV_F_I_UDMA)) {
1041 /* don't interrupt if the DMA is in progress but break off 1063 /* don't interrupt if the DMA is in progress but break off
1042 a still pending DMA. */ 1064 a still pending DMA. */
1043 got_sig = signal_pending(current); 1065 got_sig = signal_pending(current);
1044 if (got_sig && test_and_clear_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags)) 1066 if (got_sig && test_and_clear_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags))
1045 break; 1067 break;
@@ -1057,99 +1079,148 @@ int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
1057 return -EINTR; 1079 return -EINTR;
1058 } 1080 }
1059 1081
1060 atomic_set(&itv->yuv_info.next_fill_frame, next_fill_frame); 1082 ivtv_yuv_frame_complete(itv);
1061 1083
1062 mutex_unlock(&itv->udma.lock); 1084 mutex_unlock(&itv->udma.lock);
1063 return rc; 1085 return rc;
1064} 1086}
1065 1087
1088/* Setup frame according to V4L2 parameters */
1089void ivtv_yuv_setup_stream_frame(struct ivtv *itv)
1090{
1091 struct yuv_playback_info *yi = &itv->yuv_info;
1092 struct ivtv_dma_frame dma_args;
1093
1094 ivtv_yuv_next_free(itv);
1095
1096 /* Copy V4L2 parameters to an ivtv_dma_frame struct... */
1097 dma_args.y_source = 0L;
1098 dma_args.uv_source = 0L;
1099 dma_args.src.left = 0;
1100 dma_args.src.top = 0;
1101 dma_args.src.width = yi->v4l2_src_w;
1102 dma_args.src.height = yi->v4l2_src_h;
1103 dma_args.dst = yi->main_rect;
1104 dma_args.src_width = yi->v4l2_src_w;
1105 dma_args.src_height = yi->v4l2_src_h;
1106
1107 /* ... and use the same setup routine as ivtv_yuv_prep_frame */
1108 ivtv_yuv_setup_frame(itv, &dma_args);
1109
1110 if (!itv->dma_data_req_offset)
1111 itv->dma_data_req_offset = yuv_offset[yi->draw_frame];
1112}
1113
1114/* Attempt to dma a frame from a user buffer */
1115int ivtv_yuv_udma_stream_frame(struct ivtv *itv, void *src)
1116{
1117 struct yuv_playback_info *yi = &itv->yuv_info;
1118 struct ivtv_dma_frame dma_args;
1119
1120 ivtv_yuv_setup_stream_frame(itv);
1121
1122 /* We only need to supply source addresses for this */
1123 dma_args.y_source = src;
1124 dma_args.uv_source = src + 720 * ((yi->v4l2_src_h + 31) & ~31);
1125 return ivtv_yuv_udma_frame(itv, &dma_args);
1126}
1127
1128/* IVTV_IOC_DMA_FRAME ioctl handler */
1129int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
1130{
1131/* IVTV_DEBUG_INFO("yuv_prep_frame\n"); */
1132
1133 ivtv_yuv_next_free(itv);
1134 ivtv_yuv_setup_frame(itv, args);
1135 return ivtv_yuv_udma_frame(itv, args);
1136}
1137
1066void ivtv_yuv_close(struct ivtv *itv) 1138void ivtv_yuv_close(struct ivtv *itv)
1067{ 1139{
1140 struct yuv_playback_info *yi = &itv->yuv_info;
1068 int h_filter, v_filter_1, v_filter_2; 1141 int h_filter, v_filter_1, v_filter_2;
1069 1142
1070 IVTV_DEBUG_YUV("ivtv_yuv_close\n"); 1143 IVTV_DEBUG_YUV("ivtv_yuv_close\n");
1071 ivtv_waitq(&itv->vsync_waitq); 1144 ivtv_waitq(&itv->vsync_waitq);
1072 1145
1073 atomic_set(&itv->yuv_info.next_dma_frame, -1); 1146 atomic_set(&yi->next_dma_frame, -1);
1074 atomic_set(&itv->yuv_info.next_fill_frame, 0); 1147 atomic_set(&yi->next_fill_frame, 0);
1075 1148
1076 /* Reset registers we have changed so mpeg playback works */ 1149 /* Reset registers we have changed so mpeg playback works */
1077 1150
1078 /* If we fully restore this register, the display may remain active. 1151 /* If we fully restore this register, the display may remain active.
1079 Restore, but set one bit to blank the video. Firmware will always 1152 Restore, but set one bit to blank the video. Firmware will always
1080 clear this bit when needed, so not a problem. */ 1153 clear this bit when needed, so not a problem. */
1081 write_reg(itv->yuv_info.reg_2898 | 0x01000000, 0x2898); 1154 write_reg(yi->reg_2898 | 0x01000000, 0x2898);
1082 1155
1083 write_reg(itv->yuv_info.reg_2834, 0x02834); 1156 write_reg(yi->reg_2834, 0x02834);
1084 write_reg(itv->yuv_info.reg_2838, 0x02838); 1157 write_reg(yi->reg_2838, 0x02838);
1085 write_reg(itv->yuv_info.reg_283c, 0x0283c); 1158 write_reg(yi->reg_283c, 0x0283c);
1086 write_reg(itv->yuv_info.reg_2840, 0x02840); 1159 write_reg(yi->reg_2840, 0x02840);
1087 write_reg(itv->yuv_info.reg_2844, 0x02844); 1160 write_reg(yi->reg_2844, 0x02844);
1088 write_reg(itv->yuv_info.reg_2848, 0x02848); 1161 write_reg(yi->reg_2848, 0x02848);
1089 write_reg(itv->yuv_info.reg_2854, 0x02854); 1162 write_reg(yi->reg_2854, 0x02854);
1090 write_reg(itv->yuv_info.reg_285c, 0x0285c); 1163 write_reg(yi->reg_285c, 0x0285c);
1091 write_reg(itv->yuv_info.reg_2864, 0x02864); 1164 write_reg(yi->reg_2864, 0x02864);
1092 write_reg(itv->yuv_info.reg_2870, 0x02870); 1165 write_reg(yi->reg_2870, 0x02870);
1093 write_reg(itv->yuv_info.reg_2874, 0x02874); 1166 write_reg(yi->reg_2874, 0x02874);
1094 write_reg(itv->yuv_info.reg_2890, 0x02890); 1167 write_reg(yi->reg_2890, 0x02890);
1095 write_reg(itv->yuv_info.reg_289c, 0x0289c); 1168 write_reg(yi->reg_289c, 0x0289c);
1096 1169
1097 write_reg(itv->yuv_info.reg_2918, 0x02918); 1170 write_reg(yi->reg_2918, 0x02918);
1098 write_reg(itv->yuv_info.reg_291c, 0x0291c); 1171 write_reg(yi->reg_291c, 0x0291c);
1099 write_reg(itv->yuv_info.reg_2920, 0x02920); 1172 write_reg(yi->reg_2920, 0x02920);
1100 write_reg(itv->yuv_info.reg_2924, 0x02924); 1173 write_reg(yi->reg_2924, 0x02924);
1101 write_reg(itv->yuv_info.reg_2928, 0x02928); 1174 write_reg(yi->reg_2928, 0x02928);
1102 write_reg(itv->yuv_info.reg_292c, 0x0292c); 1175 write_reg(yi->reg_292c, 0x0292c);
1103 write_reg(itv->yuv_info.reg_2930, 0x02930); 1176 write_reg(yi->reg_2930, 0x02930);
1104 write_reg(itv->yuv_info.reg_2934, 0x02934); 1177 write_reg(yi->reg_2934, 0x02934);
1105 write_reg(itv->yuv_info.reg_2938, 0x02938); 1178 write_reg(yi->reg_2938, 0x02938);
1106 write_reg(itv->yuv_info.reg_293c, 0x0293c); 1179 write_reg(yi->reg_293c, 0x0293c);
1107 write_reg(itv->yuv_info.reg_2940, 0x02940); 1180 write_reg(yi->reg_2940, 0x02940);
1108 write_reg(itv->yuv_info.reg_2944, 0x02944); 1181 write_reg(yi->reg_2944, 0x02944);
1109 write_reg(itv->yuv_info.reg_2948, 0x02948); 1182 write_reg(yi->reg_2948, 0x02948);
1110 write_reg(itv->yuv_info.reg_294c, 0x0294c); 1183 write_reg(yi->reg_294c, 0x0294c);
1111 write_reg(itv->yuv_info.reg_2950, 0x02950); 1184 write_reg(yi->reg_2950, 0x02950);
1112 write_reg(itv->yuv_info.reg_2954, 0x02954); 1185 write_reg(yi->reg_2954, 0x02954);
1113 write_reg(itv->yuv_info.reg_2958, 0x02958); 1186 write_reg(yi->reg_2958, 0x02958);
1114 write_reg(itv->yuv_info.reg_295c, 0x0295c); 1187 write_reg(yi->reg_295c, 0x0295c);
1115 write_reg(itv->yuv_info.reg_2960, 0x02960); 1188 write_reg(yi->reg_2960, 0x02960);
1116 write_reg(itv->yuv_info.reg_2964, 0x02964); 1189 write_reg(yi->reg_2964, 0x02964);
1117 write_reg(itv->yuv_info.reg_2968, 0x02968); 1190 write_reg(yi->reg_2968, 0x02968);
1118 write_reg(itv->yuv_info.reg_296c, 0x0296c); 1191 write_reg(yi->reg_296c, 0x0296c);
1119 write_reg(itv->yuv_info.reg_2970, 0x02970); 1192 write_reg(yi->reg_2970, 0x02970);
1120 1193
1121 /* Prepare to restore filters */ 1194 /* Prepare to restore filters */
1122 1195
1123 /* First the horizontal filter */ 1196 /* First the horizontal filter */
1124 if ((itv->yuv_info.reg_2834 & 0x0000FFFF) == (itv->yuv_info.reg_2834 >> 16)) { 1197 if ((yi->reg_2834 & 0x0000FFFF) == (yi->reg_2834 >> 16)) {
1125 /* An exact size match uses filter 0 */ 1198 /* An exact size match uses filter 0 */
1126 h_filter = 0; 1199 h_filter = 0;
1127 } 1200 } else {
1128 else {
1129 /* Figure out which filter to use */ 1201 /* Figure out which filter to use */
1130 h_filter = ((itv->yuv_info.reg_2834 << 16) / (itv->yuv_info.reg_2834 >> 16)) >> 15; 1202 h_filter = ((yi->reg_2834 << 16) / (yi->reg_2834 >> 16)) >> 15;
1131 h_filter = (h_filter >> 1) + (h_filter & 1); 1203 h_filter = (h_filter >> 1) + (h_filter & 1);
1132 /* Only an exact size match can use filter 0. */ 1204 /* Only an exact size match can use filter 0. */
1133 if (h_filter < 1) h_filter = 1; 1205 h_filter += !h_filter;
1134 } 1206 }
1135 1207
1136 /* Now the vertical filter */ 1208 /* Now the vertical filter */
1137 if ((itv->yuv_info.reg_2918 & 0x0000FFFF) == (itv->yuv_info.reg_2918 >> 16)) { 1209 if ((yi->reg_2918 & 0x0000FFFF) == (yi->reg_2918 >> 16)) {
1138 /* An exact size match uses filter 0/1 */ 1210 /* An exact size match uses filter 0/1 */
1139 v_filter_1 = 0; 1211 v_filter_1 = 0;
1140 v_filter_2 = 1; 1212 v_filter_2 = 1;
1141 } 1213 } else {
1142 else {
1143 /* Figure out which filter to use */ 1214 /* Figure out which filter to use */
1144 v_filter_1 = ((itv->yuv_info.reg_2918 << 16) / (itv->yuv_info.reg_2918 >> 16)) >> 15; 1215 v_filter_1 = ((yi->reg_2918 << 16) / (yi->reg_2918 >> 16)) >> 15;
1145 v_filter_1 = (v_filter_1 >> 1) + (v_filter_1 & 1); 1216 v_filter_1 = (v_filter_1 >> 1) + (v_filter_1 & 1);
1146 /* Only an exact size match can use filter 0 */ 1217 /* Only an exact size match can use filter 0 */
1147 if (v_filter_1 == 0) v_filter_1 = 1; 1218 v_filter_1 += !v_filter_1;
1148 v_filter_2 = v_filter_1; 1219 v_filter_2 = v_filter_1;
1149 } 1220 }
1150 1221
1151 /* Now restore the filters */ 1222 /* Now restore the filters */
1152 ivtv_yuv_filter (itv,h_filter,v_filter_1,v_filter_2); 1223 ivtv_yuv_filter(itv, h_filter, v_filter_1, v_filter_2);
1153 1224
1154 /* and clear a few registers */ 1225 /* and clear a few registers */
1155 write_reg(0, 0x02814); 1226 write_reg(0, 0x02814);
@@ -1158,19 +1229,18 @@ void ivtv_yuv_close(struct ivtv *itv)
1158 write_reg(0, 0x02910); 1229 write_reg(0, 0x02910);
1159 1230
1160 /* Release the blanking buffer */ 1231 /* Release the blanking buffer */
1161 if (itv->yuv_info.blanking_ptr) { 1232 if (yi->blanking_ptr) {
1162 kfree (itv->yuv_info.blanking_ptr); 1233 kfree(yi->blanking_ptr);
1163 itv->yuv_info.blanking_ptr = NULL; 1234 yi->blanking_ptr = NULL;
1164 pci_unmap_single(itv->dev, itv->yuv_info.blanking_dmaptr, 720*16, PCI_DMA_TODEVICE); 1235 pci_unmap_single(itv->dev, yi->blanking_dmaptr, 720*16, PCI_DMA_TODEVICE);
1165 } 1236 }
1166 1237
1167 /* Invalidate the old dimension information */ 1238 /* Invalidate the old dimension information */
1168 itv->yuv_info.old_frame_info.src_w = 0; 1239 yi->old_frame_info.src_w = 0;
1169 itv->yuv_info.old_frame_info.src_h = 0; 1240 yi->old_frame_info.src_h = 0;
1170 itv->yuv_info.old_frame_info_args.src_w = 0; 1241 yi->old_frame_info_args.src_w = 0;
1171 itv->yuv_info.old_frame_info_args.src_h = 0; 1242 yi->old_frame_info_args.src_h = 0;
1172 1243
1173 /* All done. */ 1244 /* All done. */
1174 clear_bit(IVTV_F_I_DECODING_YUV, &itv->i_flags); 1245 clear_bit(IVTV_F_I_DECODING_YUV, &itv->i_flags);
1175} 1246}
1176
diff --git a/drivers/media/video/ivtv/ivtv-yuv.h b/drivers/media/video/ivtv/ivtv-yuv.h
index 3b966f0a204a..2fe5f1250762 100644
--- a/drivers/media/video/ivtv/ivtv-yuv.h
+++ b/drivers/media/video/ivtv/ivtv-yuv.h
@@ -21,11 +21,6 @@
21#ifndef IVTV_YUV_H 21#ifndef IVTV_YUV_H
22#define IVTV_YUV_H 22#define IVTV_YUV_H
23 23
24/* Buffers on hardware offsets */
25#define IVTV_YUV_BUFFER_OFFSET 0x001a8600 /* First YUV Buffer */
26#define IVTV_YUV_BUFFER_OFFSET_1 0x00240400 /* Second YUV Buffer */
27#define IVTV_YUV_BUFFER_OFFSET_2 0x002d8200 /* Third YUV Buffer */
28#define IVTV_YUV_BUFFER_OFFSET_3 0x00370000 /* Fourth YUV Buffer */
29#define IVTV_YUV_BUFFER_UV_OFFSET 0x65400 /* Offset to UV Buffer */ 24#define IVTV_YUV_BUFFER_UV_OFFSET 0x65400 /* Offset to UV Buffer */
30 25
31/* Offset to filter table in firmware */ 26/* Offset to filter table in firmware */
@@ -36,11 +31,14 @@
36#define IVTV_YUV_UPDATE_VERTICAL 0x02 31#define IVTV_YUV_UPDATE_VERTICAL 0x02
37#define IVTV_YUV_UPDATE_INVALID 0x04 32#define IVTV_YUV_UPDATE_INVALID 0x04
38 33
39extern const u32 yuv_offset[4]; 34extern const u32 yuv_offset[IVTV_YUV_BUFFERS];
40 35
41int ivtv_yuv_filter_check(struct ivtv *itv); 36int ivtv_yuv_filter_check(struct ivtv *itv);
37void ivtv_yuv_setup_stream_frame(struct ivtv *itv);
38int ivtv_yuv_udma_stream_frame(struct ivtv *itv, void *src);
39void ivtv_yuv_frame_complete(struct ivtv *itv);
42int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args); 40int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args);
43void ivtv_yuv_close(struct ivtv *itv); 41void ivtv_yuv_close(struct ivtv *itv);
44void ivtv_yuv_work_handler (struct ivtv *itv); 42void ivtv_yuv_work_handler(struct ivtv *itv);
45 43
46#endif 44#endif
diff --git a/drivers/media/video/ivtv/ivtvfb.c b/drivers/media/video/ivtv/ivtvfb.c
index 52ffd154a3d8..3b23fc05f7c4 100644
--- a/drivers/media/video/ivtv/ivtvfb.c
+++ b/drivers/media/video/ivtv/ivtvfb.c
@@ -504,6 +504,10 @@ static int ivtvfb_set_var(struct ivtv *itv, struct fb_var_screeninfo *var)
504 504
505 ivtvfb_set_display_window(itv, &ivtv_window); 505 ivtvfb_set_display_window(itv, &ivtv_window);
506 506
507 /* Pass screen size back to yuv handler */
508 itv->yuv_info.osd_full_w = ivtv_osd.pixel_stride;
509 itv->yuv_info.osd_full_h = ivtv_osd.lines;
510
507 /* Force update of yuv registers */ 511 /* Force update of yuv registers */
508 itv->yuv_info.yuv_forced_update = 1; 512 itv->yuv_info.yuv_forced_update = 1;
509 513
@@ -1053,7 +1057,7 @@ static int ivtvfb_init_card(struct ivtv *itv)
1053 } 1057 }
1054 1058
1055 itv->osd_info = kzalloc(sizeof(struct osd_info), GFP_ATOMIC); 1059 itv->osd_info = kzalloc(sizeof(struct osd_info), GFP_ATOMIC);
1056 if (itv->osd_info == 0) { 1060 if (itv->osd_info == NULL) {
1057 IVTVFB_ERR("Failed to allocate memory for osd_info\n"); 1061 IVTVFB_ERR("Failed to allocate memory for osd_info\n");
1058 return -ENOMEM; 1062 return -ENOMEM;
1059 } 1063 }
diff --git a/drivers/media/video/m52790.c b/drivers/media/video/m52790.c
new file mode 100644
index 000000000000..d4bf14c284ef
--- /dev/null
+++ b/drivers/media/video/m52790.c
@@ -0,0 +1,168 @@
1/*
2 * m52790 i2c ivtv driver.
3 * Copyright (C) 2007 Hans Verkuil
4 *
5 * A/V source switching Mitsubishi M52790SP/FP
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22
23#include <linux/module.h>
24#include <linux/types.h>
25#include <linux/ioctl.h>
26#include <asm/uaccess.h>
27#include <linux/i2c.h>
28#include <linux/i2c-id.h>
29#include <linux/videodev.h>
30#include <media/m52790.h>
31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h>
33#include <media/v4l2-i2c-drv.h>
34
35MODULE_DESCRIPTION("i2c device driver for m52790 A/V switch");
36MODULE_AUTHOR("Hans Verkuil");
37MODULE_LICENSE("GPL");
38
39
40struct m52790_state {
41 u16 input;
42 u16 output;
43};
44
45/* ----------------------------------------------------------------------- */
46
47static int m52790_write(struct i2c_client *client)
48{
49 struct m52790_state *state = i2c_get_clientdata(client);
50 u8 sw1 = (state->input | state->output) & 0xff;
51 u8 sw2 = (state->input | state->output) >> 8;
52
53 return i2c_smbus_write_byte_data(client, sw1, sw2);
54}
55
56static int m52790_command(struct i2c_client *client, unsigned int cmd,
57 void *arg)
58{
59 struct m52790_state *state = i2c_get_clientdata(client);
60 struct v4l2_routing *route = arg;
61
62 /* Note: audio and video are linked and cannot be switched separately.
63 So audio and video routing commands are identical for this chip.
64 In theory the video amplifier and audio modes could be handled
65 separately for the output, but that seems to be overkill right now.
66 The same holds for implementing an audio mute control, this is now
67 part of the audio output routing. The normal case is that another
68 chip takes care of the actual muting so making it part of the
69 output routing seems to be the right thing to do for now. */
70 switch (cmd) {
71 case VIDIOC_INT_G_AUDIO_ROUTING:
72 case VIDIOC_INT_G_VIDEO_ROUTING:
73 route->input = state->input;
74 route->output = state->output;
75 break;
76
77 case VIDIOC_INT_S_AUDIO_ROUTING:
78 case VIDIOC_INT_S_VIDEO_ROUTING:
79 state->input = route->input;
80 state->output = route->output;
81 m52790_write(client);
82 break;
83
84#ifdef CONFIG_VIDEO_ADV_DEBUG
85 case VIDIOC_DBG_G_REGISTER:
86 case VIDIOC_DBG_S_REGISTER:
87 {
88 struct v4l2_register *reg = arg;
89
90 if (!v4l2_chip_match_i2c_client(client,
91 reg->match_type, reg->match_chip))
92 return -EINVAL;
93 if (!capable(CAP_SYS_ADMIN))
94 return -EPERM;
95 if (reg->reg != 0)
96 return -EINVAL;
97 if (cmd == VIDIOC_DBG_G_REGISTER)
98 reg->val = state->input | state->output;
99 else {
100 state->input = reg->val & 0x0303;
101 state->output = reg->val & ~0x0303;
102 m52790_write(client);
103 }
104 break;
105 }
106#endif
107
108 case VIDIOC_G_CHIP_IDENT:
109 return v4l2_chip_ident_i2c_client(client, arg,
110 V4L2_IDENT_M52790, 0);
111
112 case VIDIOC_LOG_STATUS:
113 v4l_info(client, "Switch 1: %02x\n",
114 (state->input | state->output) & 0xff);
115 v4l_info(client, "Switch 2: %02x\n",
116 (state->input | state->output) >> 8);
117 break;
118
119 default:
120 return -EINVAL;
121 }
122 return 0;
123}
124
125/* ----------------------------------------------------------------------- */
126
127/* i2c implementation */
128
129static int m52790_probe(struct i2c_client *client)
130{
131 struct m52790_state *state;
132
133 /* Check if the adapter supports the needed features */
134 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
135 return -EIO;
136
137 snprintf(client->name, sizeof(client->name) - 1, "m52790");
138
139 v4l_info(client, "chip found @ 0x%x (%s)\n",
140 client->addr << 1, client->adapter->name);
141
142 state = kmalloc(sizeof(struct m52790_state), GFP_KERNEL);
143 if (state == NULL)
144 return -ENOMEM;
145
146 state->input = M52790_IN_TUNER;
147 state->output = M52790_OUT_STEREO;
148 i2c_set_clientdata(client, state);
149 m52790_write(client);
150 return 0;
151}
152
153static int m52790_remove(struct i2c_client *client)
154{
155 kfree(i2c_get_clientdata(client));
156 return 0;
157}
158
159/* ----------------------------------------------------------------------- */
160
161static struct v4l2_i2c_driver_data v4l2_i2c_data = {
162 .name = "m52790",
163 .driverid = I2C_DRIVERID_M52790,
164 .command = m52790_command,
165 .probe = m52790_probe,
166 .remove = m52790_remove,
167};
168
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index c31163290432..3d51fa0a52b6 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -2023,7 +2023,7 @@ static int __init meye_init(void)
2023 if (gbufsize < 0 || gbufsize > MEYE_MAX_BUFSIZE) 2023 if (gbufsize < 0 || gbufsize > MEYE_MAX_BUFSIZE)
2024 gbufsize = MEYE_MAX_BUFSIZE; 2024 gbufsize = MEYE_MAX_BUFSIZE;
2025 gbufsize = PAGE_ALIGN(gbufsize); 2025 gbufsize = PAGE_ALIGN(gbufsize);
2026 printk(KERN_INFO "meye: using %d buffers with %dk (%dk total)" 2026 printk(KERN_INFO "meye: using %d buffers with %dk (%dk total) "
2027 "for capture\n", 2027 "for capture\n",
2028 gbuffers, 2028 gbuffers,
2029 gbufsize / 1024, gbuffers * gbufsize / 1024); 2029 gbufsize / 1024, gbuffers * gbufsize / 1024);
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index c0c87e06259b..7a11f3159e32 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -42,7 +42,8 @@
42 * 42 *
43 * You should have received a copy of the GNU General Public License 43 * You should have received a copy of the GNU General Public License
44 * along with this program; if not, write to the Free Software 44 * along with this program; if not, write to the Free Software
45 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 45 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
46 * 02110-1301, USA.
46 */ 47 */
47 48
48 49
@@ -53,6 +54,7 @@
53#include <linux/videodev.h> 54#include <linux/videodev.h>
54#include <linux/videodev2.h> 55#include <linux/videodev2.h>
55#include <media/v4l2-common.h> 56#include <media/v4l2-common.h>
57#include <media/v4l2-i2c-drv-legacy.h>
56#include <media/tvaudio.h> 58#include <media/tvaudio.h>
57#include <media/msp3400.h> 59#include <media/msp3400.h>
58#include <linux/kthread.h> 60#include <linux/kthread.h>
@@ -71,7 +73,8 @@ int msp_debug; /* msp_debug output */
71int msp_once; /* no continous stereo monitoring */ 73int msp_once; /* no continous stereo monitoring */
72int msp_amsound; /* hard-wire AM sound at 6.5 Hz (france), 74int msp_amsound; /* hard-wire AM sound at 6.5 Hz (france),
73 the autoscan seems work well only with FM... */ 75 the autoscan seems work well only with FM... */
74int msp_standard = 1; /* Override auto detect of audio msp_standard, if needed. */ 76int msp_standard = 1; /* Override auto detect of audio msp_standard,
77 if needed. */
75int msp_dolby; 78int msp_dolby;
76 79
77int msp_stereo_thresh = 0x190; /* a2 threshold for stereo/bilingual 80int msp_stereo_thresh = 0x190; /* a2 threshold for stereo/bilingual
@@ -81,12 +84,12 @@ int msp_stereo_thresh = 0x190; /* a2 threshold for stereo/bilingual
81module_param(opmode, int, 0444); 84module_param(opmode, int, 0444);
82 85
83/* read-write */ 86/* read-write */
84module_param_named(once,msp_once, bool, 0644); 87module_param_named(once, msp_once, bool, 0644);
85module_param_named(debug,msp_debug, int, 0644); 88module_param_named(debug, msp_debug, int, 0644);
86module_param_named(stereo_threshold,msp_stereo_thresh, int, 0644); 89module_param_named(stereo_threshold, msp_stereo_thresh, int, 0644);
87module_param_named(standard,msp_standard, int, 0644); 90module_param_named(standard, msp_standard, int, 0644);
88module_param_named(amsound,msp_amsound, bool, 0644); 91module_param_named(amsound, msp_amsound, bool, 0644);
89module_param_named(dolby,msp_dolby, bool, 0644); 92module_param_named(dolby, msp_dolby, bool, 0644);
90 93
91MODULE_PARM_DESC(opmode, "Forces a MSP3400 opmode. 0=Manual, 1=Autodetect, 2=Autodetect and autoselect"); 94MODULE_PARM_DESC(opmode, "Forces a MSP3400 opmode. 0=Manual, 1=Autodetect, 2=Autodetect and autoselect");
92MODULE_PARM_DESC(once, "No continuous stereo monitoring"); 95MODULE_PARM_DESC(once, "No continuous stereo monitoring");
@@ -160,12 +163,13 @@ static int msp_read(struct i2c_client *client, int dev, int addr)
160 schedule_timeout_interruptible(msecs_to_jiffies(10)); 163 schedule_timeout_interruptible(msecs_to_jiffies(10));
161 } 164 }
162 if (err == 3) { 165 if (err == 3) {
163 v4l_warn(client, "giving up, resetting chip. Sound will go off, sorry folks :-|\n"); 166 v4l_warn(client, "resetting chip, sound will go off.\n");
164 msp_reset(client); 167 msp_reset(client);
165 return -1; 168 return -1;
166 } 169 }
167 retval = read[0] << 8 | read[1]; 170 retval = read[0] << 8 | read[1];
168 v4l_dbg(3, msp_debug, client, "msp_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval); 171 v4l_dbg(3, msp_debug, client, "msp_read(0x%x, 0x%x): 0x%x\n",
172 dev, addr, retval);
169 return retval; 173 return retval;
170} 174}
171 175
@@ -190,7 +194,8 @@ static int msp_write(struct i2c_client *client, int dev, int addr, int val)
190 buffer[3] = val >> 8; 194 buffer[3] = val >> 8;
191 buffer[4] = val & 0xff; 195 buffer[4] = val & 0xff;
192 196
193 v4l_dbg(3, msp_debug, client, "msp_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val); 197 v4l_dbg(3, msp_debug, client, "msp_write(0x%x, 0x%x, 0x%x)\n",
198 dev, addr, val);
194 for (err = 0; err < 3; err++) { 199 for (err = 0; err < 3; err++) {
195 if (i2c_master_send(client, buffer, 5) == 5) 200 if (i2c_master_send(client, buffer, 5) == 5)
196 break; 201 break;
@@ -199,7 +204,7 @@ static int msp_write(struct i2c_client *client, int dev, int addr, int val)
199 schedule_timeout_interruptible(msecs_to_jiffies(10)); 204 schedule_timeout_interruptible(msecs_to_jiffies(10));
200 } 205 }
201 if (err == 3) { 206 if (err == 3) {
202 v4l_warn(client, "giving up, resetting chip. Sound will go off, sorry folks :-|\n"); 207 v4l_warn(client, "resetting chip, sound will go off.\n");
203 msp_reset(client); 208 msp_reset(client);
204 return -1; 209 return -1;
205 } 210 }
@@ -273,7 +278,7 @@ void msp_set_scart(struct i2c_client *client, int in, int out)
273 state->acb = 0xf60; /* Mute Input and SCART 1 Output */ 278 state->acb = 0xf60; /* Mute Input and SCART 1 Output */
274 279
275 v4l_dbg(1, msp_debug, client, "scart switch: %s => %d (ACB=0x%04x)\n", 280 v4l_dbg(1, msp_debug, client, "scart switch: %s => %d (ACB=0x%04x)\n",
276 scart_names[in], out, state->acb); 281 scart_names[in], out, state->acb);
277 msp_write_dsp(client, 0x13, state->acb); 282 msp_write_dsp(client, 0x13, state->acb);
278 283
279 /* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */ 284 /* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */
@@ -292,7 +297,8 @@ void msp_set_audio(struct i2c_client *client)
292 val = (state->volume * 0x7f / 65535) << 8; 297 val = (state->volume * 0x7f / 65535) << 8;
293 298
294 v4l_dbg(1, msp_debug, client, "mute=%s scanning=%s volume=%d\n", 299 v4l_dbg(1, msp_debug, client, "mute=%s scanning=%s volume=%d\n",
295 state->muted ? "on" : "off", state->scan_in_progress ? "yes" : "no", 300 state->muted ? "on" : "off",
301 state->scan_in_progress ? "yes" : "no",
296 state->volume); 302 state->volume);
297 303
298 msp_write_dsp(client, 0x0000, val); 304 msp_write_dsp(client, 0x0000, val);
@@ -681,14 +687,14 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
681 v4l_dbg(1, msp_debug, client, "Setting I2S speed to %d\n", *a); 687 v4l_dbg(1, msp_debug, client, "Setting I2S speed to %d\n", *a);
682 688
683 switch (*a) { 689 switch (*a) {
684 case 1024000: 690 case 1024000:
685 state->i2s_mode = 0; 691 state->i2s_mode = 0;
686 break; 692 break;
687 case 2048000: 693 case 2048000:
688 state->i2s_mode = 1; 694 state->i2s_mode = 1;
689 break; 695 break;
690 default: 696 default:
691 return -EINVAL; 697 return -EINVAL;
692 } 698 }
693 break; 699 break;
694 } 700 }
@@ -698,22 +704,22 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
698 struct v4l2_queryctrl *qc = arg; 704 struct v4l2_queryctrl *qc = arg;
699 705
700 switch (qc->id) { 706 switch (qc->id) {
701 case V4L2_CID_AUDIO_VOLUME: 707 case V4L2_CID_AUDIO_VOLUME:
702 case V4L2_CID_AUDIO_MUTE: 708 case V4L2_CID_AUDIO_MUTE:
703 return v4l2_ctrl_query_fill_std(qc); 709 return v4l2_ctrl_query_fill_std(qc);
704 default: 710 default:
705 break; 711 break;
706 } 712 }
707 if (!state->has_sound_processing) 713 if (!state->has_sound_processing)
708 return -EINVAL; 714 return -EINVAL;
709 switch (qc->id) { 715 switch (qc->id) {
710 case V4L2_CID_AUDIO_LOUDNESS: 716 case V4L2_CID_AUDIO_LOUDNESS:
711 case V4L2_CID_AUDIO_BALANCE: 717 case V4L2_CID_AUDIO_BALANCE:
712 case V4L2_CID_AUDIO_BASS: 718 case V4L2_CID_AUDIO_BASS:
713 case V4L2_CID_AUDIO_TREBLE: 719 case V4L2_CID_AUDIO_TREBLE:
714 return v4l2_ctrl_query_fill_std(qc); 720 return v4l2_ctrl_query_fill_std(qc);
715 default: 721 default:
716 return -EINVAL; 722 return -EINVAL;
717 } 723 }
718 } 724 }
719 725
@@ -735,13 +741,14 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
735 state->volume, state->muted ? " (muted)" : ""); 741 state->volume, state->muted ? " (muted)" : "");
736 if (state->has_sound_processing) { 742 if (state->has_sound_processing) {
737 v4l_info(client, "Audio: balance %d bass %d treble %d loudness %s\n", 743 v4l_info(client, "Audio: balance %d bass %d treble %d loudness %s\n",
738 state->balance, state->bass, state->treble, 744 state->balance, state->bass,
745 state->treble,
739 state->loudness ? "on" : "off"); 746 state->loudness ? "on" : "off");
740 } 747 }
741 switch (state->mode) { 748 switch (state->mode) {
742 case MSP_MODE_AM_DETECT: p = "AM (for carrier detect)"; break; 749 case MSP_MODE_AM_DETECT: p = "AM (for carrier detect)"; break;
743 case MSP_MODE_FM_RADIO: p = "FM Radio"; break; 750 case MSP_MODE_FM_RADIO: p = "FM Radio"; break;
744 case MSP_MODE_FM_TERRA: p = "Terrestial FM-mono + FM-stereo"; break; 751 case MSP_MODE_FM_TERRA: p = "Terrestial FM-mono/stereo"; break;
745 case MSP_MODE_FM_SAT: p = "Satellite FM-mono"; break; 752 case MSP_MODE_FM_SAT: p = "Satellite FM-mono"; break;
746 case MSP_MODE_FM_NICAM1: p = "NICAM/FM (B/G, D/K)"; break; 753 case MSP_MODE_FM_NICAM1: p = "NICAM/FM (B/G, D/K)"; break;
747 case MSP_MODE_FM_NICAM2: p = "NICAM/FM (I)"; break; 754 case MSP_MODE_FM_NICAM2: p = "NICAM/FM (I)"; break;
@@ -772,7 +779,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
772 } 779 }
773 780
774 case VIDIOC_G_CHIP_IDENT: 781 case VIDIOC_G_CHIP_IDENT:
775 return v4l2_chip_ident_i2c_client(client, arg, state->ident, (state->rev1 << 16) | state->rev2); 782 return v4l2_chip_ident_i2c_client(client, arg, state->ident,
783 (state->rev1 << 16) | state->rev2);
776 784
777 default: 785 default:
778 /* unknown */ 786 /* unknown */
@@ -783,7 +791,6 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
783 791
784static int msp_suspend(struct i2c_client *client, pm_message_t state) 792static int msp_suspend(struct i2c_client *client, pm_message_t state)
785{ 793{
786
787 v4l_dbg(1, msp_debug, client, "suspend\n"); 794 v4l_dbg(1, msp_debug, client, "suspend\n");
788 msp_reset(client); 795 msp_reset(client);
789 return 0; 796 return 0;
@@ -791,7 +798,6 @@ static int msp_suspend(struct i2c_client *client, pm_message_t state)
791 798
792static int msp_resume(struct i2c_client *client) 799static int msp_resume(struct i2c_client *client)
793{ 800{
794
795 v4l_dbg(1, msp_debug, client, "resume\n"); 801 v4l_dbg(1, msp_debug, client, "resume\n");
796 msp_wake_thread(client); 802 msp_wake_thread(client);
797 return 0; 803 return 0;
@@ -799,11 +805,8 @@ static int msp_resume(struct i2c_client *client)
799 805
800/* ----------------------------------------------------------------------- */ 806/* ----------------------------------------------------------------------- */
801 807
802static struct i2c_driver i2c_driver; 808static int msp_probe(struct i2c_client *client)
803
804static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
805{ 809{
806 struct i2c_client *client;
807 struct msp_state *state; 810 struct msp_state *state;
808 int (*thread_func)(void *data) = NULL; 811 int (*thread_func)(void *data) = NULL;
809 int msp_hard; 812 int msp_hard;
@@ -812,26 +815,16 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
812 int msp_product, msp_prod_hi, msp_prod_lo; 815 int msp_product, msp_prod_hi, msp_prod_lo;
813 int msp_rom; 816 int msp_rom;
814 817
815 client = kzalloc(sizeof(*client), GFP_KERNEL);
816 if (!client)
817 return -ENOMEM;
818
819 client->addr = address;
820 client->adapter = adapter;
821 client->driver = &i2c_driver;
822 snprintf(client->name, sizeof(client->name) - 1, "msp3400"); 818 snprintf(client->name, sizeof(client->name) - 1, "msp3400");
823 819
824 if (msp_reset(client) == -1) { 820 if (msp_reset(client) == -1) {
825 v4l_dbg(1, msp_debug, client, "msp3400 not found\n"); 821 v4l_dbg(1, msp_debug, client, "msp3400 not found\n");
826 kfree(client); 822 return -ENODEV;
827 return 0;
828 } 823 }
829 824
830 state = kzalloc(sizeof(*state), GFP_KERNEL); 825 state = kzalloc(sizeof(*state), GFP_KERNEL);
831 if (!state) { 826 if (!state)
832 kfree(client);
833 return -ENOMEM; 827 return -ENOMEM;
834 }
835 828
836 i2c_set_clientdata(client, state); 829 i2c_set_clientdata(client, state);
837 830
@@ -853,12 +846,13 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
853 state->rev1 = msp_read_dsp(client, 0x1e); 846 state->rev1 = msp_read_dsp(client, 0x1e);
854 if (state->rev1 != -1) 847 if (state->rev1 != -1)
855 state->rev2 = msp_read_dsp(client, 0x1f); 848 state->rev2 = msp_read_dsp(client, 0x1f);
856 v4l_dbg(1, msp_debug, client, "rev1=0x%04x, rev2=0x%04x\n", state->rev1, state->rev2); 849 v4l_dbg(1, msp_debug, client, "rev1=0x%04x, rev2=0x%04x\n",
850 state->rev1, state->rev2);
857 if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) { 851 if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) {
858 v4l_dbg(1, msp_debug, client, "not an msp3400 (cannot read chip version)\n"); 852 v4l_dbg(1, msp_debug, client,
853 "not an msp3400 (cannot read chip version)\n");
859 kfree(state); 854 kfree(state);
860 kfree(client); 855 return -ENODEV;
861 return 0;
862 } 856 }
863 857
864 msp_set_audio(client); 858 msp_set_audio(client);
@@ -874,37 +868,55 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
874 msp_family, msp_product, 868 msp_family, msp_product,
875 msp_revision, msp_hard, msp_rom); 869 msp_revision, msp_hard, msp_rom);
876 /* Rev B=2, C=3, D=4, G=7 */ 870 /* Rev B=2, C=3, D=4, G=7 */
877 state->ident = msp_family * 10000 + 4000 + msp_product * 10 + msp_revision - '@'; 871 state->ident = msp_family * 10000 + 4000 + msp_product * 10 +
872 msp_revision - '@';
878 873
879 /* Has NICAM support: all mspx41x and mspx45x products have NICAM */ 874 /* Has NICAM support: all mspx41x and mspx45x products have NICAM */
880 state->has_nicam = msp_prod_hi == 1 || msp_prod_hi == 5; 875 state->has_nicam =
876 msp_prod_hi == 1 || msp_prod_hi == 5;
881 /* Has radio support: was added with revision G */ 877 /* Has radio support: was added with revision G */
882 state->has_radio = msp_revision >= 'G'; 878 state->has_radio =
879 msp_revision >= 'G';
883 /* Has headphones output: not for stripped down products */ 880 /* Has headphones output: not for stripped down products */
884 state->has_headphones = msp_prod_lo < 5; 881 state->has_headphones =
882 msp_prod_lo < 5;
885 /* Has scart2 input: not in stripped down products of the '3' family */ 883 /* Has scart2 input: not in stripped down products of the '3' family */
886 state->has_scart2 = msp_family >= 4 || msp_prod_lo < 7; 884 state->has_scart2 =
885 msp_family >= 4 || msp_prod_lo < 7;
887 /* Has scart3 input: not in stripped down products of the '3' family */ 886 /* Has scart3 input: not in stripped down products of the '3' family */
888 state->has_scart3 = msp_family >= 4 || msp_prod_lo < 5; 887 state->has_scart3 =
888 msp_family >= 4 || msp_prod_lo < 5;
889 /* Has scart4 input: not in pre D revisions, not in stripped D revs */ 889 /* Has scart4 input: not in pre D revisions, not in stripped D revs */
890 state->has_scart4 = msp_family >= 4 || (msp_revision >= 'D' && msp_prod_lo < 5); 890 state->has_scart4 =
891 /* Has scart2 output: not in stripped down products of the '3' family */ 891 msp_family >= 4 || (msp_revision >= 'D' && msp_prod_lo < 5);
892 state->has_scart2_out = msp_family >= 4 || msp_prod_lo < 5; 892 /* Has scart2 output: not in stripped down products of
893 * the '3' family */
894 state->has_scart2_out =
895 msp_family >= 4 || msp_prod_lo < 5;
893 /* Has scart2 a volume control? Not in pre-D revisions. */ 896 /* Has scart2 a volume control? Not in pre-D revisions. */
894 state->has_scart2_out_volume = msp_revision > 'C' && state->has_scart2_out; 897 state->has_scart2_out_volume =
898 msp_revision > 'C' && state->has_scart2_out;
895 /* Has a configurable i2s out? */ 899 /* Has a configurable i2s out? */
896 state->has_i2s_conf = msp_revision >= 'G' && msp_prod_lo < 7; 900 state->has_i2s_conf =
897 /* Has subwoofer output: not in pre-D revs and not in stripped down products */ 901 msp_revision >= 'G' && msp_prod_lo < 7;
898 state->has_subwoofer = msp_revision >= 'D' && msp_prod_lo < 5; 902 /* Has subwoofer output: not in pre-D revs and not in stripped down
899 /* Has soundprocessing (bass/treble/balance/loudness/equalizer): not in 903 * products */
900 stripped down products */ 904 state->has_subwoofer =
901 state->has_sound_processing = msp_prod_lo < 7; 905 msp_revision >= 'D' && msp_prod_lo < 5;
906 /* Has soundprocessing (bass/treble/balance/loudness/equalizer):
907 * not in stripped down products */
908 state->has_sound_processing =
909 msp_prod_lo < 7;
902 /* Has Virtual Dolby Surround: only in msp34x1 */ 910 /* Has Virtual Dolby Surround: only in msp34x1 */
903 state->has_virtual_dolby_surround = msp_revision == 'G' && msp_prod_lo == 1; 911 state->has_virtual_dolby_surround =
912 msp_revision == 'G' && msp_prod_lo == 1;
904 /* Has Virtual Dolby Surround & Dolby Pro Logic: only in msp34x2 */ 913 /* Has Virtual Dolby Surround & Dolby Pro Logic: only in msp34x2 */
905 state->has_dolby_pro_logic = msp_revision == 'G' && msp_prod_lo == 2; 914 state->has_dolby_pro_logic =
906 /* The msp343xG supports BTSC only and cannot do Automatic Standard Detection. */ 915 msp_revision == 'G' && msp_prod_lo == 2;
907 state->force_btsc = msp_family == 3 && msp_revision == 'G' && msp_prod_hi == 3; 916 /* The msp343xG supports BTSC only and cannot do Automatic Standard
917 * Detection. */
918 state->force_btsc =
919 msp_family == 3 && msp_revision == 'G' && msp_prod_hi == 3;
908 920
909 state->opmode = opmode; 921 state->opmode = opmode;
910 if (state->opmode == OPMODE_AUTO) { 922 if (state->opmode == OPMODE_AUTO) {
@@ -919,32 +931,33 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
919 } 931 }
920 932
921 /* hello world :-) */ 933 /* hello world :-) */
922 v4l_info(client, "%s found @ 0x%x (%s)\n", client->name, address << 1, adapter->name); 934 v4l_info(client, "%s found @ 0x%x (%s)\n", client->name,
935 client->addr << 1, client->adapter->name);
923 v4l_info(client, "%s ", client->name); 936 v4l_info(client, "%s ", client->name);
924 if (state->has_nicam && state->has_radio) 937 if (state->has_nicam && state->has_radio)
925 printk("supports nicam and radio, "); 938 printk(KERN_CONT "supports nicam and radio, ");
926 else if (state->has_nicam) 939 else if (state->has_nicam)
927 printk("supports nicam, "); 940 printk(KERN_CONT "supports nicam, ");
928 else if (state->has_radio) 941 else if (state->has_radio)
929 printk("supports radio, "); 942 printk(KERN_CONT "supports radio, ");
930 printk("mode is "); 943 printk(KERN_CONT "mode is ");
931 944
932 /* version-specific initialization */ 945 /* version-specific initialization */
933 switch (state->opmode) { 946 switch (state->opmode) {
934 case OPMODE_MANUAL: 947 case OPMODE_MANUAL:
935 printk("manual"); 948 printk(KERN_CONT "manual");
936 thread_func = msp3400c_thread; 949 thread_func = msp3400c_thread;
937 break; 950 break;
938 case OPMODE_AUTODETECT: 951 case OPMODE_AUTODETECT:
939 printk("autodetect"); 952 printk(KERN_CONT "autodetect");
940 thread_func = msp3410d_thread; 953 thread_func = msp3410d_thread;
941 break; 954 break;
942 case OPMODE_AUTOSELECT: 955 case OPMODE_AUTOSELECT:
943 printk("autodetect and autoselect"); 956 printk(KERN_CONT "autodetect and autoselect");
944 thread_func = msp34xxg_thread; 957 thread_func = msp34xxg_thread;
945 break; 958 break;
946 } 959 }
947 printk("\n"); 960 printk(KERN_CONT "\n");
948 961
949 /* startup control thread if needed */ 962 /* startup control thread if needed */
950 if (thread_func) { 963 if (thread_func) {
@@ -954,24 +967,12 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
954 v4l_warn(client, "kernel_thread() failed\n"); 967 v4l_warn(client, "kernel_thread() failed\n");
955 msp_wake_thread(client); 968 msp_wake_thread(client);
956 } 969 }
957
958 /* done */
959 i2c_attach_client(client);
960
961 return 0; 970 return 0;
962} 971}
963 972
964static int msp_probe(struct i2c_adapter *adapter) 973static int msp_remove(struct i2c_client *client)
965{
966 if (adapter->class & I2C_CLASS_TV_ANALOG)
967 return i2c_probe(adapter, &addr_data, msp_attach);
968 return 0;
969}
970
971static int msp_detach(struct i2c_client *client)
972{ 974{
973 struct msp_state *state = i2c_get_clientdata(client); 975 struct msp_state *state = i2c_get_clientdata(client);
974 int err;
975 976
976 /* shutdown control thread */ 977 /* shutdown control thread */
977 if (state->kthread) { 978 if (state->kthread) {
@@ -980,43 +981,22 @@ static int msp_detach(struct i2c_client *client)
980 } 981 }
981 msp_reset(client); 982 msp_reset(client);
982 983
983 err = i2c_detach_client(client);
984 if (err) {
985 return err;
986 }
987
988 kfree(state); 984 kfree(state);
989 kfree(client);
990 return 0; 985 return 0;
991} 986}
992 987
993/* ----------------------------------------------------------------------- */ 988/* ----------------------------------------------------------------------- */
994 989
995/* i2c implementation */ 990static struct v4l2_i2c_driver_data v4l2_i2c_data = {
996static struct i2c_driver i2c_driver = { 991 .name = "msp3400",
997 .id = I2C_DRIVERID_MSP3400, 992 .driverid = I2C_DRIVERID_MSP3400,
998 .attach_adapter = msp_probe, 993 .command = msp_command,
999 .detach_client = msp_detach, 994 .probe = msp_probe,
995 .remove = msp_remove,
1000 .suspend = msp_suspend, 996 .suspend = msp_suspend,
1001 .resume = msp_resume, 997 .resume = msp_resume,
1002 .command = msp_command,
1003 .driver = {
1004 .name = "msp3400",
1005 },
1006}; 998};
1007 999
1008static int __init msp3400_init_module(void)
1009{
1010 return i2c_add_driver(&i2c_driver);
1011}
1012
1013static void __exit msp3400_cleanup_module(void)
1014{
1015 i2c_del_driver(&i2c_driver);
1016}
1017
1018module_init(msp3400_init_module);
1019module_exit(msp3400_cleanup_module);
1020 1000
1021/* 1001/*
1022 * Overrides for Emacs so that we follow Linus's tabbing style. 1002 * Overrides for Emacs so that we follow Linus's tabbing style.
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index d5ee2629121e..61ec794a737e 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -15,7 +15,8 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 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 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301, USA.
19 */ 20 */
20 21
21 22
@@ -78,37 +79,37 @@ static struct msp3400c_init_data_dem {
78 {75, 19, 36, 35, 39, 40}, 79 {75, 19, 36, 35, 39, 40},
79 MSP_CARRIER(5.5), MSP_CARRIER(5.5), 80 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
80 0x00d0, 0x0500, 0x0020, 0x3000 81 0x00d0, 0x0500, 0x0020, 0x3000
81 },{ /* AM (for carrier detect / msp3410) */ 82 }, { /* AM (for carrier detect / msp3410) */
82 {-1, -1, -8, 2, 59, 126}, 83 {-1, -1, -8, 2, 59, 126},
83 {-1, -1, -8, 2, 59, 126}, 84 {-1, -1, -8, 2, 59, 126},
84 MSP_CARRIER(5.5), MSP_CARRIER(5.5), 85 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
85 0x00d0, 0x0100, 0x0020, 0x3000 86 0x00d0, 0x0100, 0x0020, 0x3000
86 },{ /* FM Radio */ 87 }, { /* FM Radio */
87 {-8, -8, 4, 6, 78, 107}, 88 {-8, -8, 4, 6, 78, 107},
88 {-8, -8, 4, 6, 78, 107}, 89 {-8, -8, 4, 6, 78, 107},
89 MSP_CARRIER(10.7), MSP_CARRIER(10.7), 90 MSP_CARRIER(10.7), MSP_CARRIER(10.7),
90 0x00d0, 0x0480, 0x0020, 0x3000 91 0x00d0, 0x0480, 0x0020, 0x3000
91 },{ /* Terrestial FM-mono + FM-stereo */ 92 }, { /* Terrestial FM-mono + FM-stereo */
92 {3, 18, 27, 48, 66, 72}, 93 {3, 18, 27, 48, 66, 72},
93 {3, 18, 27, 48, 66, 72}, 94 {3, 18, 27, 48, 66, 72},
94 MSP_CARRIER(5.5), MSP_CARRIER(5.5), 95 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
95 0x00d0, 0x0480, 0x0030, 0x3000 96 0x00d0, 0x0480, 0x0030, 0x3000
96 },{ /* Sat FM-mono */ 97 }, { /* Sat FM-mono */
97 { 1, 9, 14, 24, 33, 37}, 98 { 1, 9, 14, 24, 33, 37},
98 { 3, 18, 27, 48, 66, 72}, 99 { 3, 18, 27, 48, 66, 72},
99 MSP_CARRIER(6.5), MSP_CARRIER(6.5), 100 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
100 0x00c6, 0x0480, 0x0000, 0x3000 101 0x00c6, 0x0480, 0x0000, 0x3000
101 },{ /* NICAM/FM -- B/G (5.5/5.85), D/K (6.5/5.85) */ 102 }, { /* NICAM/FM -- B/G (5.5/5.85), D/K (6.5/5.85) */
102 {-2, -8, -10, 10, 50, 86}, 103 {-2, -8, -10, 10, 50, 86},
103 {3, 18, 27, 48, 66, 72}, 104 {3, 18, 27, 48, 66, 72},
104 MSP_CARRIER(5.5), MSP_CARRIER(5.5), 105 MSP_CARRIER(5.5), MSP_CARRIER(5.5),
105 0x00d0, 0x0040, 0x0120, 0x3000 106 0x00d0, 0x0040, 0x0120, 0x3000
106 },{ /* NICAM/FM -- I (6.0/6.552) */ 107 }, { /* NICAM/FM -- I (6.0/6.552) */
107 {2, 4, -6, -4, 40, 94}, 108 {2, 4, -6, -4, 40, 94},
108 {3, 18, 27, 48, 66, 72}, 109 {3, 18, 27, 48, 66, 72},
109 MSP_CARRIER(6.0), MSP_CARRIER(6.0), 110 MSP_CARRIER(6.0), MSP_CARRIER(6.0),
110 0x00d0, 0x0040, 0x0120, 0x3000 111 0x00d0, 0x0040, 0x0120, 0x3000
111 },{ /* NICAM/AM -- L (6.5/5.85) */ 112 }, { /* NICAM/AM -- L (6.5/5.85) */
112 {-2, -8, -10, 10, 50, 86}, 113 {-2, -8, -10, 10, 50, 86},
113 {-4, -12, -9, 23, 79, 126}, 114 {-4, -12, -9, 23, 79, 126},
114 MSP_CARRIER(6.5), MSP_CARRIER(6.5), 115 MSP_CARRIER(6.5), MSP_CARRIER(6.5),
@@ -224,7 +225,9 @@ void msp3400c_set_mode(struct i2c_client *client, int mode)
224 nor do they support stereo BTSC. */ 225 nor do they support stereo BTSC. */
225static void msp3400c_set_audmode(struct i2c_client *client) 226static void msp3400c_set_audmode(struct i2c_client *client)
226{ 227{
227 static char *strmode[] = { "mono", "stereo", "lang2", "lang1", "lang1+lang2" }; 228 static char *strmode[] = {
229 "mono", "stereo", "lang2", "lang1", "lang1+lang2"
230 };
228 struct msp_state *state = i2c_get_clientdata(client); 231 struct msp_state *state = i2c_get_clientdata(client);
229 char *modestr = (state->audmode >= 0 && state->audmode < 5) ? 232 char *modestr = (state->audmode >= 0 && state->audmode < 5) ?
230 strmode[state->audmode] : "unknown"; 233 strmode[state->audmode] : "unknown";
@@ -298,19 +301,23 @@ static void msp3400c_set_audmode(struct i2c_client *client)
298 case MSP_MODE_FM_NICAM1: 301 case MSP_MODE_FM_NICAM1:
299 case MSP_MODE_FM_NICAM2: 302 case MSP_MODE_FM_NICAM2:
300 case MSP_MODE_AM_NICAM: 303 case MSP_MODE_AM_NICAM:
301 v4l_dbg(1, msp_debug, client, "NICAM set_audmode: %s\n",modestr); 304 v4l_dbg(1, msp_debug, client,
305 "NICAM set_audmode: %s\n", modestr);
302 if (state->nicam_on) 306 if (state->nicam_on)
303 src = 0x0100; /* NICAM */ 307 src = 0x0100; /* NICAM */
304 break; 308 break;
305 case MSP_MODE_BTSC: 309 case MSP_MODE_BTSC:
306 v4l_dbg(1, msp_debug, client, "BTSC set_audmode: %s\n",modestr); 310 v4l_dbg(1, msp_debug, client,
311 "BTSC set_audmode: %s\n", modestr);
307 break; 312 break;
308 case MSP_MODE_EXTERN: 313 case MSP_MODE_EXTERN:
309 v4l_dbg(1, msp_debug, client, "extern set_audmode: %s\n",modestr); 314 v4l_dbg(1, msp_debug, client,
315 "extern set_audmode: %s\n", modestr);
310 src = 0x0200; /* SCART */ 316 src = 0x0200; /* SCART */
311 break; 317 break;
312 case MSP_MODE_FM_RADIO: 318 case MSP_MODE_FM_RADIO:
313 v4l_dbg(1, msp_debug, client, "FM-Radio set_audmode: %s\n",modestr); 319 v4l_dbg(1, msp_debug, client,
320 "FM-Radio set_audmode: %s\n", modestr);
314 break; 321 break;
315 default: 322 default:
316 v4l_dbg(1, msp_debug, client, "mono set_audmode\n"); 323 v4l_dbg(1, msp_debug, client, "mono set_audmode\n");
@@ -342,7 +349,8 @@ static void msp3400c_set_audmode(struct i2c_client *client)
342 src |= 0x0010; 349 src |= 0x0010;
343 break; 350 break;
344 } 351 }
345 v4l_dbg(1, msp_debug, client, "set_audmode final source/matrix = 0x%x\n", src); 352 v4l_dbg(1, msp_debug, client,
353 "set_audmode final source/matrix = 0x%x\n", src);
346 354
347 msp_set_source(client, src); 355 msp_set_source(client, src);
348} 356}
@@ -351,22 +359,26 @@ static void msp3400c_print_mode(struct i2c_client *client)
351{ 359{
352 struct msp_state *state = i2c_get_clientdata(client); 360 struct msp_state *state = i2c_get_clientdata(client);
353 361
354 if (state->main == state->second) { 362 if (state->main == state->second)
355 v4l_dbg(1, msp_debug, client, "mono sound carrier: %d.%03d MHz\n", 363 v4l_dbg(1, msp_debug, client,
356 state->main / 910000, (state->main / 910) % 1000); 364 "mono sound carrier: %d.%03d MHz\n",
357 } else { 365 state->main / 910000, (state->main / 910) % 1000);
358 v4l_dbg(1, msp_debug, client, "main sound carrier: %d.%03d MHz\n", 366 else
359 state->main / 910000, (state->main / 910) % 1000); 367 v4l_dbg(1, msp_debug, client,
360 } 368 "main sound carrier: %d.%03d MHz\n",
369 state->main / 910000, (state->main / 910) % 1000);
361 if (state->mode == MSP_MODE_FM_NICAM1 || state->mode == MSP_MODE_FM_NICAM2) 370 if (state->mode == MSP_MODE_FM_NICAM1 || state->mode == MSP_MODE_FM_NICAM2)
362 v4l_dbg(1, msp_debug, client, "NICAM/FM carrier : %d.%03d MHz\n", 371 v4l_dbg(1, msp_debug, client,
363 state->second / 910000, (state->second/910) % 1000); 372 "NICAM/FM carrier : %d.%03d MHz\n",
373 state->second / 910000, (state->second/910) % 1000);
364 if (state->mode == MSP_MODE_AM_NICAM) 374 if (state->mode == MSP_MODE_AM_NICAM)
365 v4l_dbg(1, msp_debug, client, "NICAM/AM carrier : %d.%03d MHz\n", 375 v4l_dbg(1, msp_debug, client,
366 state->second / 910000, (state->second / 910) % 1000); 376 "NICAM/AM carrier : %d.%03d MHz\n",
377 state->second / 910000, (state->second / 910) % 1000);
367 if (state->mode == MSP_MODE_FM_TERRA && state->main != state->second) { 378 if (state->mode == MSP_MODE_FM_TERRA && state->main != state->second) {
368 v4l_dbg(1, msp_debug, client, "FM-stereo carrier : %d.%03d MHz\n", 379 v4l_dbg(1, msp_debug, client,
369 state->second / 910000, (state->second / 910) % 1000); 380 "FM-stereo carrier : %d.%03d MHz\n",
381 state->second / 910000, (state->second / 910) % 1000);
370 } 382 }
371} 383}
372 384
@@ -385,7 +397,8 @@ static int msp3400c_detect_stereo(struct i2c_client *client)
385 val = msp_read_dsp(client, 0x18); 397 val = msp_read_dsp(client, 0x18);
386 if (val > 32767) 398 if (val > 32767)
387 val -= 65536; 399 val -= 65536;
388 v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val); 400 v4l_dbg(2, msp_debug, client,
401 "stereo detect register: %d\n", val);
389 if (val > 8192) { 402 if (val > 8192) {
390 rxsubchans = V4L2_TUNER_SUB_STEREO; 403 rxsubchans = V4L2_TUNER_SUB_STEREO;
391 } else if (val < -4096) { 404 } else if (val < -4096) {
@@ -430,7 +443,8 @@ static int msp3400c_detect_stereo(struct i2c_client *client)
430 } 443 }
431 if (rxsubchans != state->rxsubchans) { 444 if (rxsubchans != state->rxsubchans) {
432 update = 1; 445 update = 1;
433 v4l_dbg(1, msp_debug, client, "watch: rxsubchans %02x => %02x\n", 446 v4l_dbg(1, msp_debug, client,
447 "watch: rxsubchans %02x => %02x\n",
434 state->rxsubchans, rxsubchans); 448 state->rxsubchans, rxsubchans);
435 state->rxsubchans = rxsubchans; 449 state->rxsubchans = rxsubchans;
436 } 450 }
@@ -452,9 +466,8 @@ static void watch_stereo(struct i2c_client *client)
452{ 466{
453 struct msp_state *state = i2c_get_clientdata(client); 467 struct msp_state *state = i2c_get_clientdata(client);
454 468
455 if (msp_detect_stereo(client)) { 469 if (msp_detect_stereo(client))
456 msp_set_audmode(client); 470 msp_set_audmode(client);
457 }
458 471
459 if (msp_once) 472 if (msp_once)
460 state->watch_stereo = 0; 473 state->watch_stereo = 0;
@@ -465,7 +478,7 @@ int msp3400c_thread(void *data)
465 struct i2c_client *client = data; 478 struct i2c_client *client = data;
466 struct msp_state *state = i2c_get_clientdata(client); 479 struct msp_state *state = i2c_get_clientdata(client);
467 struct msp3400c_carrier_detect *cd; 480 struct msp3400c_carrier_detect *cd;
468 int count, max1, max2, val1, val2, val, this; 481 int count, max1, max2, val1, val2, val, i;
469 482
470 483
471 v4l_dbg(1, msp_debug, client, "msp3400 daemon started\n"); 484 v4l_dbg(1, msp_debug, client, "msp3400 daemon started\n");
@@ -475,7 +488,7 @@ int msp3400c_thread(void *data)
475 msp_sleep(state, -1); 488 msp_sleep(state, -1);
476 v4l_dbg(2, msp_debug, client, "msp3400 thread: wakeup\n"); 489 v4l_dbg(2, msp_debug, client, "msp3400 thread: wakeup\n");
477 490
478 restart: 491restart:
479 v4l_dbg(2, msp_debug, client, "thread: restart scan\n"); 492 v4l_dbg(2, msp_debug, client, "thread: restart scan\n");
480 state->restart = 0; 493 state->restart = 0;
481 if (kthread_should_stop()) 494 if (kthread_should_stop())
@@ -483,7 +496,8 @@ int msp3400c_thread(void *data)
483 496
484 if (state->radio || MSP_MODE_EXTERN == state->mode) { 497 if (state->radio || MSP_MODE_EXTERN == state->mode) {
485 /* no carrier scan, just unmute */ 498 /* no carrier scan, just unmute */
486 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); 499 v4l_dbg(1, msp_debug, client,
500 "thread: no carrier scan\n");
487 state->scan_in_progress = 0; 501 state->scan_in_progress = 0;
488 msp_set_audio(client); 502 msp_set_audio(client);
489 continue; 503 continue;
@@ -514,16 +528,17 @@ int msp3400c_thread(void *data)
514 v4l_dbg(1, msp_debug, client, "AM sound override\n"); 528 v4l_dbg(1, msp_debug, client, "AM sound override\n");
515 } 529 }
516 530
517 for (this = 0; this < count; this++) { 531 for (i = 0; i < count; i++) {
518 msp3400c_set_carrier(client, cd[this].cdo, cd[this].cdo); 532 msp3400c_set_carrier(client, cd[i].cdo, cd[i].cdo);
519 if (msp_sleep(state,100)) 533 if (msp_sleep(state, 100))
520 goto restart; 534 goto restart;
521 val = msp_read_dsp(client, 0x1b); 535 val = msp_read_dsp(client, 0x1b);
522 if (val > 32767) 536 if (val > 32767)
523 val -= 65536; 537 val -= 65536;
524 if (val1 < val) 538 if (val1 < val)
525 val1 = val, max1 = this; 539 val1 = val, max1 = i;
526 v4l_dbg(1, msp_debug, client, "carrier1 val: %5d / %s\n", val,cd[this].name); 540 v4l_dbg(1, msp_debug, client,
541 "carrier1 val: %5d / %s\n", val, cd[i].name);
527 } 542 }
528 543
529 /* carrier detect pass #2 -- second (stereo) carrier */ 544 /* carrier detect pass #2 -- second (stereo) carrier */
@@ -550,16 +565,17 @@ int msp3400c_thread(void *data)
550 count = 0; 565 count = 0;
551 max2 = 0; 566 max2 = 0;
552 } 567 }
553 for (this = 0; this < count; this++) { 568 for (i = 0; i < count; i++) {
554 msp3400c_set_carrier(client, cd[this].cdo, cd[this].cdo); 569 msp3400c_set_carrier(client, cd[i].cdo, cd[i].cdo);
555 if (msp_sleep(state,100)) 570 if (msp_sleep(state, 100))
556 goto restart; 571 goto restart;
557 val = msp_read_dsp(client, 0x1b); 572 val = msp_read_dsp(client, 0x1b);
558 if (val > 32767) 573 if (val > 32767)
559 val -= 65536; 574 val -= 65536;
560 if (val2 < val) 575 if (val2 < val)
561 val2 = val, max2 = this; 576 val2 = val, max2 = i;
562 v4l_dbg(1, msp_debug, client, "carrier2 val: %5d / %s\n", val,cd[this].name); 577 v4l_dbg(1, msp_debug, client,
578 "carrier2 val: %5d / %s\n", val, cd[i].name);
563 } 579 }
564 580
565 /* program the msp3400 according to the results */ 581 /* program the msp3400 according to the results */
@@ -611,7 +627,7 @@ int msp3400c_thread(void *data)
611 break; 627 break;
612 case 0: /* 4.5 */ 628 case 0: /* 4.5 */
613 default: 629 default:
614 no_second: 630no_second:
615 state->second = msp3400c_carrier_detect_main[max1].cdo; 631 state->second = msp3400c_carrier_detect_main[max1].cdo;
616 msp3400c_set_mode(client, MSP_MODE_FM_TERRA); 632 msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
617 break; 633 break;
@@ -632,7 +648,8 @@ int msp3400c_thread(void *data)
632 while (state->watch_stereo) { 648 while (state->watch_stereo) {
633 if (msp_sleep(state, count ? 1000 : 5000)) 649 if (msp_sleep(state, count ? 1000 : 5000))
634 goto restart; 650 goto restart;
635 if (count) count--; 651 if (count)
652 count--;
636 watch_stereo(client); 653 watch_stereo(client);
637 } 654 }
638 } 655 }
@@ -651,10 +668,10 @@ int msp3410d_thread(void *data)
651 set_freezable(); 668 set_freezable();
652 for (;;) { 669 for (;;) {
653 v4l_dbg(2, msp_debug, client, "msp3410 thread: sleep\n"); 670 v4l_dbg(2, msp_debug, client, "msp3410 thread: sleep\n");
654 msp_sleep(state,-1); 671 msp_sleep(state, -1);
655 v4l_dbg(2, msp_debug, client, "msp3410 thread: wakeup\n"); 672 v4l_dbg(2, msp_debug, client, "msp3410 thread: wakeup\n");
656 673
657 restart: 674restart:
658 v4l_dbg(2, msp_debug, client, "thread: restart scan\n"); 675 v4l_dbg(2, msp_debug, client, "thread: restart scan\n");
659 state->restart = 0; 676 state->restart = 0;
660 if (kthread_should_stop()) 677 if (kthread_should_stop())
@@ -662,7 +679,8 @@ int msp3410d_thread(void *data)
662 679
663 if (state->mode == MSP_MODE_EXTERN) { 680 if (state->mode == MSP_MODE_EXTERN) {
664 /* no carrier scan needed, just unmute */ 681 /* no carrier scan needed, just unmute */
665 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); 682 v4l_dbg(1, msp_debug, client,
683 "thread: no carrier scan\n");
666 state->scan_in_progress = 0; 684 state->scan_in_progress = 0;
667 msp_set_audio(client); 685 msp_set_audio(client);
668 continue; 686 continue;
@@ -673,7 +691,8 @@ int msp3410d_thread(void *data)
673 msp_set_audio(client); 691 msp_set_audio(client);
674 692
675 /* start autodetect. Note: autodetect is not supported for 693 /* start autodetect. Note: autodetect is not supported for
676 NTSC-M and radio, hence we force the standard in those cases. */ 694 NTSC-M and radio, hence we force the standard in those
695 cases. */
677 if (state->radio) 696 if (state->radio)
678 std = 0x40; 697 std = 0x40;
679 else 698 else
@@ -686,8 +705,9 @@ int msp3410d_thread(void *data)
686 goto restart; 705 goto restart;
687 706
688 if (msp_debug) 707 if (msp_debug)
689 v4l_dbg(2, msp_debug, client, "setting standard: %s (0x%04x)\n", 708 v4l_dbg(2, msp_debug, client,
690 msp_standard_std_name(std), std); 709 "setting standard: %s (0x%04x)\n",
710 msp_standard_std_name(std), std);
691 711
692 if (std != 1) { 712 if (std != 1) {
693 /* programmed some specific mode */ 713 /* programmed some specific mode */
@@ -703,7 +723,8 @@ int msp3410d_thread(void *data)
703 val = msp_read_dem(client, 0x7e); 723 val = msp_read_dem(client, 0x7e);
704 if (val < 0x07ff) 724 if (val < 0x07ff)
705 break; 725 break;
706 v4l_dbg(2, msp_debug, client, "detection still in progress\n"); 726 v4l_dbg(2, msp_debug, client,
727 "detection still in progress\n");
707 } 728 }
708 } 729 }
709 for (i = 0; msp_stdlist[i].name != NULL; i++) 730 for (i = 0; msp_stdlist[i].name != NULL; i++)
@@ -716,12 +737,13 @@ int msp3410d_thread(void *data)
716 state->std = val; 737 state->std = val;
717 state->rxsubchans = V4L2_TUNER_SUB_MONO; 738 state->rxsubchans = V4L2_TUNER_SUB_MONO;
718 739
719 if (msp_amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) && 740 if (msp_amsound && !state->radio &&
720 (val != 0x0009)) { 741 (state->v4l2_std & V4L2_STD_SECAM) && (val != 0x0009)) {
721 /* autodetection has failed, let backup */ 742 /* autodetection has failed, let backup */
722 v4l_dbg(1, msp_debug, client, "autodetection failed," 743 v4l_dbg(1, msp_debug, client, "autodetection failed,"
723 " switching to backup standard: %s (0x%04x)\n", 744 " switching to backup standard: %s (0x%04x)\n",
724 msp_stdlist[8].name ? msp_stdlist[8].name : "unknown",val); 745 msp_stdlist[8].name ?
746 msp_stdlist[8].name : "unknown", val);
725 state->std = val = 0x0009; 747 state->std = val = 0x0009;
726 msp_write_dem(client, 0x20, val); 748 msp_write_dem(client, 0x20, val);
727 } 749 }
@@ -786,7 +808,8 @@ int msp3410d_thread(void *data)
786 while (state->watch_stereo) { 808 while (state->watch_stereo) {
787 if (msp_sleep(state, count ? 1000 : 5000)) 809 if (msp_sleep(state, count ? 1000 : 5000))
788 goto restart; 810 goto restart;
789 if (count) count--; 811 if (count)
812 count--;
790 watch_stereo(client); 813 watch_stereo(client);
791 } 814 }
792 } 815 }
@@ -872,8 +895,8 @@ static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in)
872 else 895 else
873 source = (in << 8) | matrix; 896 source = (in << 8) | matrix;
874 897
875 v4l_dbg(1, msp_debug, client, "set source to %d (0x%x) for output %02x\n", 898 v4l_dbg(1, msp_debug, client,
876 in, source, reg); 899 "set source to %d (0x%x) for output %02x\n", in, source, reg);
877 msp_write_dsp(client, reg, source); 900 msp_write_dsp(client, reg, source);
878} 901}
879 902
@@ -948,7 +971,7 @@ int msp34xxg_thread(void *data)
948 msp_sleep(state, -1); 971 msp_sleep(state, -1);
949 v4l_dbg(2, msp_debug, client, "msp34xxg thread: wakeup\n"); 972 v4l_dbg(2, msp_debug, client, "msp34xxg thread: wakeup\n");
950 973
951 restart: 974restart:
952 v4l_dbg(1, msp_debug, client, "thread: restart scan\n"); 975 v4l_dbg(1, msp_debug, client, "thread: restart scan\n");
953 state->restart = 0; 976 state->restart = 0;
954 if (kthread_should_stop()) 977 if (kthread_should_stop())
@@ -956,7 +979,8 @@ int msp34xxg_thread(void *data)
956 979
957 if (state->mode == MSP_MODE_EXTERN) { 980 if (state->mode == MSP_MODE_EXTERN) {
958 /* no carrier scan needed, just unmute */ 981 /* no carrier scan needed, just unmute */
959 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); 982 v4l_dbg(1, msp_debug, client,
983 "thread: no carrier scan\n");
960 state->scan_in_progress = 0; 984 state->scan_in_progress = 0;
961 msp_set_audio(client); 985 msp_set_audio(client);
962 continue; 986 continue;
@@ -972,7 +996,8 @@ int msp34xxg_thread(void *data)
972 goto unmute; 996 goto unmute;
973 997
974 /* watch autodetect */ 998 /* watch autodetect */
975 v4l_dbg(1, msp_debug, client, "started autodetect, waiting for result\n"); 999 v4l_dbg(1, msp_debug, client,
1000 "started autodetect, waiting for result\n");
976 for (i = 0; i < 10; i++) { 1001 for (i = 0; i < 10; i++) {
977 if (msp_sleep(state, 100)) 1002 if (msp_sleep(state, 100))
978 goto restart; 1003 goto restart;
@@ -983,15 +1008,18 @@ int msp34xxg_thread(void *data)
983 state->std = val; 1008 state->std = val;
984 break; 1009 break;
985 } 1010 }
986 v4l_dbg(2, msp_debug, client, "detection still in progress\n"); 1011 v4l_dbg(2, msp_debug, client,
1012 "detection still in progress\n");
987 } 1013 }
988 if (state->std == 1) { 1014 if (state->std == 1) {
989 v4l_dbg(1, msp_debug, client, "detection still in progress after 10 tries. giving up.\n"); 1015 v4l_dbg(1, msp_debug, client,
1016 "detection still in progress after 10 tries. giving up.\n");
990 continue; 1017 continue;
991 } 1018 }
992 1019
993 unmute: 1020unmute:
994 v4l_dbg(1, msp_debug, client, "detected standard: %s (0x%04x)\n", 1021 v4l_dbg(1, msp_debug, client,
1022 "detected standard: %s (0x%04x)\n",
995 msp_standard_std_name(state->std), state->std); 1023 msp_standard_std_name(state->std), state->std);
996 1024
997 if (state->std == 9) { 1025 if (state->std == 9) {
@@ -1046,9 +1074,11 @@ static int msp34xxg_detect_stereo(struct i2c_client *client)
1046 if (state->std == 0x20) 1074 if (state->std == 0x20)
1047 state->rxsubchans |= V4L2_TUNER_SUB_SAP; 1075 state->rxsubchans |= V4L2_TUNER_SUB_SAP;
1048 else 1076 else
1049 state->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 1077 state->rxsubchans =
1078 V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
1050 } 1079 }
1051 v4l_dbg(1, msp_debug, client, "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n", 1080 v4l_dbg(1, msp_debug, client,
1081 "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n",
1052 status, is_stereo, is_bilingual, state->rxsubchans); 1082 status, is_stereo, is_bilingual, state->rxsubchans);
1053 return (oldrx != state->rxsubchans); 1083 return (oldrx != state->rxsubchans);
1054} 1084}
diff --git a/drivers/media/video/mt20xx.c b/drivers/media/video/mt20xx.c
index f49d1f4c40db..b630c26cfe85 100644
--- a/drivers/media/video/mt20xx.c
+++ b/drivers/media/video/mt20xx.c
@@ -14,7 +14,7 @@ static int debug = 0;
14module_param(debug, int, 0644); 14module_param(debug, int, 0644);
15MODULE_PARM_DESC(debug, "enable verbose debug messages"); 15MODULE_PARM_DESC(debug, "enable verbose debug messages");
16 16
17#define PREFIX "mt20xx " 17#define PREFIX "mt20xx"
18 18
19/* ---------------------------------------------------------------------- */ 19/* ---------------------------------------------------------------------- */
20 20
diff --git a/drivers/media/video/pvrusb2/Kconfig b/drivers/media/video/pvrusb2/Kconfig
index d0c2cd785430..6fc1b8be1a1f 100644
--- a/drivers/media/video/pvrusb2/Kconfig
+++ b/drivers/media/video/pvrusb2/Kconfig
@@ -5,6 +5,10 @@ config VIDEO_PVRUSB2
5 select VIDEO_TUNER 5 select VIDEO_TUNER
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
7 select VIDEO_CX2341X 7 select VIDEO_CX2341X
8 select VIDEO_SAA711X
9 select VIDEO_CX25840
10 select VIDEO_MSP3400
11 select VIDEO_WM8775
8 ---help--- 12 ---help---
9 This is a video4linux driver for Conexant 23416 based 13 This is a video4linux driver for Conexant 23416 based
10 usb2 personal video recorder devices. 14 usb2 personal video recorder devices.
@@ -12,32 +16,29 @@ config VIDEO_PVRUSB2
12 To compile this driver as a module, choose M here: the 16 To compile this driver as a module, choose M here: the
13 module will be called pvrusb2 17 module will be called pvrusb2
14 18
15config VIDEO_PVRUSB2_29XXX 19config VIDEO_PVRUSB2_ONAIR_CREATOR
16 bool "Hauppauge WinTV-PVR USB2 support for 29xxx model series" 20 bool "pvrusb2 driver support for OnAir Creator model"
17 depends on VIDEO_PVRUSB2 && EXPERIMENTAL 21 depends on VIDEO_PVRUSB2 && EXPERIMENTAL
18 select VIDEO_SAA711X 22 select VIDEO_SAA711X
19 select VIDEO_MSP3400 23 select VIDEO_CS53L32A
20 ---help--- 24 ---help---
21 This option enables support for WinTV-PVR USB2 devices whose 25
22 model number is of the form "29xxx" (leading prefix of "29" 26 This option enables support for the OnAir Creator USB tuner
23 followed by 3 digits). 27 device. This is a hybrid device, however currently only
24 To see if you may need this option, examine the white 28 analog mode is supported.
25 sticker on the underside of your device.
26 29
27 If you are in doubt, say Y. 30 If you are in doubt, say Y.
28 31
29config VIDEO_PVRUSB2_24XXX 32config VIDEO_PVRUSB2_ONAIR_USB2
30 bool "Hauppauge WinTV-PVR USB2 support for 24xxx model series" 33 bool "pvrusb2 driver support for OnAir USB2 model"
31 depends on VIDEO_PVRUSB2 && EXPERIMENTAL 34 depends on VIDEO_PVRUSB2 && EXPERIMENTAL
32 select VIDEO_CX25840 35 select VIDEO_SAA711X
33 select VIDEO_WM8775 36 select VIDEO_CS53L32A
34 ---help--- 37 ---help---
35 This option enables inclusion of additional logic to operate 38
36 newer WinTV-PVR USB2 devices whose model number is of the 39 This option enables support for the OnAir USB2 tuner device
37 form "24xxx" (leading prefix of "24" followed by 3 digits). 40 (also known as the Sasem tuner). This is a hybrid device,
38 To see if you may need this option, examine the white 41 however currently only analog mode is supported.
39 sticker on the underside of your device. Enabling this
40 option will not harm support for older devices.
41 42
42 If you are in doubt, say Y. 43 If you are in doubt, say Y.
43 44
diff --git a/drivers/media/video/pvrusb2/Makefile b/drivers/media/video/pvrusb2/Makefile
index 69b3e43cd0eb..47284e558648 100644
--- a/drivers/media/video/pvrusb2/Makefile
+++ b/drivers/media/video/pvrusb2/Makefile
@@ -6,7 +6,7 @@ pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \
6 pvrusb2-encoder.o pvrusb2-video-v4l.o \ 6 pvrusb2-encoder.o pvrusb2-video-v4l.o \
7 pvrusb2-eeprom.o pvrusb2-tuner.o \ 7 pvrusb2-eeprom.o pvrusb2-tuner.o \
8 pvrusb2-main.o pvrusb2-hdw.o pvrusb2-v4l2.o \ 8 pvrusb2-main.o pvrusb2-hdw.o pvrusb2-v4l2.o \
9 pvrusb2-ctrl.o pvrusb2-std.o \ 9 pvrusb2-ctrl.o pvrusb2-std.o pvrusb2-devattr.o \
10 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \ 10 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \
11 pvrusb2-cx2584x-v4l.o pvrusb2-wm8775.o \ 11 pvrusb2-cx2584x-v4l.o pvrusb2-wm8775.o \
12 $(obj-pvrusb2-sysfs-y) $(obj-pvrusb2-debugifc-y) 12 $(obj-pvrusb2-sysfs-y) $(obj-pvrusb2-debugifc-y)
diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.c b/drivers/media/video/pvrusb2/pvrusb2-audio.c
index 379645e481c6..9a7c8e9c3e8b 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.c
@@ -35,34 +35,58 @@ struct pvr2_msp3400_handler {
35}; 35};
36 36
37 37
38
39struct routing_scheme {
40 const int *def;
41 unsigned int cnt;
42};
43
44static const int routing_scheme0[] = {
45 [PVR2_CVAL_INPUT_TV] = MSP_INPUT_DEFAULT,
46 [PVR2_CVAL_INPUT_RADIO] = MSP_INPUT(MSP_IN_SCART2,
47 MSP_IN_TUNER1,
48 MSP_DSP_IN_SCART,
49 MSP_DSP_IN_SCART),
50 [PVR2_CVAL_INPUT_COMPOSITE] = MSP_INPUT(MSP_IN_SCART1,
51 MSP_IN_TUNER1,
52 MSP_DSP_IN_SCART,
53 MSP_DSP_IN_SCART),
54 [PVR2_CVAL_INPUT_SVIDEO] = MSP_INPUT(MSP_IN_SCART1,
55 MSP_IN_TUNER1,
56 MSP_DSP_IN_SCART,
57 MSP_DSP_IN_SCART),
58};
59
60static const struct routing_scheme routing_schemes[] = {
61 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
62 .def = routing_scheme0,
63 .cnt = ARRAY_SIZE(routing_scheme0),
64 },
65};
66
38/* This function selects the correct audio input source */ 67/* This function selects the correct audio input source */
39static void set_stereo(struct pvr2_msp3400_handler *ctxt) 68static void set_stereo(struct pvr2_msp3400_handler *ctxt)
40{ 69{
41 struct pvr2_hdw *hdw = ctxt->hdw; 70 struct pvr2_hdw *hdw = ctxt->hdw;
42 struct v4l2_routing route; 71 struct v4l2_routing route;
72 const struct routing_scheme *sp;
73 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
43 74
44 pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo"); 75 pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo");
45 76
46 route.input = MSP_INPUT_DEFAULT; 77 if ((sid < ARRAY_SIZE(routing_schemes)) &&
47 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); 78 ((sp = routing_schemes + sid) != 0) &&
48 switch (hdw->input_val) { 79 (hdw->input_val >= 0) &&
49 case PVR2_CVAL_INPUT_TV: 80 (hdw->input_val < sp->cnt)) {
50 break; 81 route.input = sp->def[hdw->input_val];
51 case PVR2_CVAL_INPUT_RADIO: 82 } else {
52 /* Assume that msp34xx also handle FM decoding, in which case 83 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
53 we're still using the tuner. */ 84 "*** WARNING *** i2c msp3400 v4l2 set_stereo:"
54 /* HV: actually it is more likely to be the SCART2 input if 85 " Invalid routing scheme (%u) and/or input (%d)",
55 the ivtv experience is any indication. */ 86 sid,hdw->input_val);
56 route.input = MSP_INPUT(MSP_IN_SCART2, MSP_IN_TUNER1, 87 return;
57 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
58 break;
59 case PVR2_CVAL_INPUT_SVIDEO:
60 case PVR2_CVAL_INPUT_COMPOSITE:
61 /* SCART 1 input */
62 route.input = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
63 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
64 break;
65 } 88 }
89 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
66 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route); 90 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
67} 91}
68 92
diff --git a/drivers/media/video/pvrusb2/pvrusb2-context.c b/drivers/media/video/pvrusb2/pvrusb2-context.c
index 22719ba861ac..9d94aed2e12d 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-context.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-context.c
@@ -31,52 +31,32 @@
31 31
32static void pvr2_context_destroy(struct pvr2_context *mp) 32static void pvr2_context_destroy(struct pvr2_context *mp)
33{ 33{
34 if (mp->hdw) pvr2_hdw_destroy(mp->hdw);
35 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr_main id=%p",mp); 34 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr_main id=%p",mp);
36 if (mp->workqueue) { 35 if (mp->hdw) pvr2_hdw_destroy(mp->hdw);
37 flush_workqueue(mp->workqueue);
38 destroy_workqueue(mp->workqueue);
39 }
40 kfree(mp); 36 kfree(mp);
41} 37}
42 38
43 39
44static void pvr2_context_trigger_poll(struct pvr2_context *mp) 40static void pvr2_context_state_check(struct pvr2_context *mp)
45{
46 queue_work(mp->workqueue,&mp->workpoll);
47}
48
49
50static void pvr2_context_poll(struct work_struct *work)
51{
52 struct pvr2_context *mp =
53 container_of(work, struct pvr2_context, workpoll);
54 pvr2_context_enter(mp); do {
55 pvr2_hdw_poll(mp->hdw);
56 } while (0); pvr2_context_exit(mp);
57}
58
59
60static void pvr2_context_setup(struct work_struct *work)
61{ 41{
62 struct pvr2_context *mp = 42 if (mp->init_flag) return;
63 container_of(work, struct pvr2_context, workinit); 43
44 switch (pvr2_hdw_get_state(mp->hdw)) {
45 case PVR2_STATE_WARM: break;
46 case PVR2_STATE_ERROR: break;
47 case PVR2_STATE_READY: break;
48 case PVR2_STATE_RUN: break;
49 default: return;
50 }
64 51
65 pvr2_context_enter(mp); do { 52 pvr2_context_enter(mp); do {
66 if (!pvr2_hdw_dev_ok(mp->hdw)) break; 53 mp->init_flag = !0;
67 pvr2_hdw_setup(mp->hdw);
68 pvr2_hdw_setup_poll_trigger(
69 mp->hdw,
70 (void (*)(void *))pvr2_context_trigger_poll,
71 mp);
72 if (!pvr2_hdw_dev_ok(mp->hdw)) break;
73 if (!pvr2_hdw_init_ok(mp->hdw)) break;
74 mp->video_stream.stream = pvr2_hdw_get_video_stream(mp->hdw); 54 mp->video_stream.stream = pvr2_hdw_get_video_stream(mp->hdw);
75 if (mp->setup_func) { 55 if (mp->setup_func) {
76 mp->setup_func(mp); 56 mp->setup_func(mp);
77 } 57 }
78 } while (0); pvr2_context_exit(mp); 58 } while (0); pvr2_context_exit(mp);
79} 59 }
80 60
81 61
82struct pvr2_context *pvr2_context_create( 62struct pvr2_context *pvr2_context_create(
@@ -96,11 +76,10 @@ struct pvr2_context *pvr2_context_create(
96 mp = NULL; 76 mp = NULL;
97 goto done; 77 goto done;
98 } 78 }
99 79 pvr2_hdw_set_state_callback(mp->hdw,
100 mp->workqueue = create_singlethread_workqueue("pvrusb2"); 80 (void (*)(void *))pvr2_context_state_check,
101 INIT_WORK(&mp->workinit, pvr2_context_setup); 81 mp);
102 INIT_WORK(&mp->workpoll, pvr2_context_poll); 82 pvr2_context_state_check(mp);
103 queue_work(mp->workqueue,&mp->workinit);
104 done: 83 done:
105 return mp; 84 return mp;
106} 85}
diff --git a/drivers/media/video/pvrusb2/pvrusb2-context.h b/drivers/media/video/pvrusb2/pvrusb2-context.h
index 6327fa1f7e4f..a04187a93225 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-context.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-context.h
@@ -45,14 +45,11 @@ struct pvr2_context {
45 struct pvr2_context_stream video_stream; 45 struct pvr2_context_stream video_stream;
46 struct mutex mutex; 46 struct mutex mutex;
47 int disconnect_flag; 47 int disconnect_flag;
48 int init_flag;
48 49
49 /* Called after pvr2_context initialization is complete */ 50 /* Called after pvr2_context initialization is complete */
50 void (*setup_func)(struct pvr2_context *); 51 void (*setup_func)(struct pvr2_context *);
51 52
52 /* Work queue overhead for out-of-line processing */
53 struct workqueue_struct *workqueue;
54 struct work_struct workinit;
55 struct work_struct workpoll;
56}; 53};
57 54
58struct pvr2_channel { 55struct pvr2_channel {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index e8a9252c7df6..ffdc45c324e5 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -49,34 +49,89 @@ struct pvr2_v4l_cx2584x {
49}; 49};
50 50
51 51
52struct routing_scheme_item {
53 int vid;
54 int aud;
55};
56
57struct routing_scheme {
58 const struct routing_scheme_item *def;
59 unsigned int cnt;
60};
61
62static const struct routing_scheme_item routing_scheme0[] = {
63 [PVR2_CVAL_INPUT_TV] = {
64 .vid = CX25840_COMPOSITE7,
65 .aud = CX25840_AUDIO8,
66 },
67 [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
68 .vid = CX25840_COMPOSITE3,
69 .aud = CX25840_AUDIO_SERIAL,
70 },
71 [PVR2_CVAL_INPUT_COMPOSITE] = {
72 .vid = CX25840_COMPOSITE3,
73 .aud = CX25840_AUDIO_SERIAL,
74 },
75 [PVR2_CVAL_INPUT_SVIDEO] = {
76 .vid = CX25840_SVIDEO1,
77 .aud = CX25840_AUDIO_SERIAL,
78 },
79};
80
81/* Specific to gotview device */
82static const struct routing_scheme_item routing_schemegv[] = {
83 [PVR2_CVAL_INPUT_TV] = {
84 .vid = CX25840_COMPOSITE2,
85 .aud = CX25840_AUDIO5,
86 },
87 [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
88 .vid = CX25840_COMPOSITE1,
89 .aud = CX25840_AUDIO_SERIAL,
90 },
91 [PVR2_CVAL_INPUT_COMPOSITE] = {
92 .vid = CX25840_COMPOSITE1,
93 .aud = CX25840_AUDIO_SERIAL,
94 },
95 [PVR2_CVAL_INPUT_SVIDEO] = {
96 .vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
97 .aud = CX25840_AUDIO_SERIAL,
98 },
99};
100
101static const struct routing_scheme routing_schemes[] = {
102 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
103 .def = routing_scheme0,
104 .cnt = ARRAY_SIZE(routing_scheme0),
105 },
106 [PVR2_ROUTING_SCHEME_GOTVIEW] = {
107 .def = routing_schemegv,
108 .cnt = ARRAY_SIZE(routing_schemegv),
109 },
110};
111
52static void set_input(struct pvr2_v4l_cx2584x *ctxt) 112static void set_input(struct pvr2_v4l_cx2584x *ctxt)
53{ 113{
54 struct pvr2_hdw *hdw = ctxt->hdw; 114 struct pvr2_hdw *hdw = ctxt->hdw;
55 struct v4l2_routing route; 115 struct v4l2_routing route;
56 enum cx25840_video_input vid_input; 116 enum cx25840_video_input vid_input;
57 enum cx25840_audio_input aud_input; 117 enum cx25840_audio_input aud_input;
118 const struct routing_scheme *sp;
119 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
58 120
59 memset(&route,0,sizeof(route)); 121 memset(&route,0,sizeof(route));
60 122
61 switch(hdw->input_val) { 123 if ((sid < ARRAY_SIZE(routing_schemes)) &&
62 case PVR2_CVAL_INPUT_TV: 124 ((sp = routing_schemes + sid) != 0) &&
63 vid_input = CX25840_COMPOSITE7; 125 (hdw->input_val >= 0) &&
64 aud_input = CX25840_AUDIO8; 126 (hdw->input_val < sp->cnt)) {
65 break; 127 vid_input = sp->def[hdw->input_val].vid;
66 case PVR2_CVAL_INPUT_RADIO: // Treat same as composite 128 aud_input = sp->def[hdw->input_val].aud;
67 case PVR2_CVAL_INPUT_COMPOSITE: 129 } else {
68 vid_input = CX25840_COMPOSITE3; 130 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
69 aud_input = CX25840_AUDIO_SERIAL; 131 "*** WARNING *** i2c cx2584x set_input:"
70 break; 132 " Invalid routing scheme (%u) and/or input (%d)",
71 case PVR2_CVAL_INPUT_SVIDEO: 133 sid,hdw->input_val);
72 vid_input = CX25840_SVIDEO1; 134 return;
73 aud_input = CX25840_AUDIO_SERIAL;
74 break;
75 default:
76 // Just set it to be composite input for now...
77 vid_input = CX25840_COMPOSITE3;
78 aud_input = CX25840_AUDIO_SERIAL;
79 break;
80 } 135 }
81 136
82 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx2584x set_input vid=0x%x aud=0x%x", 137 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx2584x set_input vid=0x%x aud=0x%x",
@@ -140,7 +195,7 @@ static const struct pvr2_v4l_cx2584x_ops decoder_ops[] = {
140static void decoder_detach(struct pvr2_v4l_cx2584x *ctxt) 195static void decoder_detach(struct pvr2_v4l_cx2584x *ctxt)
141{ 196{
142 ctxt->client->handler = NULL; 197 ctxt->client->handler = NULL;
143 ctxt->hdw->decoder_ctrl = NULL; 198 pvr2_hdw_set_decoder(ctxt->hdw,NULL);
144 kfree(ctxt); 199 kfree(ctxt);
145} 200}
146 201
@@ -241,7 +296,7 @@ int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *hdw,
241 ctxt->client = cp; 296 ctxt->client = cp;
242 ctxt->hdw = hdw; 297 ctxt->hdw = hdw;
243 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1; 298 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
244 hdw->decoder_ctrl = &ctxt->ctrl; 299 pvr2_hdw_set_decoder(hdw,&ctxt->ctrl);
245 cp->handler = &ctxt->handler; 300 cp->handler = &ctxt->handler;
246 { 301 {
247 /* 302 /*
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debug.h b/drivers/media/video/pvrusb2/pvrusb2-debug.h
index da6441b88f31..fca49d8a9311 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debug.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-debug.h
@@ -34,25 +34,26 @@ extern int pvrusb2_debug;
34#define PVR2_TRACE_INIT (1 << 5) /* misc initialization steps */ 34#define PVR2_TRACE_INIT (1 << 5) /* misc initialization steps */
35#define PVR2_TRACE_START_STOP (1 << 6) /* Streaming start / stop */ 35#define PVR2_TRACE_START_STOP (1 << 6) /* Streaming start / stop */
36#define PVR2_TRACE_CTL (1 << 7) /* commit of control changes */ 36#define PVR2_TRACE_CTL (1 << 7) /* commit of control changes */
37#define PVR2_TRACE_DEBUG (1 << 8) /* Temporary debug code */ 37#define PVR2_TRACE_STATE (1 << 8) /* Device state changes */
38#define PVR2_TRACE_EEPROM (1 << 9) /* eeprom parsing / report */ 38#define PVR2_TRACE_STBITS (1 << 9) /* Individual bit state changes */
39#define PVR2_TRACE_STRUCT (1 << 10) /* internal struct creation */ 39#define PVR2_TRACE_EEPROM (1 << 10) /* eeprom parsing / report */
40#define PVR2_TRACE_OPEN_CLOSE (1 << 11) /* application open / close */ 40#define PVR2_TRACE_STRUCT (1 << 11) /* internal struct creation */
41#define PVR2_TRACE_CREG (1 << 12) /* Main critical region entry / exit */ 41#define PVR2_TRACE_OPEN_CLOSE (1 << 12) /* application open / close */
42#define PVR2_TRACE_SYSFS (1 << 13) /* Sysfs driven I/O */ 42#define PVR2_TRACE_CREG (1 << 13) /* Main critical region entry / exit */
43#define PVR2_TRACE_FIRMWARE (1 << 14) /* firmware upload actions */ 43#define PVR2_TRACE_SYSFS (1 << 14) /* Sysfs driven I/O */
44#define PVR2_TRACE_CHIPS (1 << 15) /* chip broadcast operation */ 44#define PVR2_TRACE_FIRMWARE (1 << 15) /* firmware upload actions */
45#define PVR2_TRACE_I2C (1 << 16) /* I2C related stuff */ 45#define PVR2_TRACE_CHIPS (1 << 16) /* chip broadcast operation */
46#define PVR2_TRACE_I2C_CMD (1 << 17) /* Software commands to I2C modules */ 46#define PVR2_TRACE_I2C (1 << 17) /* I2C related stuff */
47#define PVR2_TRACE_I2C_CORE (1 << 18) /* I2C core debugging */ 47#define PVR2_TRACE_I2C_CMD (1 << 18) /* Software commands to I2C modules */
48#define PVR2_TRACE_I2C_TRAF (1 << 19) /* I2C traffic through the adapter */ 48#define PVR2_TRACE_I2C_CORE (1 << 19) /* I2C core debugging */
49#define PVR2_TRACE_V4LIOCTL (1 << 20) /* v4l ioctl details */ 49#define PVR2_TRACE_I2C_TRAF (1 << 20) /* I2C traffic through the adapter */
50#define PVR2_TRACE_ENCODER (1 << 21) /* mpeg2 encoder operation */ 50#define PVR2_TRACE_V4LIOCTL (1 << 21) /* v4l ioctl details */
51#define PVR2_TRACE_BUF_POOL (1 << 22) /* Track buffer pool management */ 51#define PVR2_TRACE_ENCODER (1 << 22) /* mpeg2 encoder operation */
52#define PVR2_TRACE_BUF_FLOW (1 << 23) /* Track buffer flow in system */ 52#define PVR2_TRACE_BUF_POOL (1 << 23) /* Track buffer pool management */
53#define PVR2_TRACE_DATA_FLOW (1 << 24) /* Track data flow */ 53#define PVR2_TRACE_BUF_FLOW (1 << 24) /* Track buffer flow in system */
54#define PVR2_TRACE_DEBUGIFC (1 << 25) /* Debug interface actions */ 54#define PVR2_TRACE_DATA_FLOW (1 << 25) /* Track data flow */
55#define PVR2_TRACE_GPIO (1 << 26) /* GPIO state bit changes */ 55#define PVR2_TRACE_DEBUGIFC (1 << 26) /* Debug interface actions */
56#define PVR2_TRACE_GPIO (1 << 27) /* GPIO state bit changes */
56 57
57 58
58#endif /* __PVRUSB2_HDW_INTERNAL_H */ 59#endif /* __PVRUSB2_HDW_INTERNAL_H */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
index 6f135f4a2497..b0687430fdd4 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
@@ -31,14 +31,6 @@ struct debugifc_mask_item {
31 unsigned long msk; 31 unsigned long msk;
32}; 32};
33 33
34static struct debugifc_mask_item mask_items[] = {
35 {"ENC_FIRMWARE",(1<<PVR2_SUBSYS_B_ENC_FIRMWARE)},
36 {"ENC_CFG",(1<<PVR2_SUBSYS_B_ENC_CFG)},
37 {"DIG_RUN",(1<<PVR2_SUBSYS_B_DIGITIZER_RUN)},
38 {"USB_RUN",(1<<PVR2_SUBSYS_B_USBSTREAM_RUN)},
39 {"ENC_RUN",(1<<PVR2_SUBSYS_B_ENC_RUN)},
40};
41
42 34
43static unsigned int debugifc_count_whitespace(const char *buf, 35static unsigned int debugifc_count_whitespace(const char *buf,
44 unsigned int count) 36 unsigned int count)
@@ -148,134 +140,14 @@ static int debugifc_match_keyword(const char *buf,unsigned int count,
148} 140}
149 141
150 142
151static unsigned long debugifc_find_mask(const char *buf,unsigned int count)
152{
153 struct debugifc_mask_item *mip;
154 unsigned int idx;
155 for (idx = 0; idx < ARRAY_SIZE(mask_items); idx++) {
156 mip = mask_items + idx;
157 if (debugifc_match_keyword(buf,count,mip->name)) {
158 return mip->msk;
159 }
160 }
161 return 0;
162}
163
164
165static int debugifc_print_mask(char *buf,unsigned int sz,
166 unsigned long msk,unsigned long val)
167{
168 struct debugifc_mask_item *mip;
169 unsigned int idx;
170 int bcnt = 0;
171 int ccnt;
172 for (idx = 0; idx < ARRAY_SIZE(mask_items); idx++) {
173 mip = mask_items + idx;
174 if (!(mip->msk & msk)) continue;
175 ccnt = scnprintf(buf,sz,"%s%c%s",
176 (bcnt ? " " : ""),
177 ((mip->msk & val) ? '+' : '-'),
178 mip->name);
179 sz -= ccnt;
180 buf += ccnt;
181 bcnt += ccnt;
182 }
183 return bcnt;
184}
185
186static unsigned int debugifc_parse_subsys_mask(const char *buf,
187 unsigned int count,
188 unsigned long *mskPtr,
189 unsigned long *valPtr)
190{
191 const char *wptr;
192 unsigned int consume_cnt = 0;
193 unsigned int scnt;
194 unsigned int wlen;
195 int mode;
196 unsigned long m1,msk,val;
197
198 msk = 0;
199 val = 0;
200
201 while (count) {
202 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
203 if (!scnt) break;
204 consume_cnt += scnt; count -= scnt; buf += scnt;
205 if (!wptr) break;
206
207 mode = 0;
208 if (wlen) switch (wptr[0]) {
209 case '+':
210 wptr++;
211 wlen--;
212 break;
213 case '-':
214 mode = 1;
215 wptr++;
216 wlen--;
217 break;
218 }
219 if (!wlen) continue;
220 m1 = debugifc_find_mask(wptr,wlen);
221 if (!m1) break;
222 msk |= m1;
223 if (!mode) val |= m1;
224 }
225 *mskPtr = msk;
226 *valPtr = val;
227 return consume_cnt;
228}
229
230
231int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt) 143int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
232{ 144{
233 int bcnt = 0; 145 int bcnt = 0;
234 int ccnt; 146 int ccnt;
235 struct pvr2_hdw_debug_info dbg; 147 ccnt = scnprintf(buf,acnt,"Driver state info:\n");
236
237 pvr2_hdw_get_debug_info(hdw,&dbg);
238
239 ccnt = scnprintf(buf,acnt,"big lock %s; ctl lock %s",
240 (dbg.big_lock_held ? "held" : "free"),
241 (dbg.ctl_lock_held ? "held" : "free"));
242 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
243 if (dbg.ctl_lock_held) {
244 ccnt = scnprintf(buf,acnt,"; cmd_state=%d cmd_code=%d"
245 " cmd_wlen=%d cmd_rlen=%d"
246 " wpend=%d rpend=%d tmout=%d rstatus=%d"
247 " wstatus=%d",
248 dbg.cmd_debug_state,dbg.cmd_code,
249 dbg.cmd_debug_write_len,
250 dbg.cmd_debug_read_len,
251 dbg.cmd_debug_write_pend,
252 dbg.cmd_debug_read_pend,
253 dbg.cmd_debug_timeout,
254 dbg.cmd_debug_rstatus,
255 dbg.cmd_debug_wstatus);
256 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
257 }
258 ccnt = scnprintf(buf,acnt,"\n");
259 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
260 ccnt = scnprintf(
261 buf,acnt,"driver flags: %s %s %s\n",
262 (dbg.flag_init_ok ? "initialized" : "uninitialized"),
263 (dbg.flag_ok ? "ok" : "fail"),
264 (dbg.flag_disconnected ? "disconnected" : "connected"));
265 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
266 ccnt = scnprintf(buf,acnt,"Subsystems enabled / configured: ");
267 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 148 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
268 ccnt = debugifc_print_mask(buf,acnt,dbg.subsys_flags,dbg.subsys_flags); 149 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
269 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 150 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
270 ccnt = scnprintf(buf,acnt,"\n");
271 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
272 ccnt = scnprintf(buf,acnt,"Subsystems disabled / unconfigured: ");
273 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
274 ccnt = debugifc_print_mask(buf,acnt,~dbg.subsys_flags,dbg.subsys_flags);
275 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
276 ccnt = scnprintf(buf,acnt,"\n");
277 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
278
279 ccnt = scnprintf(buf,acnt,"Attached I2C modules:\n"); 151 ccnt = scnprintf(buf,acnt,"Attached I2C modules:\n");
280 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 152 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
281 ccnt = pvr2_i2c_report(hdw,buf,acnt); 153 ccnt = pvr2_i2c_report(hdw,buf,acnt);
@@ -290,7 +162,6 @@ int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
290{ 162{
291 int bcnt = 0; 163 int bcnt = 0;
292 int ccnt; 164 int ccnt;
293 unsigned long msk;
294 int ret; 165 int ret;
295 u32 gpio_dir,gpio_in,gpio_out; 166 u32 gpio_dir,gpio_in,gpio_out;
296 167
@@ -311,28 +182,6 @@ int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
311 pvr2_hdw_get_streaming(hdw) ? "on" : "off"); 182 pvr2_hdw_get_streaming(hdw) ? "on" : "off");
312 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 183 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
313 184
314 msk = pvr2_hdw_subsys_get(hdw);
315 ccnt = scnprintf(buf,acnt,"Subsystems enabled / configured: ");
316 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
317 ccnt = debugifc_print_mask(buf,acnt,msk,msk);
318 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
319 ccnt = scnprintf(buf,acnt,"\n");
320 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
321 ccnt = scnprintf(buf,acnt,"Subsystems disabled / unconfigured: ");
322 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
323 ccnt = debugifc_print_mask(buf,acnt,~msk,msk);
324 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
325 ccnt = scnprintf(buf,acnt,"\n");
326 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
327
328 msk = pvr2_hdw_subsys_stream_get(hdw);
329 ccnt = scnprintf(buf,acnt,"Subsystems stopped on stream shutdown: ");
330 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
331 ccnt = debugifc_print_mask(buf,acnt,msk,msk);
332 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
333 ccnt = scnprintf(buf,acnt,"\n");
334 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
335
336 return bcnt; 185 return bcnt;
337} 186}
338 187
@@ -369,28 +218,10 @@ static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
369 return pvr2_upload_firmware2(hdw); 218 return pvr2_upload_firmware2(hdw);
370 } else if (debugifc_match_keyword(wptr,wlen,"decoder")) { 219 } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
371 return pvr2_hdw_cmd_decoder_reset(hdw); 220 return pvr2_hdw_cmd_decoder_reset(hdw);
221 } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
222 return pvr2_hdw_untrip(hdw);
372 } 223 }
373 return -EINVAL; 224 return -EINVAL;
374 } else if (debugifc_match_keyword(wptr,wlen,"subsys_flags")) {
375 unsigned long msk = 0;
376 unsigned long val = 0;
377 if (debugifc_parse_subsys_mask(buf,count,&msk,&val) != count) {
378 pvr2_trace(PVR2_TRACE_DEBUGIFC,
379 "debugifc parse error on subsys mask");
380 return -EINVAL;
381 }
382 pvr2_hdw_subsys_bit_chg(hdw,msk,val);
383 return 0;
384 } else if (debugifc_match_keyword(wptr,wlen,"stream_flags")) {
385 unsigned long msk = 0;
386 unsigned long val = 0;
387 if (debugifc_parse_subsys_mask(buf,count,&msk,&val) != count) {
388 pvr2_trace(PVR2_TRACE_DEBUGIFC,
389 "debugifc parse error on stream mask");
390 return -EINVAL;
391 }
392 pvr2_hdw_subsys_stream_bit_chg(hdw,msk,val);
393 return 0;
394 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) { 225 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
395 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen); 226 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
396 if (!scnt) return -EINVAL; 227 if (!scnt) return -EINVAL;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-devattr.c b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
new file mode 100644
index 000000000000..4df6d6d936fc
--- /dev/null
+++ b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
@@ -0,0 +1,217 @@
1/*
2 *
3 * $Id$
4 *
5 * Copyright (C) 2007 Mike Isely <isely@pobox.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22/*
23
24This source file should encompass ALL per-device type information for the
25driver. To define a new device, add elements to the pvr2_device_table and
26pvr2_device_desc structures.
27
28*/
29
30#include "pvrusb2-devattr.h"
31#include <linux/usb.h>
32/* This is needed in order to pull in tuner type ids... */
33#include <linux/i2c.h>
34#include <media/tuner.h>
35
36
37
38/*------------------------------------------------------------------------*/
39/* Hauppauge PVR-USB2 Model 29xxx */
40
41static const char *pvr2_client_29xxx[] = {
42 "msp3400",
43 "saa7115",
44 "tuner",
45};
46
47static const char *pvr2_fw1_names_29xxx[] = {
48 "v4l-pvrusb2-29xxx-01.fw",
49};
50
51static const struct pvr2_device_desc pvr2_device_29xxx = {
52 .description = "WinTV PVR USB2 Model Category 29xxxx",
53 .shortname = "29xxx",
54 .client_modules.lst = pvr2_client_29xxx,
55 .client_modules.cnt = ARRAY_SIZE(pvr2_client_29xxx),
56 .fx2_firmware.lst = pvr2_fw1_names_29xxx,
57 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_29xxx),
58 .flag_has_hauppauge_rom = !0,
59 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
60};
61
62
63
64/*------------------------------------------------------------------------*/
65/* Hauppauge PVR-USB2 Model 24xxx */
66
67static const char *pvr2_client_24xxx[] = {
68 "cx25840",
69 "tuner",
70 "wm8775",
71};
72
73static const char *pvr2_fw1_names_24xxx[] = {
74 "v4l-pvrusb2-24xxx-01.fw",
75};
76
77static const struct pvr2_device_desc pvr2_device_24xxx = {
78 .description = "WinTV PVR USB2 Model Category 24xxxx",
79 .shortname = "24xxx",
80 .client_modules.lst = pvr2_client_24xxx,
81 .client_modules.cnt = ARRAY_SIZE(pvr2_client_24xxx),
82 .fx2_firmware.lst = pvr2_fw1_names_24xxx,
83 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_24xxx),
84 .flag_has_cx25840 = !0,
85 .flag_has_wm8775 = !0,
86 .flag_has_hauppauge_rom = !0,
87 .flag_has_hauppauge_custom_ir = !0,
88 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
89};
90
91
92
93/*------------------------------------------------------------------------*/
94/* GOTVIEW USB2.0 DVD2 */
95
96static const char *pvr2_client_gotview_2[] = {
97 "cx25840",
98 "tuner",
99};
100
101static const struct pvr2_device_desc pvr2_device_gotview_2 = {
102 .description = "Gotview USB 2.0 DVD 2",
103 .shortname = "gv2",
104 .client_modules.lst = pvr2_client_gotview_2,
105 .client_modules.cnt = ARRAY_SIZE(pvr2_client_gotview_2),
106 .flag_has_cx25840 = !0,
107 .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
108 .signal_routing_scheme = PVR2_ROUTING_SCHEME_GOTVIEW,
109};
110
111
112
113#ifdef CONFIG_VIDEO_PVRUSB2_ONAIR_CREATOR
114/*------------------------------------------------------------------------*/
115/* OnAir Creator */
116
117static const char *pvr2_client_onair_creator[] = {
118 "saa7115",
119 "tuner",
120 "cs53l32a",
121};
122
123static const struct pvr2_device_desc pvr2_device_onair_creator = {
124 .description = "OnAir Creator Hybrid USB tuner",
125 .shortname = "oac",
126 .client_modules.lst = pvr2_client_onair_creator,
127 .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_creator),
128 .default_tuner_type = TUNER_LG_TDVS_H06XF,
129 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
130};
131#endif
132
133
134
135#ifdef CONFIG_VIDEO_PVRUSB2_ONAIR_USB2
136/*------------------------------------------------------------------------*/
137/* OnAir USB 2.0 */
138
139static const char *pvr2_client_onair_usb2[] = {
140 "saa7115",
141 "tuner",
142 "cs53l32a",
143};
144
145static const struct pvr2_device_desc pvr2_device_onair_usb2 = {
146 .description = "OnAir USB2 Hybrid USB tuner",
147 .shortname = "oa2",
148 .client_modules.lst = pvr2_client_onair_usb2,
149 .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_usb2),
150 .default_tuner_type = TUNER_PHILIPS_ATSC,
151 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
152};
153#endif
154
155
156
157/*------------------------------------------------------------------------*/
158/* Hauppauge PVR-USB2 Model 75xxx */
159
160static const char *pvr2_client_75xxx[] = {
161 "cx25840",
162 "tuner",
163};
164
165static const char *pvr2_fw1_names_75xxx[] = {
166 "v4l-pvrusb2-73xxx-01.fw",
167};
168
169static const struct pvr2_device_desc pvr2_device_75xxx = {
170 .description = "WinTV PVR USB2 Model Category 75xxxx",
171 .shortname = "75xxx",
172 .client_modules.lst = pvr2_client_75xxx,
173 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx),
174 .fx2_firmware.lst = pvr2_fw1_names_75xxx,
175 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx),
176 .flag_has_cx25840 = !0,
177 .flag_has_hauppauge_rom = !0,
178 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
179 .default_std_mask = V4L2_STD_NTSC_M,
180};
181
182
183
184/*------------------------------------------------------------------------*/
185
186struct usb_device_id pvr2_device_table[] = {
187 { USB_DEVICE(0x2040, 0x2900),
188 .driver_info = (kernel_ulong_t)&pvr2_device_29xxx},
189 { USB_DEVICE(0x2040, 0x2400),
190 .driver_info = (kernel_ulong_t)&pvr2_device_24xxx},
191 { USB_DEVICE(0x1164, 0x0622),
192 .driver_info = (kernel_ulong_t)&pvr2_device_gotview_2},
193#ifdef CONFIG_VIDEO_PVRUSB2_ONAIR_CREATOR
194 { USB_DEVICE(0x11ba, 0x1003),
195 .driver_info = (kernel_ulong_t)&pvr2_device_onair_creator},
196#endif
197#ifdef CONFIG_VIDEO_PVRUSB2_ONAIR_USB2
198 { USB_DEVICE(0x11ba, 0x1001),
199 .driver_info = (kernel_ulong_t)&pvr2_device_onair_usb2},
200#endif
201 { USB_DEVICE(0x2040, 0x7500),
202 .driver_info = (kernel_ulong_t)&pvr2_device_75xxx},
203 { }
204};
205
206MODULE_DEVICE_TABLE(usb, pvr2_device_table);
207
208
209/*
210 Stuff for Emacs to see, in order to encourage consistent editing style:
211 *** Local Variables: ***
212 *** mode: c ***
213 *** fill-column: 75 ***
214 *** tab-width: 8 ***
215 *** c-basic-offset: 8 ***
216 *** End: ***
217 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-devattr.h b/drivers/media/video/pvrusb2/pvrusb2-devattr.h
new file mode 100644
index 000000000000..64b467f0637f
--- /dev/null
+++ b/drivers/media/video/pvrusb2/pvrusb2-devattr.h
@@ -0,0 +1,119 @@
1/*
2 *
3 * $Id$
4 *
5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21#ifndef __PVRUSB2_DEVATTR_H
22#define __PVRUSB2_DEVATTR_H
23
24#include <linux/mod_devicetable.h>
25#include <linux/videodev2.h>
26
27/*
28
29 This header defines structures used to describe attributes of a device.
30
31*/
32
33
34struct pvr2_string_table {
35 const char **lst;
36 unsigned int cnt;
37};
38
39#define PVR2_ROUTING_SCHEME_HAUPPAUGE 0
40#define PVR2_ROUTING_SCHEME_GOTVIEW 1
41
42/* This describes a particular hardware type (except for the USB device ID
43 which must live in a separate structure due to environmental
44 constraints). See the top of pvrusb2-hdw.c for where this is
45 instantiated. */
46struct pvr2_device_desc {
47 /* Single line text description of hardware */
48 const char *description;
49
50 /* Single token identifier for hardware */
51 const char *shortname;
52
53 /* List of additional client modules we need to load */
54 struct pvr2_string_table client_modules;
55
56 /* List of FX2 firmware file names we should search; if empty then
57 FX2 firmware check / load is skipped and we assume the device
58 was initialized from internal ROM. */
59 struct pvr2_string_table fx2_firmware;
60
61 /* Signal routing scheme used by device, contains one of
62 PVR2_ROUTING_SCHEME_XXX. Schemes have to be defined as we
63 encounter them. This is an arbitrary integer scheme id; its
64 meaning is contained entirely within the driver and is
65 interpreted by logic which must send commands to the chip-level
66 drivers (search for things which touch this field). */
67 unsigned int signal_routing_scheme;
68
69 /* V4L tuner type ID to use with this device (only used if the
70 driver could not discover the type any other way). */
71 int default_tuner_type;
72
73 /* Initial standard bits to use for this device, if not zero.
74 Anything set here is also implied as an available standard.
75 Note: This is ignored if overridden on the module load line via
76 the video_std module option. */
77 v4l2_std_id default_std_mask;
78
79 /* If set, we don't bother trying to load cx23416 firmware. */
80 char flag_skip_cx23416_firmware;
81
82 /* Device has a hauppauge eeprom which we can interrogate. */
83 char flag_has_hauppauge_rom;
84
85 /* Device does not require a powerup command to be issued. */
86 char flag_no_powerup;
87
88 /* Device has a cx25840 - this enables special additional logic to
89 handle it. */
90 char flag_has_cx25840;
91
92 /* Device has a wm8775 - this enables special additional logic to
93 ensure that it is found. */
94 char flag_has_wm8775;
95
96 /* Device has IR hardware that can be faked into looking like a
97 normal Hauppauge i2c IR receiver. This is currently very
98 specific to the 24xxx device, where Hauppauge had replaced their
99 'standard' I2C IR receiver with a bunch of FPGA logic controlled
100 directly via the FX2. Turning this on tells the pvrusb2 driver
101 to virtualize the presence of the non-existant IR receiver chip and
102 implement the virtual receiver in terms of appropriate FX2
103 commands. */
104 char flag_has_hauppauge_custom_ir;
105};
106
107extern struct usb_device_id pvr2_device_table[];
108
109#endif /* __PVRUSB2_HDW_INTERNAL_H */
110
111/*
112 Stuff for Emacs to see, in order to encourage consistent editing style:
113 *** Local Variables: ***
114 *** mode: c ***
115 *** fill-column: 75 ***
116 *** tab-width: 8 ***
117 *** c-basic-offset: 8 ***
118 *** End: ***
119 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
index 45cbca0143ca..5ef005947b04 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
@@ -144,6 +144,7 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
144 trace_eeprom("serial_number=%d",tvdata.serial_number); 144 trace_eeprom("serial_number=%d",tvdata.serial_number);
145 trace_eeprom("rev_str=%s",tvdata.rev_str); 145 trace_eeprom("rev_str=%s",tvdata.rev_str);
146 hdw->tuner_type = tvdata.tuner_type; 146 hdw->tuner_type = tvdata.tuner_type;
147 hdw->tuner_updated = !0;
147 hdw->serial_number = tvdata.serial_number; 148 hdw->serial_number = tvdata.serial_number;
148 hdw->std_mask_eeprom = tvdata.tuner_formats; 149 hdw->std_mask_eeprom = tvdata.tuner_formats;
149 150
diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
index 205087a3e136..64062879981e 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
@@ -140,7 +140,7 @@ static int pvr2_encoder_read_words(struct pvr2_hdw *hdw,
140 cx2341x.ko to write to our encoder (by handing it a pointer to this 140 cx2341x.ko to write to our encoder (by handing it a pointer to this
141 function). For earlier kernels this doesn't really matter. */ 141 function). For earlier kernels this doesn't really matter. */
142static int pvr2_encoder_cmd(void *ctxt, 142static int pvr2_encoder_cmd(void *ctxt,
143 int cmd, 143 u32 cmd,
144 int arg_cnt_send, 144 int arg_cnt_send,
145 int arg_cnt_recv, 145 int arg_cnt_recv,
146 u32 *argp) 146 u32 *argp)
@@ -209,7 +209,7 @@ static int pvr2_encoder_cmd(void *ctxt,
209 209
210 LOCK_TAKE(hdw->ctl_lock); do { 210 LOCK_TAKE(hdw->ctl_lock); do {
211 211
212 if (!hdw->flag_encoder_ok) { 212 if (!hdw->state_encoder_ok) {
213 ret = -EIO; 213 ret = -EIO;
214 break; 214 break;
215 } 215 }
@@ -278,12 +278,15 @@ static int pvr2_encoder_cmd(void *ctxt,
278 ret = -EBUSY; 278 ret = -EBUSY;
279 } 279 }
280 if (ret) { 280 if (ret) {
281 hdw->flag_encoder_ok = 0; 281 hdw->state_encoder_ok = 0;
282 pvr2_trace(PVR2_TRACE_STBITS,
283 "State bit %s <-- %s",
284 "state_encoder_ok",
285 (hdw->state_encoder_ok ? "true" : "false"));
282 pvr2_trace( 286 pvr2_trace(
283 PVR2_TRACE_ERROR_LEGS, 287 PVR2_TRACE_ERROR_LEGS,
284 "Giving up on command." 288 "Giving up on command."
285 " It is likely that" 289 " This is normally recovered by the driver.");
286 " this is a bad idea...");
287 break; 290 break;
288 } 291 }
289 wrData[0] = 0x7; 292 wrData[0] = 0x7;
@@ -366,13 +369,13 @@ static int pvr2_encoder_prep_config(struct pvr2_hdw *hdw)
366 369
367 /* This ENC_MISC(3,encMisc3Arg) command is critical - without 370 /* This ENC_MISC(3,encMisc3Arg) command is critical - without
368 it there will eventually be video corruption. Also, the 371 it there will eventually be video corruption. Also, the
369 29xxx case is strange - the Windows driver is passing 1 372 saa7115 case is strange - the Windows driver is passing 1
370 regardless of device type but if we have 1 for 29xxx device 373 regardless of device type but if we have 1 for saa7115
371 the video turns sluggish. */ 374 devices the video turns sluggish. */
372 switch (hdw->hdw_type) { 375 if (hdw->hdw_desc->flag_has_cx25840) {
373 case PVR2_HDW_TYPE_24XXX: encMisc3Arg = 1; break; 376 encMisc3Arg = 1;
374 case PVR2_HDW_TYPE_29XXX: encMisc3Arg = 0; break; 377 } else {
375 default: break; 378 encMisc3Arg = 0;
376 } 379 }
377 ret |= pvr2_encoder_vcmd(hdw, CX2341X_ENC_MISC,4, 3, 380 ret |= pvr2_encoder_vcmd(hdw, CX2341X_ENC_MISC,4, 3,
378 encMisc3Arg,0,0); 381 encMisc3Arg,0,0);
@@ -394,6 +397,24 @@ static int pvr2_encoder_prep_config(struct pvr2_hdw *hdw)
394 return ret; 397 return ret;
395} 398}
396 399
400int pvr2_encoder_adjust(struct pvr2_hdw *hdw)
401{
402 int ret;
403 ret = cx2341x_update(hdw,pvr2_encoder_cmd,
404 (hdw->enc_cur_valid ? &hdw->enc_cur_state : NULL),
405 &hdw->enc_ctl_state);
406 if (ret) {
407 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
408 "Error from cx2341x module code=%d",ret);
409 } else {
410 memcpy(&hdw->enc_cur_state,&hdw->enc_ctl_state,
411 sizeof(struct cx2341x_mpeg_params));
412 hdw->enc_cur_valid = !0;
413 }
414 return ret;
415}
416
417
397int pvr2_encoder_configure(struct pvr2_hdw *hdw) 418int pvr2_encoder_configure(struct pvr2_hdw *hdw)
398{ 419{
399 int ret; 420 int ret;
@@ -412,7 +433,7 @@ int pvr2_encoder_configure(struct pvr2_hdw *hdw)
412 433
413 /* saa7115: 0xf0 */ 434 /* saa7115: 0xf0 */
414 val = 0xf0; 435 val = 0xf0;
415 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) { 436 if (hdw->hdw_desc->flag_has_cx25840) {
416 /* ivtv cx25840: 0x140 */ 437 /* ivtv cx25840: 0x140 */
417 val = 0x140; 438 val = 0x140;
418 } 439 }
@@ -436,18 +457,10 @@ int pvr2_encoder_configure(struct pvr2_hdw *hdw)
436 return ret; 457 return ret;
437 } 458 }
438 459
439 ret = cx2341x_update(hdw,pvr2_encoder_cmd, 460 ret = pvr2_encoder_adjust(hdw);
440 (hdw->enc_cur_valid ? &hdw->enc_cur_state : NULL), 461 if (ret) return ret;
441 &hdw->enc_ctl_state);
442 if (ret) {
443 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
444 "Error from cx2341x module code=%d",ret);
445 return ret;
446 }
447
448 ret = 0;
449 462
450 if (!ret) ret = pvr2_encoder_vcmd( 463 ret = pvr2_encoder_vcmd(
451 hdw, CX2341X_ENC_INITIALIZE_INPUT, 0); 464 hdw, CX2341X_ENC_INITIALIZE_INPUT, 0);
452 465
453 if (ret) { 466 if (ret) {
@@ -456,10 +469,6 @@ int pvr2_encoder_configure(struct pvr2_hdw *hdw)
456 return ret; 469 return ret;
457 } 470 }
458 471
459 hdw->subsys_enabled_mask |= (1<<PVR2_SUBSYS_B_ENC_CFG);
460 memcpy(&hdw->enc_cur_state,&hdw->enc_ctl_state,
461 sizeof(struct cx2341x_mpeg_params));
462 hdw->enc_cur_valid = !0;
463 return 0; 472 return 0;
464} 473}
465 474
@@ -478,7 +487,7 @@ int pvr2_encoder_start(struct pvr2_hdw *hdw)
478 pvr2_encoder_vcmd(hdw,CX2341X_ENC_MUTE_VIDEO,1, 487 pvr2_encoder_vcmd(hdw,CX2341X_ENC_MUTE_VIDEO,1,
479 hdw->input_val == PVR2_CVAL_INPUT_RADIO ? 1 : 0); 488 hdw->input_val == PVR2_CVAL_INPUT_RADIO ? 1 : 0);
480 489
481 switch (hdw->config) { 490 switch (hdw->active_stream_type) {
482 case pvr2_config_vbi: 491 case pvr2_config_vbi:
483 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_START_CAPTURE,2, 492 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_START_CAPTURE,2,
484 0x01,0x14); 493 0x01,0x14);
@@ -492,9 +501,6 @@ int pvr2_encoder_start(struct pvr2_hdw *hdw)
492 0,0x13); 501 0,0x13);
493 break; 502 break;
494 } 503 }
495 if (!status) {
496 hdw->subsys_enabled_mask |= (1<<PVR2_SUBSYS_B_ENC_RUN);
497 }
498 return status; 504 return status;
499} 505}
500 506
@@ -505,7 +511,7 @@ int pvr2_encoder_stop(struct pvr2_hdw *hdw)
505 /* mask all interrupts */ 511 /* mask all interrupts */
506 pvr2_write_register(hdw, 0x0048, 0xffffffff); 512 pvr2_write_register(hdw, 0x0048, 0xffffffff);
507 513
508 switch (hdw->config) { 514 switch (hdw->active_stream_type) {
509 case pvr2_config_vbi: 515 case pvr2_config_vbi:
510 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_STOP_CAPTURE,3, 516 status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_STOP_CAPTURE,3,
511 0x01,0x01,0x14); 517 0x01,0x01,0x14);
@@ -526,9 +532,6 @@ int pvr2_encoder_stop(struct pvr2_hdw *hdw)
526 pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000401); 532 pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000401);
527 pvr2_hdw_gpio_chg_out(hdw,0xffffffff,0x00000000); 533 pvr2_hdw_gpio_chg_out(hdw,0xffffffff,0x00000000);
528 534
529 if (!status) {
530 hdw->subsys_enabled_mask &= ~(1<<PVR2_SUBSYS_B_ENC_RUN);
531 }
532 return status; 535 return status;
533} 536}
534 537
diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.h b/drivers/media/video/pvrusb2/pvrusb2-encoder.h
index 01b5a0b89c03..54caf2e3c428 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-encoder.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.h
@@ -25,6 +25,7 @@
25 25
26struct pvr2_hdw; 26struct pvr2_hdw;
27 27
28int pvr2_encoder_adjust(struct pvr2_hdw *);
28int pvr2_encoder_configure(struct pvr2_hdw *); 29int pvr2_encoder_configure(struct pvr2_hdw *);
29int pvr2_encoder_start(struct pvr2_hdw *); 30int pvr2_encoder_start(struct pvr2_hdw *);
30int pvr2_encoder_stop(struct pvr2_hdw *); 31int pvr2_encoder_stop(struct pvr2_hdw *);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index f873994b088c..d7a216b41b72 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -35,10 +35,12 @@
35 35
36#include <linux/videodev2.h> 36#include <linux/videodev2.h>
37#include <linux/i2c.h> 37#include <linux/i2c.h>
38#include <linux/workqueue.h>
38#include <linux/mutex.h> 39#include <linux/mutex.h>
39#include "pvrusb2-hdw.h" 40#include "pvrusb2-hdw.h"
40#include "pvrusb2-io.h" 41#include "pvrusb2-io.h"
41#include <media/cx2341x.h> 42#include <media/cx2341x.h>
43#include "pvrusb2-devattr.h"
42 44
43/* Legal values for PVR2_CID_HSM */ 45/* Legal values for PVR2_CID_HSM */
44#define PVR2_CVAL_HSM_FAIL 0 46#define PVR2_CVAL_HSM_FAIL 0
@@ -161,10 +163,6 @@ struct pvr2_decoder_ctrl {
161#define FW1_STATE_RELOAD 3 163#define FW1_STATE_RELOAD 3
162#define FW1_STATE_OK 4 164#define FW1_STATE_OK 4
163 165
164/* Known major hardware variants, keyed from device ID */
165#define PVR2_HDW_TYPE_29XXX 0
166#define PVR2_HDW_TYPE_24XXX 1
167
168typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16); 166typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16);
169#define PVR2_I2C_FUNC_CNT 128 167#define PVR2_I2C_FUNC_CNT 128
170 168
@@ -176,8 +174,15 @@ struct pvr2_hdw {
176 struct usb_device *usb_dev; 174 struct usb_device *usb_dev;
177 struct usb_interface *usb_intf; 175 struct usb_interface *usb_intf;
178 176
179 /* Device type, one of PVR2_HDW_TYPE_xxxxx */ 177 /* Device description, anything that must adjust behavior based on
180 unsigned int hdw_type; 178 device specific info will use information held here. */
179 const struct pvr2_device_desc *hdw_desc;
180
181 /* Kernel worker thread handling */
182 struct workqueue_struct *workqueue;
183 struct work_struct workpoll; /* Update driver state */
184 struct work_struct worki2csync; /* Update i2c clients */
185 struct work_struct workinit; /* Driver initialization sequence */
181 186
182 /* Video spigot */ 187 /* Video spigot */
183 struct pvr2_stream *vid_stream; 188 struct pvr2_stream *vid_stream;
@@ -186,9 +191,6 @@ struct pvr2_hdw {
186 struct mutex big_lock_mutex; 191 struct mutex big_lock_mutex;
187 int big_lock_held; /* For debugging */ 192 int big_lock_held; /* For debugging */
188 193
189 void (*poll_trigger_func)(void *);
190 void *poll_trigger_data;
191
192 char name[32]; 194 char name[32];
193 195
194 /* I2C stuff */ 196 /* I2C stuff */
@@ -215,9 +217,9 @@ struct pvr2_hdw {
215 struct urb *ctl_read_urb; 217 struct urb *ctl_read_urb;
216 unsigned char *ctl_write_buffer; 218 unsigned char *ctl_write_buffer;
217 unsigned char *ctl_read_buffer; 219 unsigned char *ctl_read_buffer;
218 volatile int ctl_write_pend_flag; 220 int ctl_write_pend_flag;
219 volatile int ctl_read_pend_flag; 221 int ctl_read_pend_flag;
220 volatile int ctl_timeout_flag; 222 int ctl_timeout_flag;
221 struct completion ctl_done; 223 struct completion ctl_done;
222 unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE]; 224 unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE];
223 int cmd_debug_state; // Low level command debugging info 225 int cmd_debug_state; // Low level command debugging info
@@ -225,14 +227,48 @@ struct pvr2_hdw {
225 unsigned int cmd_debug_write_len; // 227 unsigned int cmd_debug_write_len; //
226 unsigned int cmd_debug_read_len; // 228 unsigned int cmd_debug_read_len; //
227 229
230 /* Bits of state that describe what is going on with various parts
231 of the driver. */
232 int state_encoder_ok; /* Encoder is operational */
233 int state_encoder_run; /* Encoder is running */
234 int state_encoder_config; /* Encoder is configured */
235 int state_encoder_waitok; /* Encoder pre-wait done */
236 int state_decoder_run; /* Decoder is running */
237 int state_usbstream_run; /* FX2 is streaming */
238 int state_decoder_quiescent; /* Decoder idle for > 50msec */
239 int state_pipeline_config; /* Pipeline is configured */
240 int state_pipeline_req; /* Somebody wants to stream */
241 int state_pipeline_pause; /* Pipeline must be paused */
242 int state_pipeline_idle; /* Pipeline not running */
243
244 /* This is the master state of the driver. It is the combined
245 result of other bits of state. Examining this will indicate the
246 overall state of the driver. Values here are one of
247 PVR2_STATE_xxxx */
248 unsigned int master_state;
249
250 /* True if states must be re-evaluated */
251 int state_stale;
252
253 void (*state_func)(void *);
254 void *state_data;
255
256 /* Timer for measuring decoder settling time */
257 struct timer_list quiescent_timer;
258
259 /* Timer for measuring encoder pre-wait time */
260 struct timer_list encoder_wait_timer;
261
262 /* Place to block while waiting for state changes */
263 wait_queue_head_t state_wait_data;
264
265
228 int flag_ok; /* device in known good state */ 266 int flag_ok; /* device in known good state */
229 int flag_disconnected; /* flag_ok == 0 due to disconnect */ 267 int flag_disconnected; /* flag_ok == 0 due to disconnect */
230 int flag_init_ok; /* true if structure is fully initialized */ 268 int flag_init_ok; /* true if structure is fully initialized */
231 int flag_streaming_enabled; /* true if streaming should be on */
232 int fw1_state; /* current situation with fw1 */ 269 int fw1_state; /* current situation with fw1 */
233 int flag_encoder_ok; /* True if encoder is healthy */ 270 int flag_decoder_missed;/* We've noticed missing decoder */
234 271 int flag_tripped; /* Indicates overall failure to start */
235 int flag_decoder_is_tuned;
236 272
237 struct pvr2_decoder_ctrl *decoder_ctrl; 273 struct pvr2_decoder_ctrl *decoder_ctrl;
238 274
@@ -241,12 +277,6 @@ struct pvr2_hdw {
241 unsigned int fw_size; 277 unsigned int fw_size;
242 int fw_cpu_flag; /* True if we are dealing with the CPU */ 278 int fw_cpu_flag; /* True if we are dealing with the CPU */
243 279
244 // Which subsystem pieces have been enabled / configured
245 unsigned long subsys_enabled_mask;
246
247 // Which subsystems are manipulated to enable streaming
248 unsigned long subsys_stream_mask;
249
250 // True if there is a request to trigger logging of state in each 280 // True if there is a request to trigger logging of state in each
251 // module. 281 // module.
252 int log_requested; 282 int log_requested;
@@ -296,13 +326,16 @@ struct pvr2_hdw {
296 /* Location of eeprom or a negative number if none */ 326 /* Location of eeprom or a negative number if none */
297 int eeprom_addr; 327 int eeprom_addr;
298 328
299 enum pvr2_config config; 329 enum pvr2_config active_stream_type;
330 enum pvr2_config desired_stream_type;
300 331
301 /* Control state needed for cx2341x module */ 332 /* Control state needed for cx2341x module */
302 struct cx2341x_mpeg_params enc_cur_state; 333 struct cx2341x_mpeg_params enc_cur_state;
303 struct cx2341x_mpeg_params enc_ctl_state; 334 struct cx2341x_mpeg_params enc_ctl_state;
304 /* True if an encoder attribute has changed */ 335 /* True if an encoder attribute has changed */
305 int enc_stale; 336 int enc_stale;
337 /* True if an unsafe encoder attribute has changed */
338 int enc_unsafe_stale;
306 /* True if enc_cur_state is valid */ 339 /* True if enc_cur_state is valid */
307 int enc_cur_valid; 340 int enc_cur_valid;
308 341
@@ -332,6 +365,7 @@ struct pvr2_hdw {
332 365
333/* This function gets the current frequency */ 366/* This function gets the current frequency */
334unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *); 367unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
368void pvr2_hdw_set_decoder(struct pvr2_hdw *,struct pvr2_decoder_ctrl *);
335 369
336#endif /* __PVRUSB2_HDW_INTERNAL_H */ 370#endif /* __PVRUSB2_HDW_INTERNAL_H */
337 371
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index 402c59488253..41ae980405ed 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -41,47 +41,6 @@
41#define TV_MIN_FREQ 55250000L 41#define TV_MIN_FREQ 55250000L
42#define TV_MAX_FREQ 850000000L 42#define TV_MAX_FREQ 850000000L
43 43
44struct usb_device_id pvr2_device_table[] = {
45 [PVR2_HDW_TYPE_29XXX] = { USB_DEVICE(0x2040, 0x2900) },
46 [PVR2_HDW_TYPE_24XXX] = { USB_DEVICE(0x2040, 0x2400) },
47 { }
48};
49
50MODULE_DEVICE_TABLE(usb, pvr2_device_table);
51
52static const char *pvr2_device_names[] = {
53 [PVR2_HDW_TYPE_29XXX] = "WinTV PVR USB2 Model Category 29xxxx",
54 [PVR2_HDW_TYPE_24XXX] = "WinTV PVR USB2 Model Category 24xxxx",
55};
56
57struct pvr2_string_table {
58 const char **lst;
59 unsigned int cnt;
60};
61
62// Names of other client modules to request for 24xxx model hardware
63static const char *pvr2_client_24xxx[] = {
64 "cx25840",
65 "tuner",
66 "wm8775",
67};
68
69// Names of other client modules to request for 29xxx model hardware
70static const char *pvr2_client_29xxx[] = {
71 "msp3400",
72 "saa7115",
73 "tuner",
74};
75
76static struct pvr2_string_table pvr2_client_lists[] = {
77 [PVR2_HDW_TYPE_29XXX] = {
78 pvr2_client_29xxx, ARRAY_SIZE(pvr2_client_29xxx)
79 },
80 [PVR2_HDW_TYPE_24XXX] = {
81 pvr2_client_24xxx, ARRAY_SIZE(pvr2_client_24xxx)
82 },
83};
84
85static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL}; 44static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL};
86static DEFINE_MUTEX(pvr2_unit_mtx); 45static DEFINE_MUTEX(pvr2_unit_mtx);
87 46
@@ -246,32 +205,46 @@ static const char *control_values_hsm[] = {
246}; 205};
247 206
248 207
249static const char *control_values_subsystem[] = { 208static const char *pvr2_state_names[] = {
250 [PVR2_SUBSYS_B_ENC_FIRMWARE] = "enc_firmware", 209 [PVR2_STATE_NONE] = "none",
251 [PVR2_SUBSYS_B_ENC_CFG] = "enc_config", 210 [PVR2_STATE_DEAD] = "dead",
252 [PVR2_SUBSYS_B_DIGITIZER_RUN] = "digitizer_run", 211 [PVR2_STATE_COLD] = "cold",
253 [PVR2_SUBSYS_B_USBSTREAM_RUN] = "usbstream_run", 212 [PVR2_STATE_WARM] = "warm",
254 [PVR2_SUBSYS_B_ENC_RUN] = "enc_run", 213 [PVR2_STATE_ERROR] = "error",
214 [PVR2_STATE_READY] = "ready",
215 [PVR2_STATE_RUN] = "run",
255}; 216};
256 217
218
219static void pvr2_hdw_state_sched(struct pvr2_hdw *);
220static int pvr2_hdw_state_eval(struct pvr2_hdw *);
257static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long); 221static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long);
222static void pvr2_hdw_worker_i2c(struct work_struct *work);
223static void pvr2_hdw_worker_poll(struct work_struct *work);
224static void pvr2_hdw_worker_init(struct work_struct *work);
225static int pvr2_hdw_wait(struct pvr2_hdw *,int state);
226static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *);
227static void pvr2_hdw_state_log_state(struct pvr2_hdw *);
258static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl); 228static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl);
259static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw); 229static int pvr2_hdw_commit_setup(struct pvr2_hdw *hdw);
260static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw); 230static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw);
261static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw); 231static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw);
262static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw); 232static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw);
263static void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *hdw); 233static void pvr2_hdw_quiescent_timeout(unsigned long);
264static void pvr2_hdw_subsys_bit_chg_no_lock(struct pvr2_hdw *hdw, 234static void pvr2_hdw_encoder_wait_timeout(unsigned long);
265 unsigned long msk,
266 unsigned long val);
267static void pvr2_hdw_subsys_stream_bit_chg_no_lock(struct pvr2_hdw *hdw,
268 unsigned long msk,
269 unsigned long val);
270static int pvr2_send_request_ex(struct pvr2_hdw *hdw, 235static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
271 unsigned int timeout,int probe_fl, 236 unsigned int timeout,int probe_fl,
272 void *write_data,unsigned int write_len, 237 void *write_data,unsigned int write_len,
273 void *read_data,unsigned int read_len); 238 void *read_data,unsigned int read_len);
274 239
240
241static void trace_stbit(const char *name,int val)
242{
243 pvr2_trace(PVR2_TRACE_STBITS,
244 "State bit %s <-- %s",
245 name,(val ? "true" : "false"));
246}
247
275static int ctrl_channelfreq_get(struct pvr2_ctrl *cptr,int *vp) 248static int ctrl_channelfreq_get(struct pvr2_ctrl *cptr,int *vp)
276{ 249{
277 struct pvr2_hdw *hdw = cptr->hdw; 250 struct pvr2_hdw *hdw = cptr->hdw;
@@ -380,8 +353,8 @@ static int ctrl_vres_max_get(struct pvr2_ctrl *cptr,int *vp)
380 353
381static int ctrl_vres_min_get(struct pvr2_ctrl *cptr,int *vp) 354static int ctrl_vres_min_get(struct pvr2_ctrl *cptr,int *vp)
382{ 355{
383 /* Actual minimum depends on device type. */ 356 /* Actual minimum depends on device digitizer type. */
384 if (cptr->hdw->hdw_type == PVR2_HDW_TYPE_24XXX) { 357 if (cptr->hdw->hdw_desc->flag_has_cx25840) {
385 *vp = 75; 358 *vp = 75;
386 } else { 359 } else {
387 *vp = 17; 360 *vp = 17;
@@ -480,6 +453,7 @@ static int ctrl_cx2341x_is_dirty(struct pvr2_ctrl *cptr)
480static void ctrl_cx2341x_clear_dirty(struct pvr2_ctrl *cptr) 453static void ctrl_cx2341x_clear_dirty(struct pvr2_ctrl *cptr)
481{ 454{
482 cptr->hdw->enc_stale = 0; 455 cptr->hdw->enc_stale = 0;
456 cptr->hdw->enc_unsafe_stale = 0;
483} 457}
484 458
485static int ctrl_cx2341x_get(struct pvr2_ctrl *cptr,int *vp) 459static int ctrl_cx2341x_get(struct pvr2_ctrl *cptr,int *vp)
@@ -502,6 +476,7 @@ static int ctrl_cx2341x_get(struct pvr2_ctrl *cptr,int *vp)
502static int ctrl_cx2341x_set(struct pvr2_ctrl *cptr,int m,int v) 476static int ctrl_cx2341x_set(struct pvr2_ctrl *cptr,int m,int v)
503{ 477{
504 int ret; 478 int ret;
479 struct pvr2_hdw *hdw = cptr->hdw;
505 struct v4l2_ext_controls cs; 480 struct v4l2_ext_controls cs;
506 struct v4l2_ext_control c1; 481 struct v4l2_ext_control c1;
507 memset(&cs,0,sizeof(cs)); 482 memset(&cs,0,sizeof(cs));
@@ -510,10 +485,22 @@ static int ctrl_cx2341x_set(struct pvr2_ctrl *cptr,int m,int v)
510 cs.count = 1; 485 cs.count = 1;
511 c1.id = cptr->info->v4l_id; 486 c1.id = cptr->info->v4l_id;
512 c1.value = v; 487 c1.value = v;
513 ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state, 0, &cs, 488 ret = cx2341x_ext_ctrls(&hdw->enc_ctl_state,
489 hdw->state_encoder_run, &cs,
514 VIDIOC_S_EXT_CTRLS); 490 VIDIOC_S_EXT_CTRLS);
491 if (ret == -EBUSY) {
492 /* Oops. cx2341x is telling us it's not safe to change
493 this control while we're capturing. Make a note of this
494 fact so that the pipeline will be stopped the next time
495 controls are committed. Then go on ahead and store this
496 change anyway. */
497 ret = cx2341x_ext_ctrls(&hdw->enc_ctl_state,
498 0, &cs,
499 VIDIOC_S_EXT_CTRLS);
500 if (!ret) hdw->enc_unsafe_stale = !0;
501 }
515 if (ret) return ret; 502 if (ret) return ret;
516 cptr->hdw->enc_stale = !0; 503 hdw->enc_stale = !0;
517 return 0; 504 return 0;
518} 505}
519 506
@@ -544,7 +531,13 @@ static unsigned int ctrl_cx2341x_getv4lflags(struct pvr2_ctrl *cptr)
544 531
545static int ctrl_streamingenabled_get(struct pvr2_ctrl *cptr,int *vp) 532static int ctrl_streamingenabled_get(struct pvr2_ctrl *cptr,int *vp)
546{ 533{
547 *vp = cptr->hdw->flag_streaming_enabled; 534 *vp = cptr->hdw->state_pipeline_req;
535 return 0;
536}
537
538static int ctrl_masterstate_get(struct pvr2_ctrl *cptr,int *vp)
539{
540 *vp = cptr->hdw->master_state;
548 return 0; 541 return 0;
549} 542}
550 543
@@ -657,29 +650,6 @@ static int ctrl_audio_modes_present_get(struct pvr2_ctrl *cptr,int *vp)
657 return 0; 650 return 0;
658} 651}
659 652
660static int ctrl_subsys_get(struct pvr2_ctrl *cptr,int *vp)
661{
662 *vp = cptr->hdw->subsys_enabled_mask;
663 return 0;
664}
665
666static int ctrl_subsys_set(struct pvr2_ctrl *cptr,int m,int v)
667{
668 pvr2_hdw_subsys_bit_chg_no_lock(cptr->hdw,m,v);
669 return 0;
670}
671
672static int ctrl_subsys_stream_get(struct pvr2_ctrl *cptr,int *vp)
673{
674 *vp = cptr->hdw->subsys_stream_mask;
675 return 0;
676}
677
678static int ctrl_subsys_stream_set(struct pvr2_ctrl *cptr,int m,int v)
679{
680 pvr2_hdw_subsys_stream_bit_chg_no_lock(cptr->hdw,m,v);
681 return 0;
682}
683 653
684static int ctrl_stdenumcur_set(struct pvr2_ctrl *cptr,int m,int v) 654static int ctrl_stdenumcur_set(struct pvr2_ctrl *cptr,int m,int v)
685{ 655{
@@ -915,6 +885,11 @@ static const struct pvr2_ctl_info control_defs[] = {
915 .get_value = ctrl_hsm_get, 885 .get_value = ctrl_hsm_get,
916 DEFENUM(control_values_hsm), 886 DEFENUM(control_values_hsm),
917 },{ 887 },{
888 .desc = "Master State",
889 .name = "master_state",
890 .get_value = ctrl_masterstate_get,
891 DEFENUM(pvr2_state_names),
892 },{
918 .desc = "Signal Present", 893 .desc = "Signal Present",
919 .name = "signal_present", 894 .name = "signal_present",
920 .get_value = ctrl_signal_get, 895 .get_value = ctrl_signal_get,
@@ -955,20 +930,6 @@ static const struct pvr2_ctl_info control_defs[] = {
955 .sym_to_val = ctrl_std_sym_to_val, 930 .sym_to_val = ctrl_std_sym_to_val,
956 .type = pvr2_ctl_bitmask, 931 .type = pvr2_ctl_bitmask,
957 },{ 932 },{
958 .desc = "Subsystem enabled mask",
959 .name = "debug_subsys_mask",
960 .skip_init = !0,
961 .get_value = ctrl_subsys_get,
962 .set_value = ctrl_subsys_set,
963 DEFMASK(PVR2_SUBSYS_ALL,control_values_subsystem),
964 },{
965 .desc = "Subsystem stream mask",
966 .name = "debug_subsys_stream_mask",
967 .skip_init = !0,
968 .get_value = ctrl_subsys_stream_get,
969 .set_value = ctrl_subsys_stream_set,
970 DEFMASK(PVR2_SUBSYS_ALL,control_values_subsystem),
971 },{
972 .desc = "Video Standard Name", 933 .desc = "Video Standard Name",
973 .name = "video_standard", 934 .name = "video_standard",
974 .internal_id = PVR2_CID_STDENUM, 935 .internal_id = PVR2_CID_STDENUM,
@@ -1129,25 +1090,13 @@ static int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
1129 unsigned int pipe; 1090 unsigned int pipe;
1130 int ret; 1091 int ret;
1131 u16 address; 1092 u16 address;
1132 static const char *fw_files_29xxx[] = {
1133 "v4l-pvrusb2-29xxx-01.fw",
1134 };
1135 static const char *fw_files_24xxx[] = {
1136 "v4l-pvrusb2-24xxx-01.fw",
1137 };
1138 static const struct pvr2_string_table fw_file_defs[] = {
1139 [PVR2_HDW_TYPE_29XXX] = {
1140 fw_files_29xxx, ARRAY_SIZE(fw_files_29xxx)
1141 },
1142 [PVR2_HDW_TYPE_24XXX] = {
1143 fw_files_24xxx, ARRAY_SIZE(fw_files_24xxx)
1144 },
1145 };
1146 1093
1147 if ((hdw->hdw_type >= ARRAY_SIZE(fw_file_defs)) || 1094 if (!hdw->hdw_desc->fx2_firmware.cnt) {
1148 (!fw_file_defs[hdw->hdw_type].lst)) {
1149 hdw->fw1_state = FW1_STATE_OK; 1095 hdw->fw1_state = FW1_STATE_OK;
1150 return 0; 1096 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1097 "Connected device type defines"
1098 " no firmware to upload; ignoring firmware");
1099 return -ENOTTY;
1151 } 1100 }
1152 1101
1153 hdw->fw1_state = FW1_STATE_FAILED; // default result 1102 hdw->fw1_state = FW1_STATE_FAILED; // default result
@@ -1155,8 +1104,8 @@ static int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
1155 trace_firmware("pvr2_upload_firmware1"); 1104 trace_firmware("pvr2_upload_firmware1");
1156 1105
1157 ret = pvr2_locate_firmware(hdw,&fw_entry,"fx2 controller", 1106 ret = pvr2_locate_firmware(hdw,&fw_entry,"fx2 controller",
1158 fw_file_defs[hdw->hdw_type].cnt, 1107 hdw->hdw_desc->fx2_firmware.cnt,
1159 fw_file_defs[hdw->hdw_type].lst); 1108 hdw->hdw_desc->fx2_firmware.lst);
1160 if (ret < 0) { 1109 if (ret < 0) {
1161 if (ret == -ENOENT) hdw->fw1_state = FW1_STATE_MISSING; 1110 if (ret == -ENOENT) hdw->fw1_state = FW1_STATE_MISSING;
1162 return ret; 1111 return ret;
@@ -1231,8 +1180,7 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1231 CX2341X_FIRM_ENC_FILENAME, 1180 CX2341X_FIRM_ENC_FILENAME,
1232 }; 1181 };
1233 1182
1234 if ((hdw->hdw_type != PVR2_HDW_TYPE_29XXX) && 1183 if (hdw->hdw_desc->flag_skip_cx23416_firmware) {
1235 (hdw->hdw_type != PVR2_HDW_TYPE_24XXX)) {
1236 return 0; 1184 return 0;
1237 } 1185 }
1238 1186
@@ -1248,8 +1196,6 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1248 time we configure the encoder, then we'll fully configure it. */ 1196 time we configure the encoder, then we'll fully configure it. */
1249 hdw->enc_cur_valid = 0; 1197 hdw->enc_cur_valid = 0;
1250 1198
1251 hdw->flag_encoder_ok = 0;
1252
1253 /* First prepare firmware loading */ 1199 /* First prepare firmware loading */
1254 ret |= pvr2_write_register(hdw, 0x0048, 0xffffffff); /*interrupt mask*/ 1200 ret |= pvr2_write_register(hdw, 0x0048, 0xffffffff); /*interrupt mask*/
1255 ret |= pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000088); /*gpio dir*/ 1201 ret |= pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000088); /*gpio dir*/
@@ -1347,293 +1293,129 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1347 if (ret) { 1293 if (ret) {
1348 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1294 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1349 "firmware2 upload post-proc failure"); 1295 "firmware2 upload post-proc failure");
1350 } else {
1351 hdw->flag_encoder_ok = !0;
1352 hdw->subsys_enabled_mask |= (1<<PVR2_SUBSYS_B_ENC_FIRMWARE);
1353 } 1296 }
1354 return ret; 1297 return ret;
1355} 1298}
1356 1299
1357 1300
1358#define FIRMWARE_RECOVERY_BITS \ 1301static const char *pvr2_get_state_name(unsigned int st)
1359 ((1<<PVR2_SUBSYS_B_ENC_CFG) | \ 1302{
1360 (1<<PVR2_SUBSYS_B_ENC_RUN) | \ 1303 if (st < ARRAY_SIZE(pvr2_state_names)) {
1361 (1<<PVR2_SUBSYS_B_ENC_FIRMWARE) | \ 1304 return pvr2_state_names[st];
1362 (1<<PVR2_SUBSYS_B_USBSTREAM_RUN))
1363
1364/*
1365
1366 This single function is key to pretty much everything. The pvrusb2
1367 device can logically be viewed as a series of subsystems which can be
1368 stopped / started or unconfigured / configured. To get things streaming,
1369 one must configure everything and start everything, but there may be
1370 various reasons over time to deconfigure something or stop something.
1371 This function handles all of this activity. Everything EVERYWHERE that
1372 must affect a subsystem eventually comes here to do the work.
1373
1374 The current state of all subsystems is represented by a single bit mask,
1375 known as subsys_enabled_mask. The bit positions are defined by the
1376 PVR2_SUBSYS_xxxx macros, with one subsystem per bit position. At any
1377 time the set of configured or active subsystems can be queried just by
1378 looking at that mask. To change bits in that mask, this function here
1379 must be called. The "msk" argument indicates which bit positions to
1380 change, and the "val" argument defines the new values for the positions
1381 defined by "msk".
1382
1383 There is a priority ordering of starting / stopping things, and for
1384 multiple requested changes, this function implements that ordering.
1385 (Thus we will act on a request to load encoder firmware before we
1386 configure the encoder.) In addition to priority ordering, there is a
1387 recovery strategy implemented here. If a particular step fails and we
1388 detect that failure, this function will clear the affected subsystem bits
1389 and restart. Thus we have a means for recovering from a dead encoder:
1390 Clear all bits that correspond to subsystems that we need to restart /
1391 reconfigure and start over.
1392
1393*/
1394static void pvr2_hdw_subsys_bit_chg_no_lock(struct pvr2_hdw *hdw,
1395 unsigned long msk,
1396 unsigned long val)
1397{
1398 unsigned long nmsk;
1399 unsigned long vmsk;
1400 int ret;
1401 unsigned int tryCount = 0;
1402
1403 if (!hdw->flag_ok) return;
1404
1405 msk &= PVR2_SUBSYS_ALL;
1406 nmsk = (hdw->subsys_enabled_mask & ~msk) | (val & msk);
1407 nmsk &= PVR2_SUBSYS_ALL;
1408
1409 for (;;) {
1410 tryCount++;
1411 if (!((nmsk ^ hdw->subsys_enabled_mask) &
1412 PVR2_SUBSYS_ALL)) break;
1413 if (tryCount > 4) {
1414 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1415 "Too many retries when configuring device;"
1416 " giving up");
1417 pvr2_hdw_render_useless(hdw);
1418 break;
1419 }
1420 if (tryCount > 1) {
1421 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1422 "Retrying device reconfiguration");
1423 }
1424 pvr2_trace(PVR2_TRACE_INIT,
1425 "subsys mask changing 0x%lx:0x%lx"
1426 " from 0x%lx to 0x%lx",
1427 msk,val,hdw->subsys_enabled_mask,nmsk);
1428
1429 vmsk = (nmsk ^ hdw->subsys_enabled_mask) &
1430 hdw->subsys_enabled_mask;
1431 if (vmsk) {
1432 if (vmsk & (1<<PVR2_SUBSYS_B_ENC_RUN)) {
1433 pvr2_trace(PVR2_TRACE_CTL,
1434 "/*---TRACE_CTL----*/"
1435 " pvr2_encoder_stop");
1436 ret = pvr2_encoder_stop(hdw);
1437 if (ret) {
1438 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1439 "Error recovery initiated");
1440 hdw->subsys_enabled_mask &=
1441 ~FIRMWARE_RECOVERY_BITS;
1442 continue;
1443 }
1444 }
1445 if (vmsk & (1<<PVR2_SUBSYS_B_USBSTREAM_RUN)) {
1446 pvr2_trace(PVR2_TRACE_CTL,
1447 "/*---TRACE_CTL----*/"
1448 " pvr2_hdw_cmd_usbstream(0)");
1449 pvr2_hdw_cmd_usbstream(hdw,0);
1450 }
1451 if (vmsk & (1<<PVR2_SUBSYS_B_DIGITIZER_RUN)) {
1452 pvr2_trace(PVR2_TRACE_CTL,
1453 "/*---TRACE_CTL----*/"
1454 " decoder disable");
1455 if (hdw->decoder_ctrl) {
1456 hdw->decoder_ctrl->enable(
1457 hdw->decoder_ctrl->ctxt,0);
1458 } else {
1459 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1460 "WARNING:"
1461 " No decoder present");
1462 }
1463 hdw->subsys_enabled_mask &=
1464 ~(1<<PVR2_SUBSYS_B_DIGITIZER_RUN);
1465 }
1466 if (vmsk & PVR2_SUBSYS_CFG_ALL) {
1467 hdw->subsys_enabled_mask &=
1468 ~(vmsk & PVR2_SUBSYS_CFG_ALL);
1469 }
1470 }
1471 vmsk = (nmsk ^ hdw->subsys_enabled_mask) & nmsk;
1472 if (vmsk) {
1473 if (vmsk & (1<<PVR2_SUBSYS_B_ENC_FIRMWARE)) {
1474 pvr2_trace(PVR2_TRACE_CTL,
1475 "/*---TRACE_CTL----*/"
1476 " pvr2_upload_firmware2");
1477 ret = pvr2_upload_firmware2(hdw);
1478 if (ret) {
1479 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1480 "Failure uploading encoder"
1481 " firmware");
1482 pvr2_hdw_render_useless(hdw);
1483 break;
1484 }
1485 }
1486 if (vmsk & (1<<PVR2_SUBSYS_B_ENC_CFG)) {
1487 pvr2_trace(PVR2_TRACE_CTL,
1488 "/*---TRACE_CTL----*/"
1489 " pvr2_encoder_configure");
1490 ret = pvr2_encoder_configure(hdw);
1491 if (ret) {
1492 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1493 "Error recovery initiated");
1494 hdw->subsys_enabled_mask &=
1495 ~FIRMWARE_RECOVERY_BITS;
1496 continue;
1497 }
1498 }
1499 if (vmsk & (1<<PVR2_SUBSYS_B_DIGITIZER_RUN)) {
1500 pvr2_trace(PVR2_TRACE_CTL,
1501 "/*---TRACE_CTL----*/"
1502 " decoder enable");
1503 if (hdw->decoder_ctrl) {
1504 hdw->decoder_ctrl->enable(
1505 hdw->decoder_ctrl->ctxt,!0);
1506 } else {
1507 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1508 "WARNING:"
1509 " No decoder present");
1510 }
1511 hdw->subsys_enabled_mask |=
1512 (1<<PVR2_SUBSYS_B_DIGITIZER_RUN);
1513 }
1514 if (vmsk & (1<<PVR2_SUBSYS_B_USBSTREAM_RUN)) {
1515 pvr2_trace(PVR2_TRACE_CTL,
1516 "/*---TRACE_CTL----*/"
1517 " pvr2_hdw_cmd_usbstream(1)");
1518 pvr2_hdw_cmd_usbstream(hdw,!0);
1519 }
1520 if (vmsk & (1<<PVR2_SUBSYS_B_ENC_RUN)) {
1521 pvr2_trace(PVR2_TRACE_CTL,
1522 "/*---TRACE_CTL----*/"
1523 " pvr2_encoder_start");
1524 ret = pvr2_encoder_start(hdw);
1525 if (ret) {
1526 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1527 "Error recovery initiated");
1528 hdw->subsys_enabled_mask &=
1529 ~FIRMWARE_RECOVERY_BITS;
1530 continue;
1531 }
1532 }
1533 }
1534 } 1305 }
1306 return "???";
1535} 1307}
1536 1308
1537 1309static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl)
1538void pvr2_hdw_subsys_bit_chg(struct pvr2_hdw *hdw,
1539 unsigned long msk,unsigned long val)
1540{ 1310{
1541 LOCK_TAKE(hdw->big_lock); do { 1311 if (!hdw->decoder_ctrl) {
1542 pvr2_hdw_subsys_bit_chg_no_lock(hdw,msk,val); 1312 if (!hdw->flag_decoder_missed) {
1543 } while (0); LOCK_GIVE(hdw->big_lock); 1313 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1314 "WARNING: No decoder present");
1315 hdw->flag_decoder_missed = !0;
1316 trace_stbit("flag_decoder_missed",
1317 hdw->flag_decoder_missed);
1318 }
1319 return -EIO;
1320 }
1321 hdw->decoder_ctrl->enable(hdw->decoder_ctrl->ctxt,enablefl);
1322 return 0;
1544} 1323}
1545 1324
1546 1325
1547unsigned long pvr2_hdw_subsys_get(struct pvr2_hdw *hdw) 1326void pvr2_hdw_set_decoder(struct pvr2_hdw *hdw,struct pvr2_decoder_ctrl *ptr)
1548{ 1327{
1549 return hdw->subsys_enabled_mask; 1328 if (hdw->decoder_ctrl == ptr) return;
1329 hdw->decoder_ctrl = ptr;
1330 if (hdw->decoder_ctrl && hdw->flag_decoder_missed) {
1331 hdw->flag_decoder_missed = 0;
1332 trace_stbit("flag_decoder_missed",
1333 hdw->flag_decoder_missed);
1334 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1335 "Decoder has appeared");
1336 pvr2_hdw_state_sched(hdw);
1337 }
1550} 1338}
1551 1339
1552 1340
1553unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *hdw) 1341int pvr2_hdw_get_state(struct pvr2_hdw *hdw)
1554{ 1342{
1555 return hdw->subsys_stream_mask; 1343 return hdw->master_state;
1556} 1344}
1557 1345
1558 1346
1559static void pvr2_hdw_subsys_stream_bit_chg_no_lock(struct pvr2_hdw *hdw, 1347static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *hdw)
1560 unsigned long msk,
1561 unsigned long val)
1562{ 1348{
1563 unsigned long val2; 1349 if (!hdw->flag_tripped) return 0;
1564 msk &= PVR2_SUBSYS_ALL; 1350 hdw->flag_tripped = 0;
1565 val2 = ((hdw->subsys_stream_mask & ~msk) | (val & msk)); 1351 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1566 pvr2_trace(PVR2_TRACE_INIT, 1352 "Clearing driver error statuss");
1567 "stream mask changing 0x%lx:0x%lx from 0x%lx to 0x%lx", 1353 return !0;
1568 msk,val,hdw->subsys_stream_mask,val2);
1569 hdw->subsys_stream_mask = val2;
1570} 1354}
1571 1355
1572 1356
1573void pvr2_hdw_subsys_stream_bit_chg(struct pvr2_hdw *hdw, 1357int pvr2_hdw_untrip(struct pvr2_hdw *hdw)
1574 unsigned long msk,
1575 unsigned long val)
1576{ 1358{
1359 int fl;
1577 LOCK_TAKE(hdw->big_lock); do { 1360 LOCK_TAKE(hdw->big_lock); do {
1578 pvr2_hdw_subsys_stream_bit_chg_no_lock(hdw,msk,val); 1361 fl = pvr2_hdw_untrip_unlocked(hdw);
1579 } while (0); LOCK_GIVE(hdw->big_lock); 1362 } while (0); LOCK_GIVE(hdw->big_lock);
1363 if (fl) pvr2_hdw_state_sched(hdw);
1364 return 0;
1580} 1365}
1581 1366
1582 1367
1583static int pvr2_hdw_set_streaming_no_lock(struct pvr2_hdw *hdw,int enableFl) 1368const char *pvr2_hdw_get_state_name(unsigned int id)
1584{ 1369{
1585 if ((!enableFl) == !(hdw->flag_streaming_enabled)) return 0; 1370 if (id >= ARRAY_SIZE(pvr2_state_names)) return NULL;
1586 if (enableFl) { 1371 return pvr2_state_names[id];
1587 pvr2_trace(PVR2_TRACE_START_STOP,
1588 "/*--TRACE_STREAM--*/ enable");
1589 pvr2_hdw_subsys_bit_chg_no_lock(hdw,~0,~0);
1590 } else {
1591 pvr2_trace(PVR2_TRACE_START_STOP,
1592 "/*--TRACE_STREAM--*/ disable");
1593 pvr2_hdw_subsys_bit_chg_no_lock(hdw,hdw->subsys_stream_mask,0);
1594 }
1595 if (!hdw->flag_ok) return -EIO;
1596 hdw->flag_streaming_enabled = enableFl != 0;
1597 return 0;
1598} 1372}
1599 1373
1600 1374
1601int pvr2_hdw_get_streaming(struct pvr2_hdw *hdw) 1375int pvr2_hdw_get_streaming(struct pvr2_hdw *hdw)
1602{ 1376{
1603 return hdw->flag_streaming_enabled != 0; 1377 return hdw->state_pipeline_req != 0;
1604} 1378}
1605 1379
1606 1380
1607int pvr2_hdw_set_streaming(struct pvr2_hdw *hdw,int enable_flag) 1381int pvr2_hdw_set_streaming(struct pvr2_hdw *hdw,int enable_flag)
1608{ 1382{
1609 int ret; 1383 int ret,st;
1610 LOCK_TAKE(hdw->big_lock); do { 1384 LOCK_TAKE(hdw->big_lock); do {
1611 ret = pvr2_hdw_set_streaming_no_lock(hdw,enable_flag); 1385 pvr2_hdw_untrip_unlocked(hdw);
1386 if ((!enable_flag) != !(hdw->state_pipeline_req)) {
1387 hdw->state_pipeline_req = enable_flag != 0;
1388 pvr2_trace(PVR2_TRACE_START_STOP,
1389 "/*--TRACE_STREAM--*/ %s",
1390 enable_flag ? "enable" : "disable");
1391 }
1392 pvr2_hdw_state_sched(hdw);
1612 } while (0); LOCK_GIVE(hdw->big_lock); 1393 } while (0); LOCK_GIVE(hdw->big_lock);
1613 return ret; 1394 if ((ret = pvr2_hdw_wait(hdw,0)) < 0) return ret;
1614} 1395 if (enable_flag) {
1615 1396 while ((st = hdw->master_state) != PVR2_STATE_RUN) {
1616 1397 if (st != PVR2_STATE_READY) return -EIO;
1617static int pvr2_hdw_set_stream_type_no_lock(struct pvr2_hdw *hdw, 1398 if ((ret = pvr2_hdw_wait(hdw,st)) < 0) return ret;
1618 enum pvr2_config config) 1399 }
1619{ 1400 }
1620 unsigned long sm = hdw->subsys_enabled_mask;
1621 if (!hdw->flag_ok) return -EIO;
1622 pvr2_hdw_subsys_bit_chg_no_lock(hdw,hdw->subsys_stream_mask,0);
1623 hdw->config = config;
1624 pvr2_hdw_subsys_bit_chg_no_lock(hdw,~0,sm);
1625 return 0; 1401 return 0;
1626} 1402}
1627 1403
1628 1404
1629int pvr2_hdw_set_stream_type(struct pvr2_hdw *hdw,enum pvr2_config config) 1405int pvr2_hdw_set_stream_type(struct pvr2_hdw *hdw,enum pvr2_config config)
1630{ 1406{
1631 int ret; 1407 int fl;
1632 if (!hdw->flag_ok) return -EIO;
1633 LOCK_TAKE(hdw->big_lock); 1408 LOCK_TAKE(hdw->big_lock);
1634 ret = pvr2_hdw_set_stream_type_no_lock(hdw,config); 1409 if ((fl = (hdw->desired_stream_type != config)) != 0) {
1410 hdw->desired_stream_type = config;
1411 hdw->state_pipeline_config = 0;
1412 trace_stbit("state_pipeline_config",
1413 hdw->state_pipeline_config);
1414 pvr2_hdw_state_sched(hdw);
1415 }
1635 LOCK_GIVE(hdw->big_lock); 1416 LOCK_GIVE(hdw->big_lock);
1636 return ret; 1417 if (fl) return 0;
1418 return pvr2_hdw_wait(hdw,0);
1637} 1419}
1638 1420
1639 1421
@@ -1646,6 +1428,7 @@ static int get_default_tuner_type(struct pvr2_hdw *hdw)
1646 } 1428 }
1647 if (tp < 0) return -EINVAL; 1429 if (tp < 0) return -EINVAL;
1648 hdw->tuner_type = tp; 1430 hdw->tuner_type = tp;
1431 hdw->tuner_updated = !0;
1649 return 0; 1432 return 0;
1650} 1433}
1651 1434
@@ -1656,8 +1439,9 @@ static v4l2_std_id get_default_standard(struct pvr2_hdw *hdw)
1656 int tp = 0; 1439 int tp = 0;
1657 if ((unit_number >= 0) && (unit_number < PVR_NUM)) { 1440 if ((unit_number >= 0) && (unit_number < PVR_NUM)) {
1658 tp = video_std[unit_number]; 1441 tp = video_std[unit_number];
1442 if (tp) return tp;
1659 } 1443 }
1660 return tp; 1444 return 0;
1661} 1445}
1662 1446
1663 1447
@@ -1731,7 +1515,7 @@ const static struct pvr2_std_hack std_eeprom_maps[] = {
1731 }, 1515 },
1732 { /* PAL(D/D1/K) */ 1516 { /* PAL(D/D1/K) */
1733 .pat = V4L2_STD_DK, 1517 .pat = V4L2_STD_DK,
1734 .std = V4L2_STD_PAL_D/V4L2_STD_PAL_D1|V4L2_STD_PAL_K, 1518 .std = V4L2_STD_PAL_D|V4L2_STD_PAL_D1|V4L2_STD_PAL_K,
1735 }, 1519 },
1736}; 1520};
1737 1521
@@ -1739,18 +1523,20 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
1739{ 1523{
1740 char buf[40]; 1524 char buf[40];
1741 unsigned int bcnt; 1525 unsigned int bcnt;
1742 v4l2_std_id std1,std2; 1526 v4l2_std_id std1,std2,std3;
1743 1527
1744 std1 = get_default_standard(hdw); 1528 std1 = get_default_standard(hdw);
1529 std3 = std1 ? 0 : hdw->hdw_desc->default_std_mask;
1745 1530
1746 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),hdw->std_mask_eeprom); 1531 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),hdw->std_mask_eeprom);
1747 pvr2_trace(PVR2_TRACE_STD, 1532 pvr2_trace(PVR2_TRACE_STD,
1748 "Supported video standard(s) reported by eeprom: %.*s", 1533 "Supported video standard(s) reported available"
1534 " in hardware: %.*s",
1749 bcnt,buf); 1535 bcnt,buf);
1750 1536
1751 hdw->std_mask_avail = hdw->std_mask_eeprom; 1537 hdw->std_mask_avail = hdw->std_mask_eeprom;
1752 1538
1753 std2 = std1 & ~hdw->std_mask_avail; 1539 std2 = (std1|std3) & ~hdw->std_mask_avail;
1754 if (std2) { 1540 if (std2) {
1755 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),std2); 1541 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),std2);
1756 pvr2_trace(PVR2_TRACE_STD, 1542 pvr2_trace(PVR2_TRACE_STD,
@@ -1772,6 +1558,16 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
1772 pvr2_hdw_internal_find_stdenum(hdw); 1558 pvr2_hdw_internal_find_stdenum(hdw);
1773 return; 1559 return;
1774 } 1560 }
1561 if (std3) {
1562 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),std3);
1563 pvr2_trace(PVR2_TRACE_STD,
1564 "Initial video standard"
1565 " (determined by device type): %.*s",bcnt,buf);
1566 hdw->std_mask_cur = std3;
1567 hdw->std_dirty = !0;
1568 pvr2_hdw_internal_find_stdenum(hdw);
1569 return;
1570 }
1775 1571
1776 { 1572 {
1777 unsigned int idx; 1573 unsigned int idx;
@@ -1816,8 +1612,7 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1816 unsigned int idx; 1612 unsigned int idx;
1817 struct pvr2_ctrl *cptr; 1613 struct pvr2_ctrl *cptr;
1818 int reloadFl = 0; 1614 int reloadFl = 0;
1819 if ((hdw->hdw_type == PVR2_HDW_TYPE_29XXX) || 1615 if (hdw->hdw_desc->fx2_firmware.cnt) {
1820 (hdw->hdw_type == PVR2_HDW_TYPE_24XXX)) {
1821 if (!reloadFl) { 1616 if (!reloadFl) {
1822 reloadFl = 1617 reloadFl =
1823 (hdw->usb_intf->cur_altsetting->desc.bNumEndpoints 1618 (hdw->usb_intf->cur_altsetting->desc.bNumEndpoints
@@ -1853,25 +1648,13 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1853 } 1648 }
1854 if (!pvr2_hdw_dev_ok(hdw)) return; 1649 if (!pvr2_hdw_dev_ok(hdw)) return;
1855 1650
1856 if (hdw->hdw_type < ARRAY_SIZE(pvr2_client_lists)) { 1651 for (idx = 0; idx < hdw->hdw_desc->client_modules.cnt; idx++) {
1857 for (idx = 0; 1652 request_module(hdw->hdw_desc->client_modules.lst[idx]);
1858 idx < pvr2_client_lists[hdw->hdw_type].cnt;
1859 idx++) {
1860 request_module(
1861 pvr2_client_lists[hdw->hdw_type].lst[idx]);
1862 }
1863 } 1653 }
1864 1654
1865 if ((hdw->hdw_type == PVR2_HDW_TYPE_29XXX) || 1655 if (!hdw->hdw_desc->flag_no_powerup) {
1866 (hdw->hdw_type == PVR2_HDW_TYPE_24XXX)) {
1867 pvr2_hdw_cmd_powerup(hdw); 1656 pvr2_hdw_cmd_powerup(hdw);
1868 if (!pvr2_hdw_dev_ok(hdw)) return; 1657 if (!pvr2_hdw_dev_ok(hdw)) return;
1869
1870 if (pvr2_upload_firmware2(hdw)){
1871 pvr2_trace(PVR2_TRACE_ERROR_LEGS,"device unstable!!");
1872 pvr2_hdw_render_useless(hdw);
1873 return;
1874 }
1875 } 1658 }
1876 1659
1877 // This step MUST happen after the earlier powerup step. 1660 // This step MUST happen after the earlier powerup step.
@@ -1899,15 +1682,22 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1899 // thread-safe against the normal pvr2_send_request() mechanism. 1682 // thread-safe against the normal pvr2_send_request() mechanism.
1900 // (We should make it thread safe). 1683 // (We should make it thread safe).
1901 1684
1902 ret = pvr2_hdw_get_eeprom_addr(hdw); 1685 if (hdw->hdw_desc->flag_has_hauppauge_rom) {
1903 if (!pvr2_hdw_dev_ok(hdw)) return; 1686 ret = pvr2_hdw_get_eeprom_addr(hdw);
1904 if (ret < 0) {
1905 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1906 "Unable to determine location of eeprom, skipping");
1907 } else {
1908 hdw->eeprom_addr = ret;
1909 pvr2_eeprom_analyze(hdw);
1910 if (!pvr2_hdw_dev_ok(hdw)) return; 1687 if (!pvr2_hdw_dev_ok(hdw)) return;
1688 if (ret < 0) {
1689 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1690 "Unable to determine location of eeprom,"
1691 " skipping");
1692 } else {
1693 hdw->eeprom_addr = ret;
1694 pvr2_eeprom_analyze(hdw);
1695 if (!pvr2_hdw_dev_ok(hdw)) return;
1696 }
1697 } else {
1698 hdw->tuner_type = hdw->hdw_desc->default_tuner_type;
1699 hdw->tuner_updated = !0;
1700 hdw->std_mask_eeprom = V4L2_STD_ALL;
1911 } 1701 }
1912 1702
1913 pvr2_hdw_setup_std(hdw); 1703 pvr2_hdw_setup_std(hdw);
@@ -1918,14 +1708,12 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1918 hdw->tuner_type); 1708 hdw->tuner_type);
1919 } 1709 }
1920 1710
1921 hdw->tuner_updated = !0;
1922 pvr2_i2c_core_check_stale(hdw); 1711 pvr2_i2c_core_check_stale(hdw);
1923 hdw->tuner_updated = 0; 1712 hdw->tuner_updated = 0;
1924 1713
1925 if (!pvr2_hdw_dev_ok(hdw)) return; 1714 if (!pvr2_hdw_dev_ok(hdw)) return;
1926 1715
1927 pvr2_hdw_commit_ctl_internal(hdw); 1716 pvr2_hdw_commit_setup(hdw);
1928 if (!pvr2_hdw_dev_ok(hdw)) return;
1929 1717
1930 hdw->vid_stream = pvr2_stream_create(); 1718 hdw->vid_stream = pvr2_stream_create();
1931 if (!pvr2_hdw_dev_ok(hdw)) return; 1719 if (!pvr2_hdw_dev_ok(hdw)) return;
@@ -1945,25 +1733,25 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1945 1733
1946 if (!pvr2_hdw_dev_ok(hdw)) return; 1734 if (!pvr2_hdw_dev_ok(hdw)) return;
1947 1735
1948 /* Make sure everything is up to date */
1949 pvr2_i2c_core_sync(hdw);
1950
1951 if (!pvr2_hdw_dev_ok(hdw)) return;
1952
1953 hdw->flag_init_ok = !0; 1736 hdw->flag_init_ok = !0;
1737
1738 pvr2_hdw_state_sched(hdw);
1954} 1739}
1955 1740
1956 1741
1957int pvr2_hdw_setup(struct pvr2_hdw *hdw) 1742/* Set up the structure and attempt to put the device into a usable state.
1743 This can be a time-consuming operation, which is why it is not done
1744 internally as part of the create() step. */
1745static void pvr2_hdw_setup(struct pvr2_hdw *hdw)
1958{ 1746{
1959 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_setup(hdw=%p) begin",hdw); 1747 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_setup(hdw=%p) begin",hdw);
1960 LOCK_TAKE(hdw->big_lock); do { 1748 do {
1961 pvr2_hdw_setup_low(hdw); 1749 pvr2_hdw_setup_low(hdw);
1962 pvr2_trace(PVR2_TRACE_INIT, 1750 pvr2_trace(PVR2_TRACE_INIT,
1963 "pvr2_hdw_setup(hdw=%p) done, ok=%d init_ok=%d", 1751 "pvr2_hdw_setup(hdw=%p) done, ok=%d init_ok=%d",
1964 hdw,hdw->flag_ok,hdw->flag_init_ok); 1752 hdw,pvr2_hdw_dev_ok(hdw),hdw->flag_init_ok);
1965 if (pvr2_hdw_dev_ok(hdw)) { 1753 if (pvr2_hdw_dev_ok(hdw)) {
1966 if (pvr2_hdw_init_ok(hdw)) { 1754 if (hdw->flag_init_ok) {
1967 pvr2_trace( 1755 pvr2_trace(
1968 PVR2_TRACE_INFO, 1756 PVR2_TRACE_INFO,
1969 "Device initialization" 1757 "Device initialization"
@@ -2013,9 +1801,8 @@ int pvr2_hdw_setup(struct pvr2_hdw *hdw)
2013 " the pvrusb2 device" 1801 " the pvrusb2 device"
2014 " in order to recover."); 1802 " in order to recover.");
2015 } 1803 }
2016 } while (0); LOCK_GIVE(hdw->big_lock); 1804 } while (0);
2017 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_setup(hdw=%p) end",hdw); 1805 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_setup(hdw=%p) end",hdw);
2018 return hdw->flag_init_ok;
2019} 1806}
2020 1807
2021 1808
@@ -2026,24 +1813,32 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2026{ 1813{
2027 unsigned int idx,cnt1,cnt2; 1814 unsigned int idx,cnt1,cnt2;
2028 struct pvr2_hdw *hdw; 1815 struct pvr2_hdw *hdw;
2029 unsigned int hdw_type;
2030 int valid_std_mask; 1816 int valid_std_mask;
2031 struct pvr2_ctrl *cptr; 1817 struct pvr2_ctrl *cptr;
1818 const struct pvr2_device_desc *hdw_desc;
2032 __u8 ifnum; 1819 __u8 ifnum;
2033 struct v4l2_queryctrl qctrl; 1820 struct v4l2_queryctrl qctrl;
2034 struct pvr2_ctl_info *ciptr; 1821 struct pvr2_ctl_info *ciptr;
2035 1822
2036 hdw_type = devid - pvr2_device_table; 1823 hdw_desc = (const struct pvr2_device_desc *)(devid->driver_info);
2037 if (hdw_type >= ARRAY_SIZE(pvr2_device_names)) {
2038 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2039 "Bogus device type of %u reported",hdw_type);
2040 return NULL;
2041 }
2042 1824
2043 hdw = kzalloc(sizeof(*hdw),GFP_KERNEL); 1825 hdw = kzalloc(sizeof(*hdw),GFP_KERNEL);
2044 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_create: hdw=%p, type \"%s\"", 1826 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_create: hdw=%p, type \"%s\"",
2045 hdw,pvr2_device_names[hdw_type]); 1827 hdw,hdw_desc->description);
2046 if (!hdw) goto fail; 1828 if (!hdw) goto fail;
1829
1830 init_timer(&hdw->quiescent_timer);
1831 hdw->quiescent_timer.data = (unsigned long)hdw;
1832 hdw->quiescent_timer.function = pvr2_hdw_quiescent_timeout;
1833
1834 init_timer(&hdw->encoder_wait_timer);
1835 hdw->encoder_wait_timer.data = (unsigned long)hdw;
1836 hdw->encoder_wait_timer.function = pvr2_hdw_encoder_wait_timeout;
1837
1838 hdw->master_state = PVR2_STATE_DEAD;
1839
1840 init_waitqueue_head(&hdw->state_wait_data);
1841
2047 hdw->tuner_signal_stale = !0; 1842 hdw->tuner_signal_stale = !0;
2048 cx2341x_fill_defaults(&hdw->enc_ctl_state); 1843 cx2341x_fill_defaults(&hdw->enc_ctl_state);
2049 1844
@@ -2052,7 +1847,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2052 hdw->controls = kzalloc(sizeof(struct pvr2_ctrl) * hdw->control_cnt, 1847 hdw->controls = kzalloc(sizeof(struct pvr2_ctrl) * hdw->control_cnt,
2053 GFP_KERNEL); 1848 GFP_KERNEL);
2054 if (!hdw->controls) goto fail; 1849 if (!hdw->controls) goto fail;
2055 hdw->hdw_type = hdw_type; 1850 hdw->hdw_desc = hdw_desc;
2056 for (idx = 0; idx < hdw->control_cnt; idx++) { 1851 for (idx = 0; idx < hdw->control_cnt; idx++) {
2057 cptr = hdw->controls + idx; 1852 cptr = hdw->controls + idx;
2058 cptr->hdw = hdw; 1853 cptr->hdw = hdw;
@@ -2184,18 +1979,16 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2184 if (cnt1 >= sizeof(hdw->name)) cnt1 = sizeof(hdw->name)-1; 1979 if (cnt1 >= sizeof(hdw->name)) cnt1 = sizeof(hdw->name)-1;
2185 hdw->name[cnt1] = 0; 1980 hdw->name[cnt1] = 0;
2186 1981
1982 hdw->workqueue = create_singlethread_workqueue(hdw->name);
1983 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll);
1984 INIT_WORK(&hdw->worki2csync,pvr2_hdw_worker_i2c);
1985 INIT_WORK(&hdw->workinit,pvr2_hdw_worker_init);
1986
2187 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s", 1987 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s",
2188 hdw->unit_number,hdw->name); 1988 hdw->unit_number,hdw->name);
2189 1989
2190 hdw->tuner_type = -1; 1990 hdw->tuner_type = -1;
2191 hdw->flag_ok = !0; 1991 hdw->flag_ok = !0;
2192 /* Initialize the mask of subsystems that we will shut down when we
2193 stop streaming. */
2194 hdw->subsys_stream_mask = PVR2_SUBSYS_RUN_ALL;
2195 hdw->subsys_stream_mask |= (1<<PVR2_SUBSYS_B_ENC_CFG);
2196
2197 pvr2_trace(PVR2_TRACE_INIT,"subsys_stream_mask: 0x%lx",
2198 hdw->subsys_stream_mask);
2199 1992
2200 hdw->usb_intf = intf; 1993 hdw->usb_intf = intf;
2201 hdw->usb_dev = interface_to_usbdev(intf); 1994 hdw->usb_dev = interface_to_usbdev(intf);
@@ -2211,15 +2004,25 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2211 mutex_init(&hdw->ctl_lock_mutex); 2004 mutex_init(&hdw->ctl_lock_mutex);
2212 mutex_init(&hdw->big_lock_mutex); 2005 mutex_init(&hdw->big_lock_mutex);
2213 2006
2007 queue_work(hdw->workqueue,&hdw->workinit);
2214 return hdw; 2008 return hdw;
2215 fail: 2009 fail:
2216 if (hdw) { 2010 if (hdw) {
2011 del_timer_sync(&hdw->quiescent_timer);
2012 del_timer_sync(&hdw->encoder_wait_timer);
2013 if (hdw->workqueue) {
2014 flush_workqueue(hdw->workqueue);
2015 destroy_workqueue(hdw->workqueue);
2016 hdw->workqueue = NULL;
2017 }
2217 usb_free_urb(hdw->ctl_read_urb); 2018 usb_free_urb(hdw->ctl_read_urb);
2218 usb_free_urb(hdw->ctl_write_urb); 2019 usb_free_urb(hdw->ctl_write_urb);
2219 kfree(hdw->ctl_read_buffer); 2020 kfree(hdw->ctl_read_buffer);
2220 kfree(hdw->ctl_write_buffer); 2021 kfree(hdw->ctl_write_buffer);
2221 kfree(hdw->controls); 2022 kfree(hdw->controls);
2222 kfree(hdw->mpeg_ctrl_info); 2023 kfree(hdw->mpeg_ctrl_info);
2024 kfree(hdw->std_defs);
2025 kfree(hdw->std_enum_names);
2223 kfree(hdw); 2026 kfree(hdw);
2224 } 2027 }
2225 return NULL; 2028 return NULL;
@@ -2250,10 +2053,10 @@ static void pvr2_hdw_remove_usb_stuff(struct pvr2_hdw *hdw)
2250 kfree(hdw->ctl_write_buffer); 2053 kfree(hdw->ctl_write_buffer);
2251 hdw->ctl_write_buffer = NULL; 2054 hdw->ctl_write_buffer = NULL;
2252 } 2055 }
2253 pvr2_hdw_render_useless_unlocked(hdw);
2254 hdw->flag_disconnected = !0; 2056 hdw->flag_disconnected = !0;
2255 hdw->usb_dev = NULL; 2057 hdw->usb_dev = NULL;
2256 hdw->usb_intf = NULL; 2058 hdw->usb_intf = NULL;
2059 pvr2_hdw_render_useless(hdw);
2257} 2060}
2258 2061
2259 2062
@@ -2262,6 +2065,13 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2262{ 2065{
2263 if (!hdw) return; 2066 if (!hdw) return;
2264 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_destroy: hdw=%p",hdw); 2067 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_destroy: hdw=%p",hdw);
2068 del_timer_sync(&hdw->quiescent_timer);
2069 del_timer_sync(&hdw->encoder_wait_timer);
2070 if (hdw->workqueue) {
2071 flush_workqueue(hdw->workqueue);
2072 destroy_workqueue(hdw->workqueue);
2073 hdw->workqueue = NULL;
2074 }
2265 if (hdw->fw_buffer) { 2075 if (hdw->fw_buffer) {
2266 kfree(hdw->fw_buffer); 2076 kfree(hdw->fw_buffer);
2267 hdw->fw_buffer = NULL; 2077 hdw->fw_buffer = NULL;
@@ -2290,12 +2100,6 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2290} 2100}
2291 2101
2292 2102
2293int pvr2_hdw_init_ok(struct pvr2_hdw *hdw)
2294{
2295 return hdw->flag_init_ok;
2296}
2297
2298
2299int pvr2_hdw_dev_ok(struct pvr2_hdw *hdw) 2103int pvr2_hdw_dev_ok(struct pvr2_hdw *hdw)
2300{ 2104{
2301 return (hdw && hdw->flag_ok); 2105 return (hdw && hdw->flag_ok);
@@ -2473,17 +2277,11 @@ static const char *get_ctrl_typename(enum pvr2_ctl_type tp)
2473} 2277}
2474 2278
2475 2279
2476/* Commit all control changes made up to this point. Subsystems can be 2280/* Figure out if we need to commit control changes. If so, mark internal
2477 indirectly affected by these changes. For a given set of things being 2281 state flags to indicate this fact and return true. Otherwise do nothing
2478 committed, we'll clear the affected subsystem bits and then once we're 2282 else and return false. */
2479 done committing everything we'll make a request to restore the subsystem 2283static int pvr2_hdw_commit_setup(struct pvr2_hdw *hdw)
2480 state(s) back to their previous value before this function was called.
2481 Thus we can automatically reconfigure affected pieces of the driver as
2482 controls are changed. */
2483static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
2484{ 2284{
2485 unsigned long saved_subsys_mask = hdw->subsys_enabled_mask;
2486 unsigned long stale_subsys_mask = 0;
2487 unsigned int idx; 2285 unsigned int idx;
2488 struct pvr2_ctrl *cptr; 2286 struct pvr2_ctrl *cptr;
2489 int value; 2287 int value;
@@ -2518,6 +2316,25 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
2518 return 0; 2316 return 0;
2519 } 2317 }
2520 2318
2319 hdw->state_pipeline_config = 0;
2320 trace_stbit("state_pipeline_config",hdw->state_pipeline_config);
2321 pvr2_hdw_state_sched(hdw);
2322
2323 return !0;
2324}
2325
2326
2327/* Perform all operations needed to commit all control changes. This must
2328 be performed in synchronization with the pipeline state and is thus
2329 expected to be called as part of the driver's worker thread. Return
2330 true if commit successful, otherwise return false to indicate that
2331 commit isn't possible at this time. */
2332static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2333{
2334 unsigned int idx;
2335 struct pvr2_ctrl *cptr;
2336 int disruptive_change;
2337
2521 /* When video standard changes, reset the hres and vres values - 2338 /* When video standard changes, reset the hres and vres values -
2522 but if the user has pending changes there, then let the changes 2339 but if the user has pending changes there, then let the changes
2523 take priority. */ 2340 take priority. */
@@ -2536,24 +2353,26 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
2536 } 2353 }
2537 } 2354 }
2538 2355
2539 if (hdw->std_dirty || 2356 /* If any of the below has changed, then we can't do the update
2540 hdw->enc_stale || 2357 while the pipeline is running. Pipeline must be paused first
2541 hdw->srate_dirty || 2358 and decoder -> encoder connection be made quiescent before we
2542 hdw->res_ver_dirty || 2359 can proceed. */
2543 hdw->res_hor_dirty || 2360 disruptive_change =
2544 0) { 2361 (hdw->std_dirty ||
2545 /* If any of this changes, then the encoder needs to be 2362 hdw->enc_unsafe_stale ||
2546 reconfigured, and we need to reset the stream. */ 2363 hdw->srate_dirty ||
2547 stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_CFG); 2364 hdw->res_ver_dirty ||
2548 } 2365 hdw->res_hor_dirty ||
2549 2366 hdw->input_dirty ||
2550 if (hdw->input_dirty) { 2367 (hdw->active_stream_type != hdw->desired_stream_type));
2551 /* pk: If input changes to or from radio, then the encoder 2368 if (disruptive_change && !hdw->state_pipeline_idle) {
2552 needs to be restarted (for ENC_MUTE_VIDEO to work) */ 2369 /* Pipeline is not idle; we can't proceed. Arrange to
2553 stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_RUN); 2370 cause pipeline to stop so that we can try this again
2371 later.... */
2372 hdw->state_pipeline_pause = !0;
2373 return 0;
2554 } 2374 }
2555 2375
2556
2557 if (hdw->srate_dirty) { 2376 if (hdw->srate_dirty) {
2558 /* Write new sample rate into control structure since 2377 /* Write new sample rate into control structure since
2559 * the master copy is stale. We must track srate 2378 * the master copy is stale. We must track srate
@@ -2582,51 +2401,88 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
2582 cptr->info->clear_dirty(cptr); 2401 cptr->info->clear_dirty(cptr);
2583 } 2402 }
2584 2403
2404 if (hdw->active_stream_type != hdw->desired_stream_type) {
2405 /* Handle any side effects of stream config here */
2406 hdw->active_stream_type = hdw->desired_stream_type;
2407 }
2408
2585 /* Now execute i2c core update */ 2409 /* Now execute i2c core update */
2586 pvr2_i2c_core_sync(hdw); 2410 pvr2_i2c_core_sync(hdw);
2587 2411
2588 pvr2_hdw_subsys_bit_chg_no_lock(hdw,stale_subsys_mask,0); 2412 if (hdw->state_encoder_run) {
2589 pvr2_hdw_subsys_bit_chg_no_lock(hdw,~0,saved_subsys_mask); 2413 /* If encoder isn't running, then this will get worked out
2414 later when we start the encoder. */
2415 if (pvr2_encoder_adjust(hdw) < 0) return !0;
2416 }
2590 2417
2591 return 0; 2418 hdw->state_pipeline_config = !0;
2419 trace_stbit("state_pipeline_config",hdw->state_pipeline_config);
2420 return !0;
2592} 2421}
2593 2422
2594 2423
2595int pvr2_hdw_commit_ctl(struct pvr2_hdw *hdw) 2424int pvr2_hdw_commit_ctl(struct pvr2_hdw *hdw)
2596{ 2425{
2426 int fl;
2427 LOCK_TAKE(hdw->big_lock);
2428 fl = pvr2_hdw_commit_setup(hdw);
2429 LOCK_GIVE(hdw->big_lock);
2430 if (!fl) return 0;
2431 return pvr2_hdw_wait(hdw,0);
2432}
2433
2434
2435static void pvr2_hdw_worker_i2c(struct work_struct *work)
2436{
2437 struct pvr2_hdw *hdw = container_of(work,struct pvr2_hdw,worki2csync);
2597 LOCK_TAKE(hdw->big_lock); do { 2438 LOCK_TAKE(hdw->big_lock); do {
2598 pvr2_hdw_commit_ctl_internal(hdw); 2439 pvr2_i2c_core_sync(hdw);
2599 } while (0); LOCK_GIVE(hdw->big_lock); 2440 } while (0); LOCK_GIVE(hdw->big_lock);
2600 return 0;
2601} 2441}
2602 2442
2603 2443
2604void pvr2_hdw_poll(struct pvr2_hdw *hdw) 2444static void pvr2_hdw_worker_poll(struct work_struct *work)
2605{ 2445{
2446 int fl = 0;
2447 struct pvr2_hdw *hdw = container_of(work,struct pvr2_hdw,workpoll);
2606 LOCK_TAKE(hdw->big_lock); do { 2448 LOCK_TAKE(hdw->big_lock); do {
2607 pvr2_i2c_core_sync(hdw); 2449 fl = pvr2_hdw_state_eval(hdw);
2608 } while (0); LOCK_GIVE(hdw->big_lock); 2450 } while (0); LOCK_GIVE(hdw->big_lock);
2451 if (fl && hdw->state_func) {
2452 hdw->state_func(hdw->state_data);
2453 }
2609} 2454}
2610 2455
2611 2456
2612void pvr2_hdw_setup_poll_trigger(struct pvr2_hdw *hdw, 2457static void pvr2_hdw_worker_init(struct work_struct *work)
2613 void (*func)(void *),
2614 void *data)
2615{ 2458{
2459 struct pvr2_hdw *hdw = container_of(work,struct pvr2_hdw,workinit);
2616 LOCK_TAKE(hdw->big_lock); do { 2460 LOCK_TAKE(hdw->big_lock); do {
2617 hdw->poll_trigger_func = func; 2461 pvr2_hdw_setup(hdw);
2618 hdw->poll_trigger_data = data;
2619 } while (0); LOCK_GIVE(hdw->big_lock); 2462 } while (0); LOCK_GIVE(hdw->big_lock);
2620} 2463}
2621 2464
2622 2465
2623void pvr2_hdw_poll_trigger_unlocked(struct pvr2_hdw *hdw) 2466static int pvr2_hdw_wait(struct pvr2_hdw *hdw,int state)
2624{ 2467{
2625 if (hdw->poll_trigger_func) { 2468 return wait_event_interruptible(
2626 hdw->poll_trigger_func(hdw->poll_trigger_data); 2469 hdw->state_wait_data,
2627 } 2470 (hdw->state_stale == 0) &&
2471 (!state || (hdw->master_state != state)));
2628} 2472}
2629 2473
2474
2475void pvr2_hdw_set_state_callback(struct pvr2_hdw *hdw,
2476 void (*callback_func)(void *),
2477 void *callback_data)
2478{
2479 LOCK_TAKE(hdw->big_lock); do {
2480 hdw->state_data = callback_data;
2481 hdw->state_func = callback_func;
2482 } while (0); LOCK_GIVE(hdw->big_lock);
2483}
2484
2485
2630/* Return name for this driver instance */ 2486/* Return name for this driver instance */
2631const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw) 2487const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw)
2632{ 2488{
@@ -2634,6 +2490,18 @@ const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw)
2634} 2490}
2635 2491
2636 2492
2493const char *pvr2_hdw_get_desc(struct pvr2_hdw *hdw)
2494{
2495 return hdw->hdw_desc->description;
2496}
2497
2498
2499const char *pvr2_hdw_get_type(struct pvr2_hdw *hdw)
2500{
2501 return hdw->hdw_desc->shortname;
2502}
2503
2504
2637int pvr2_hdw_is_hsm(struct pvr2_hdw *hdw) 2505int pvr2_hdw_is_hsm(struct pvr2_hdw *hdw)
2638{ 2506{
2639 int result; 2507 int result;
@@ -2689,6 +2557,7 @@ void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw)
2689 pvr2_i2c_core_sync(hdw); 2557 pvr2_i2c_core_sync(hdw);
2690 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:"); 2558 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:");
2691 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2"); 2559 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2");
2560 pvr2_hdw_state_log_state(hdw);
2692 printk(KERN_INFO "pvrusb2: ================== END STATUS CARD #%d ==================\n", nr); 2561 printk(KERN_INFO "pvrusb2: ================== END STATUS CARD #%d ==================\n", nr);
2693 } while (0); LOCK_GIVE(hdw->big_lock); 2562 } while (0); LOCK_GIVE(hdw->big_lock);
2694} 2563}
@@ -2959,7 +2828,7 @@ static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
2959 " without lock!!"); 2828 " without lock!!");
2960 return -EDEADLK; 2829 return -EDEADLK;
2961 } 2830 }
2962 if ((!hdw->flag_ok) && !probe_fl) { 2831 if (!hdw->flag_ok && !probe_fl) {
2963 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 2832 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2964 "Attempted to execute control transfer" 2833 "Attempted to execute control transfer"
2965 " when device not ok"); 2834 " when device not ok");
@@ -3167,7 +3036,7 @@ static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
3167 3036
3168 hdw->cmd_debug_state = 0; 3037 hdw->cmd_debug_state = 0;
3169 if ((status < 0) && (!probe_fl)) { 3038 if ((status < 0) && (!probe_fl)) {
3170 pvr2_hdw_render_useless_unlocked(hdw); 3039 pvr2_hdw_render_useless(hdw);
3171 } 3040 }
3172 return status; 3041 return status;
3173} 3042}
@@ -3227,24 +3096,17 @@ static int pvr2_read_register(struct pvr2_hdw *hdw, u16 reg, u32 *data)
3227} 3096}
3228 3097
3229 3098
3230static void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *hdw) 3099void pvr2_hdw_render_useless(struct pvr2_hdw *hdw)
3231{ 3100{
3232 if (!hdw->flag_ok) return; 3101 if (!hdw->flag_ok) return;
3233 pvr2_trace(PVR2_TRACE_INIT,"render_useless"); 3102 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
3234 hdw->flag_ok = 0; 3103 "Device being rendered inoperable");
3235 if (hdw->vid_stream) { 3104 if (hdw->vid_stream) {
3236 pvr2_stream_setup(hdw->vid_stream,NULL,0,0); 3105 pvr2_stream_setup(hdw->vid_stream,NULL,0,0);
3237 } 3106 }
3238 hdw->flag_streaming_enabled = 0; 3107 hdw->flag_ok = 0;
3239 hdw->subsys_enabled_mask = 0; 3108 trace_stbit("flag_ok",hdw->flag_ok);
3240} 3109 pvr2_hdw_state_sched(hdw);
3241
3242
3243void pvr2_hdw_render_useless(struct pvr2_hdw *hdw)
3244{
3245 LOCK_TAKE(hdw->ctl_lock);
3246 pvr2_hdw_render_useless_unlocked(hdw);
3247 LOCK_GIVE(hdw->ctl_lock);
3248} 3110}
3249 3111
3250 3112
@@ -3299,7 +3161,6 @@ int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *hdw)
3299 int status; 3161 int status;
3300 LOCK_TAKE(hdw->ctl_lock); do { 3162 LOCK_TAKE(hdw->ctl_lock); do {
3301 pvr2_trace(PVR2_TRACE_INIT,"Requesting uproc hard reset"); 3163 pvr2_trace(PVR2_TRACE_INIT,"Requesting uproc hard reset");
3302 hdw->flag_ok = !0;
3303 hdw->cmd_buffer[0] = FX2CMD_DEEP_RESET; 3164 hdw->cmd_buffer[0] = FX2CMD_DEEP_RESET;
3304 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0); 3165 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
3305 } while (0); LOCK_GIVE(hdw->ctl_lock); 3166 } while (0); LOCK_GIVE(hdw->ctl_lock);
@@ -3349,26 +3210,473 @@ static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl)
3349 (runFl ? FX2CMD_STREAMING_ON : FX2CMD_STREAMING_OFF); 3210 (runFl ? FX2CMD_STREAMING_ON : FX2CMD_STREAMING_OFF);
3350 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0); 3211 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
3351 } while (0); LOCK_GIVE(hdw->ctl_lock); 3212 } while (0); LOCK_GIVE(hdw->ctl_lock);
3352 if (!status) {
3353 hdw->subsys_enabled_mask =
3354 ((hdw->subsys_enabled_mask &
3355 ~(1<<PVR2_SUBSYS_B_USBSTREAM_RUN)) |
3356 (runFl ? (1<<PVR2_SUBSYS_B_USBSTREAM_RUN) : 0));
3357 }
3358 return status; 3213 return status;
3359} 3214}
3360 3215
3361 3216
3362void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw, 3217/* Evaluate whether or not state_encoder_ok can change */
3363 struct pvr2_hdw_debug_info *ptr) 3218static int state_eval_encoder_ok(struct pvr2_hdw *hdw)
3219{
3220 if (hdw->state_encoder_ok) return 0;
3221 if (hdw->flag_tripped) return 0;
3222 if (hdw->state_encoder_run) return 0;
3223 if (hdw->state_encoder_config) return 0;
3224 if (hdw->state_decoder_run) return 0;
3225 if (hdw->state_usbstream_run) return 0;
3226 if (pvr2_upload_firmware2(hdw) < 0) {
3227 hdw->flag_tripped = !0;
3228 trace_stbit("flag_tripped",hdw->flag_tripped);
3229 return !0;
3230 }
3231 hdw->state_encoder_ok = !0;
3232 trace_stbit("state_encoder_ok",hdw->state_encoder_ok);
3233 return !0;
3234}
3235
3236
3237/* Evaluate whether or not state_encoder_config can change */
3238static int state_eval_encoder_config(struct pvr2_hdw *hdw)
3239{
3240 if (hdw->state_encoder_config) {
3241 if (hdw->state_encoder_ok) {
3242 if (hdw->state_pipeline_req &&
3243 !hdw->state_pipeline_pause) return 0;
3244 }
3245 hdw->state_encoder_config = 0;
3246 hdw->state_encoder_waitok = 0;
3247 trace_stbit("state_encoder_waitok",hdw->state_encoder_waitok);
3248 /* paranoia - solve race if timer just completed */
3249 del_timer_sync(&hdw->encoder_wait_timer);
3250 } else {
3251 if (!hdw->state_encoder_ok ||
3252 !hdw->state_pipeline_idle ||
3253 hdw->state_pipeline_pause ||
3254 !hdw->state_pipeline_req ||
3255 !hdw->state_pipeline_config) {
3256 /* We must reset the enforced wait interval if
3257 anything has happened that might have disturbed
3258 the encoder. This should be a rare case. */
3259 if (timer_pending(&hdw->encoder_wait_timer)) {
3260 del_timer_sync(&hdw->encoder_wait_timer);
3261 }
3262 if (hdw->state_encoder_waitok) {
3263 /* Must clear the state - therefore we did
3264 something to a state bit and must also
3265 return true. */
3266 hdw->state_encoder_waitok = 0;
3267 trace_stbit("state_encoder_waitok",
3268 hdw->state_encoder_waitok);
3269 return !0;
3270 }
3271 return 0;
3272 }
3273 if (!hdw->state_encoder_waitok) {
3274 if (!timer_pending(&hdw->encoder_wait_timer)) {
3275 /* waitok flag wasn't set and timer isn't
3276 running. Check flag once more to avoid
3277 a race then start the timer. This is
3278 the point when we measure out a minimal
3279 quiet interval before doing something to
3280 the encoder. */
3281 if (!hdw->state_encoder_waitok) {
3282 hdw->encoder_wait_timer.expires =
3283 jiffies + (HZ*50/1000);
3284 add_timer(&hdw->encoder_wait_timer);
3285 }
3286 }
3287 /* We can't continue until we know we have been
3288 quiet for the interval measured by this
3289 timer. */
3290 return 0;
3291 }
3292 pvr2_encoder_configure(hdw);
3293 if (hdw->state_encoder_ok) hdw->state_encoder_config = !0;
3294 }
3295 trace_stbit("state_encoder_config",hdw->state_encoder_config);
3296 return !0;
3297}
3298
3299
3300/* Evaluate whether or not state_encoder_run can change */
3301static int state_eval_encoder_run(struct pvr2_hdw *hdw)
3302{
3303 if (hdw->state_encoder_run) {
3304 if (hdw->state_encoder_ok) {
3305 if (hdw->state_decoder_run) return 0;
3306 if (pvr2_encoder_stop(hdw) < 0) return !0;
3307 }
3308 hdw->state_encoder_run = 0;
3309 } else {
3310 if (!hdw->state_encoder_ok) return 0;
3311 if (!hdw->state_decoder_run) return 0;
3312 if (pvr2_encoder_start(hdw) < 0) return !0;
3313 hdw->state_encoder_run = !0;
3314 }
3315 trace_stbit("state_encoder_run",hdw->state_encoder_run);
3316 return !0;
3317}
3318
3319
3320/* Timeout function for quiescent timer. */
3321static void pvr2_hdw_quiescent_timeout(unsigned long data)
3322{
3323 struct pvr2_hdw *hdw = (struct pvr2_hdw *)data;
3324 hdw->state_decoder_quiescent = !0;
3325 trace_stbit("state_decoder_quiescent",hdw->state_decoder_quiescent);
3326 hdw->state_stale = !0;
3327 queue_work(hdw->workqueue,&hdw->workpoll);
3328}
3329
3330
3331/* Timeout function for encoder wait timer. */
3332static void pvr2_hdw_encoder_wait_timeout(unsigned long data)
3333{
3334 struct pvr2_hdw *hdw = (struct pvr2_hdw *)data;
3335 hdw->state_encoder_waitok = !0;
3336 trace_stbit("state_encoder_waitok",hdw->state_encoder_waitok);
3337 hdw->state_stale = !0;
3338 queue_work(hdw->workqueue,&hdw->workpoll);
3339}
3340
3341
3342/* Evaluate whether or not state_decoder_run can change */
3343static int state_eval_decoder_run(struct pvr2_hdw *hdw)
3344{
3345 if (hdw->state_decoder_run) {
3346 if (hdw->state_encoder_ok) {
3347 if (hdw->state_pipeline_req &&
3348 !hdw->state_pipeline_pause) return 0;
3349 }
3350 if (!hdw->flag_decoder_missed) {
3351 pvr2_decoder_enable(hdw,0);
3352 }
3353 hdw->state_decoder_quiescent = 0;
3354 hdw->state_decoder_run = 0;
3355 /* paranoia - solve race if timer just completed */
3356 del_timer_sync(&hdw->quiescent_timer);
3357 } else {
3358 if (!hdw->state_decoder_quiescent) {
3359 if (!timer_pending(&hdw->quiescent_timer)) {
3360 /* We don't do something about the
3361 quiescent timer until right here because
3362 we also want to catch cases where the
3363 decoder was already not running (like
3364 after initialization) as opposed to
3365 knowing that we had just stopped it.
3366 The second flag check is here to cover a
3367 race - the timer could have run and set
3368 this flag just after the previous check
3369 but before we did the pending check. */
3370 if (!hdw->state_decoder_quiescent) {
3371 hdw->quiescent_timer.expires =
3372 jiffies + (HZ*50/1000);
3373 add_timer(&hdw->quiescent_timer);
3374 }
3375 }
3376 /* Don't allow decoder to start again until it has
3377 been quiesced first. This little detail should
3378 hopefully further stabilize the encoder. */
3379 return 0;
3380 }
3381 if (!hdw->state_pipeline_req ||
3382 hdw->state_pipeline_pause ||
3383 !hdw->state_pipeline_config ||
3384 !hdw->state_encoder_config ||
3385 !hdw->state_encoder_ok) return 0;
3386 del_timer_sync(&hdw->quiescent_timer);
3387 if (hdw->flag_decoder_missed) return 0;
3388 if (pvr2_decoder_enable(hdw,!0) < 0) return 0;
3389 hdw->state_decoder_quiescent = 0;
3390 hdw->state_decoder_run = !0;
3391 }
3392 trace_stbit("state_decoder_quiescent",hdw->state_decoder_quiescent);
3393 trace_stbit("state_decoder_run",hdw->state_decoder_run);
3394 return !0;
3395}
3396
3397
3398/* Evaluate whether or not state_usbstream_run can change */
3399static int state_eval_usbstream_run(struct pvr2_hdw *hdw)
3400{
3401 if (hdw->state_usbstream_run) {
3402 if (hdw->state_encoder_ok) {
3403 if (hdw->state_encoder_run) return 0;
3404 }
3405 pvr2_hdw_cmd_usbstream(hdw,0);
3406 hdw->state_usbstream_run = 0;
3407 } else {
3408 if (!hdw->state_encoder_ok ||
3409 !hdw->state_encoder_run ||
3410 !hdw->state_pipeline_req ||
3411 hdw->state_pipeline_pause) return 0;
3412 if (pvr2_hdw_cmd_usbstream(hdw,!0) < 0) return 0;
3413 hdw->state_usbstream_run = !0;
3414 }
3415 trace_stbit("state_usbstream_run",hdw->state_usbstream_run);
3416 return !0;
3417}
3418
3419
3420/* Attempt to configure pipeline, if needed */
3421static int state_eval_pipeline_config(struct pvr2_hdw *hdw)
3422{
3423 if (hdw->state_pipeline_config ||
3424 hdw->state_pipeline_pause) return 0;
3425 pvr2_hdw_commit_execute(hdw);
3426 return !0;
3427}
3428
3429
3430/* Update pipeline idle and pipeline pause tracking states based on other
3431 inputs. This must be called whenever the other relevant inputs have
3432 changed. */
3433static int state_update_pipeline_state(struct pvr2_hdw *hdw)
3434{
3435 unsigned int st;
3436 int updatedFl = 0;
3437 /* Update pipeline state */
3438 st = !(hdw->state_encoder_run ||
3439 hdw->state_decoder_run ||
3440 hdw->state_usbstream_run ||
3441 (!hdw->state_decoder_quiescent));
3442 if (!st != !hdw->state_pipeline_idle) {
3443 hdw->state_pipeline_idle = st;
3444 updatedFl = !0;
3445 }
3446 if (hdw->state_pipeline_idle && hdw->state_pipeline_pause) {
3447 hdw->state_pipeline_pause = 0;
3448 updatedFl = !0;
3449 }
3450 return updatedFl;
3451}
3452
3453
3454typedef int (*state_eval_func)(struct pvr2_hdw *);
3455
3456/* Set of functions to be run to evaluate various states in the driver. */
3457const static state_eval_func eval_funcs[] = {
3458 state_eval_pipeline_config,
3459 state_eval_encoder_ok,
3460 state_eval_encoder_config,
3461 state_eval_decoder_run,
3462 state_eval_encoder_run,
3463 state_eval_usbstream_run,
3464};
3465
3466
3467/* Process various states and return true if we did anything interesting. */
3468static int pvr2_hdw_state_update(struct pvr2_hdw *hdw)
3469{
3470 unsigned int i;
3471 int state_updated = 0;
3472 int check_flag;
3473
3474 if (!hdw->state_stale) return 0;
3475 if ((hdw->fw1_state != FW1_STATE_OK) ||
3476 !hdw->flag_ok) {
3477 hdw->state_stale = 0;
3478 return !0;
3479 }
3480 /* This loop is the heart of the entire driver. It keeps trying to
3481 evaluate various bits of driver state until nothing changes for
3482 one full iteration. Each "bit of state" tracks some global
3483 aspect of the driver, e.g. whether decoder should run, if
3484 pipeline is configured, usb streaming is on, etc. We separately
3485 evaluate each of those questions based on other driver state to
3486 arrive at the correct running configuration. */
3487 do {
3488 check_flag = 0;
3489 state_update_pipeline_state(hdw);
3490 /* Iterate over each bit of state */
3491 for (i = 0; (i<ARRAY_SIZE(eval_funcs)) && hdw->flag_ok; i++) {
3492 if ((*eval_funcs[i])(hdw)) {
3493 check_flag = !0;
3494 state_updated = !0;
3495 state_update_pipeline_state(hdw);
3496 }
3497 }
3498 } while (check_flag && hdw->flag_ok);
3499 hdw->state_stale = 0;
3500 trace_stbit("state_stale",hdw->state_stale);
3501 return state_updated;
3502}
3503
3504
3505static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
3506 char *buf,unsigned int acnt)
3507{
3508 switch (which) {
3509 case 0:
3510 return scnprintf(
3511 buf,acnt,
3512 "driver:%s%s%s%s%s",
3513 (hdw->flag_ok ? " <ok>" : " <fail>"),
3514 (hdw->flag_init_ok ? " <init>" : " <uninitialized>"),
3515 (hdw->flag_disconnected ? " <disconnected>" :
3516 " <connected>"),
3517 (hdw->flag_tripped ? " <tripped>" : ""),
3518 (hdw->flag_decoder_missed ? " <no decoder>" : ""));
3519 case 1:
3520 return scnprintf(
3521 buf,acnt,
3522 "pipeline:%s%s%s%s",
3523 (hdw->state_pipeline_idle ? " <idle>" : ""),
3524 (hdw->state_pipeline_config ?
3525 " <configok>" : " <stale>"),
3526 (hdw->state_pipeline_req ? " <req>" : ""),
3527 (hdw->state_pipeline_pause ? " <pause>" : ""));
3528 case 2:
3529 return scnprintf(
3530 buf,acnt,
3531 "worker:%s%s%s%s%s%s",
3532 (hdw->state_decoder_run ?
3533 " <decode:run>" :
3534 (hdw->state_decoder_quiescent ?
3535 "" : " <decode:stop>")),
3536 (hdw->state_decoder_quiescent ?
3537 " <decode:quiescent>" : ""),
3538 (hdw->state_encoder_ok ?
3539 "" : " <encode:init>"),
3540 (hdw->state_encoder_run ?
3541 " <encode:run>" : " <encode:stop>"),
3542 (hdw->state_encoder_config ?
3543 " <encode:configok>" :
3544 (hdw->state_encoder_waitok ?
3545 "" : " <encode:wait>")),
3546 (hdw->state_usbstream_run ?
3547 " <usb:run>" : " <usb:stop>"));
3548 break;
3549 case 3:
3550 return scnprintf(
3551 buf,acnt,
3552 "state: %s",
3553 pvr2_get_state_name(hdw->master_state));
3554 break;
3555 default: break;
3556 }
3557 return 0;
3558}
3559
3560
3561unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
3562 char *buf,unsigned int acnt)
3563{
3564 unsigned int bcnt,ccnt,idx;
3565 bcnt = 0;
3566 LOCK_TAKE(hdw->big_lock);
3567 for (idx = 0; ; idx++) {
3568 ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,acnt);
3569 if (!ccnt) break;
3570 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
3571 if (!acnt) break;
3572 buf[0] = '\n'; ccnt = 1;
3573 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
3574 }
3575 LOCK_GIVE(hdw->big_lock);
3576 return bcnt;
3577}
3578
3579
3580static void pvr2_hdw_state_log_state(struct pvr2_hdw *hdw)
3581{
3582 char buf[128];
3583 unsigned int idx,ccnt;
3584
3585 for (idx = 0; ; idx++) {
3586 ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,sizeof(buf));
3587 if (!ccnt) break;
3588 printk(KERN_INFO "%s %.*s\n",hdw->name,ccnt,buf);
3589 }
3590}
3591
3592
3593/* Evaluate and update the driver's current state, taking various actions
3594 as appropriate for the update. */
3595static int pvr2_hdw_state_eval(struct pvr2_hdw *hdw)
3596{
3597 unsigned int st;
3598 int state_updated = 0;
3599 int callback_flag = 0;
3600
3601 pvr2_trace(PVR2_TRACE_STBITS,
3602 "Drive state check START");
3603 if (pvrusb2_debug & PVR2_TRACE_STBITS) {
3604 pvr2_hdw_state_log_state(hdw);
3605 }
3606
3607 /* Process all state and get back over disposition */
3608 state_updated = pvr2_hdw_state_update(hdw);
3609
3610 /* Update master state based upon all other states. */
3611 if (!hdw->flag_ok) {
3612 st = PVR2_STATE_DEAD;
3613 } else if (hdw->fw1_state != FW1_STATE_OK) {
3614 st = PVR2_STATE_COLD;
3615 } else if (!hdw->state_encoder_ok) {
3616 st = PVR2_STATE_WARM;
3617 } else if (hdw->flag_tripped || hdw->flag_decoder_missed) {
3618 st = PVR2_STATE_ERROR;
3619 } else if (hdw->state_encoder_run &&
3620 hdw->state_decoder_run &&
3621 hdw->state_usbstream_run) {
3622 st = PVR2_STATE_RUN;
3623 } else {
3624 st = PVR2_STATE_READY;
3625 }
3626 if (hdw->master_state != st) {
3627 pvr2_trace(PVR2_TRACE_STATE,
3628 "Device state change from %s to %s",
3629 pvr2_get_state_name(hdw->master_state),
3630 pvr2_get_state_name(st));
3631 hdw->master_state = st;
3632 state_updated = !0;
3633 callback_flag = !0;
3634 }
3635 if (state_updated) {
3636 /* Trigger anyone waiting on any state changes here. */
3637 wake_up(&hdw->state_wait_data);
3638 }
3639
3640 if (pvrusb2_debug & PVR2_TRACE_STBITS) {
3641 pvr2_hdw_state_log_state(hdw);
3642 }
3643 pvr2_trace(PVR2_TRACE_STBITS,
3644 "Drive state check DONE callback=%d",callback_flag);
3645
3646 return callback_flag;
3647}
3648
3649
3650/* Cause kernel thread to check / update driver state */
3651static void pvr2_hdw_state_sched(struct pvr2_hdw *hdw)
3652{
3653 if (hdw->state_stale) return;
3654 hdw->state_stale = !0;
3655 trace_stbit("state_stale",hdw->state_stale);
3656 queue_work(hdw->workqueue,&hdw->workpoll);
3657}
3658
3659
3660void pvr2_hdw_get_debug_info_unlocked(const struct pvr2_hdw *hdw,
3661 struct pvr2_hdw_debug_info *ptr)
3364{ 3662{
3365 ptr->big_lock_held = hdw->big_lock_held; 3663 ptr->big_lock_held = hdw->big_lock_held;
3366 ptr->ctl_lock_held = hdw->ctl_lock_held; 3664 ptr->ctl_lock_held = hdw->ctl_lock_held;
3367 ptr->flag_ok = hdw->flag_ok;
3368 ptr->flag_disconnected = hdw->flag_disconnected; 3665 ptr->flag_disconnected = hdw->flag_disconnected;
3369 ptr->flag_init_ok = hdw->flag_init_ok; 3666 ptr->flag_init_ok = hdw->flag_init_ok;
3370 ptr->flag_streaming_enabled = hdw->flag_streaming_enabled; 3667 ptr->flag_ok = hdw->flag_ok;
3371 ptr->subsys_flags = hdw->subsys_enabled_mask; 3668 ptr->fw1_state = hdw->fw1_state;
3669 ptr->flag_decoder_missed = hdw->flag_decoder_missed;
3670 ptr->flag_tripped = hdw->flag_tripped;
3671 ptr->state_encoder_ok = hdw->state_encoder_ok;
3672 ptr->state_encoder_run = hdw->state_encoder_run;
3673 ptr->state_decoder_run = hdw->state_decoder_run;
3674 ptr->state_usbstream_run = hdw->state_usbstream_run;
3675 ptr->state_decoder_quiescent = hdw->state_decoder_quiescent;
3676 ptr->state_pipeline_config = hdw->state_pipeline_config;
3677 ptr->state_pipeline_req = hdw->state_pipeline_req;
3678 ptr->state_pipeline_pause = hdw->state_pipeline_pause;
3679 ptr->state_pipeline_idle = hdw->state_pipeline_idle;
3372 ptr->cmd_debug_state = hdw->cmd_debug_state; 3680 ptr->cmd_debug_state = hdw->cmd_debug_state;
3373 ptr->cmd_code = hdw->cmd_debug_code; 3681 ptr->cmd_code = hdw->cmd_debug_code;
3374 ptr->cmd_debug_write_len = hdw->cmd_debug_write_len; 3682 ptr->cmd_debug_write_len = hdw->cmd_debug_write_len;
@@ -3381,6 +3689,15 @@ void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw,
3381} 3689}
3382 3690
3383 3691
3692void pvr2_hdw_get_debug_info_locked(struct pvr2_hdw *hdw,
3693 struct pvr2_hdw_debug_info *ptr)
3694{
3695 LOCK_TAKE(hdw->ctl_lock); do {
3696 pvr2_hdw_get_debug_info_unlocked(hdw,ptr);
3697 } while(0); LOCK_GIVE(hdw->ctl_lock);
3698}
3699
3700
3384int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *dp) 3701int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *dp)
3385{ 3702{
3386 return pvr2_read_register(hdw,PVR2_GPIO_DIR,dp); 3703 return pvr2_read_register(hdw,PVR2_GPIO_DIR,dp);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.h b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
index e2f9d5e4cb65..3ad7a13d6c39 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
@@ -44,27 +44,6 @@
44#define PVR2_CVAL_INPUT_COMPOSITE 2 44#define PVR2_CVAL_INPUT_COMPOSITE 2
45#define PVR2_CVAL_INPUT_RADIO 3 45#define PVR2_CVAL_INPUT_RADIO 3
46 46
47/* Subsystem definitions - these are various pieces that can be
48 independently stopped / started. Usually you don't want to mess with
49 this directly (let the driver handle things itself), but it is useful
50 for debugging. */
51#define PVR2_SUBSYS_B_ENC_FIRMWARE 0
52#define PVR2_SUBSYS_B_ENC_CFG 1
53#define PVR2_SUBSYS_B_DIGITIZER_RUN 2
54#define PVR2_SUBSYS_B_USBSTREAM_RUN 3
55#define PVR2_SUBSYS_B_ENC_RUN 4
56
57#define PVR2_SUBSYS_CFG_ALL ( \
58 (1 << PVR2_SUBSYS_B_ENC_FIRMWARE) | \
59 (1 << PVR2_SUBSYS_B_ENC_CFG) )
60#define PVR2_SUBSYS_RUN_ALL ( \
61 (1 << PVR2_SUBSYS_B_DIGITIZER_RUN) | \
62 (1 << PVR2_SUBSYS_B_USBSTREAM_RUN) | \
63 (1 << PVR2_SUBSYS_B_ENC_RUN) )
64#define PVR2_SUBSYS_ALL ( \
65 PVR2_SUBSYS_CFG_ALL | \
66 PVR2_SUBSYS_RUN_ALL )
67
68enum pvr2_config { 47enum pvr2_config {
69 pvr2_config_empty, /* No configuration */ 48 pvr2_config_empty, /* No configuration */
70 pvr2_config_mpeg, /* Encoded / compressed video */ 49 pvr2_config_mpeg, /* Encoded / compressed video */
@@ -79,8 +58,41 @@ enum pvr2_v4l_type {
79 pvr2_v4l_type_radio, 58 pvr2_v4l_type_radio,
80}; 59};
81 60
61/* Major states that we can be in:
62 *
63 * DEAD - Device is in an unusable state and cannot be recovered. This
64 * can happen if we completely lose the ability to communicate with it
65 * (but it might still on the bus). In this state there's nothing we can
66 * do; it must be replugged in order to recover.
67 *
68 * COLD - Device is in an unusuable state, needs microcontroller firmware.
69 *
70 * WARM - We can communicate with the device and the proper
71 * microcontroller firmware is running, but other device initialization is
72 * still needed (e.g. encoder firmware).
73 *
74 * ERROR - A problem prevents capture operation (e.g. encoder firmware
75 * missing).
76 *
77 * READY - Device is operational, but not streaming.
78 *
79 * RUN - Device is streaming.
80 *
81 */
82#define PVR2_STATE_NONE 0
83#define PVR2_STATE_DEAD 1
84#define PVR2_STATE_COLD 2
85#define PVR2_STATE_WARM 3
86#define PVR2_STATE_ERROR 4
87#define PVR2_STATE_READY 5
88#define PVR2_STATE_RUN 6
89
90/* Translate configuration enum to a string label */
82const char *pvr2_config_get_name(enum pvr2_config); 91const char *pvr2_config_get_name(enum pvr2_config);
83 92
93/* Translate a master state enum to a string label */
94const char *pvr2_hdw_get_state_name(unsigned int);
95
84struct pvr2_hdw; 96struct pvr2_hdw;
85 97
86/* Create and return a structure for interacting with the underlying 98/* Create and return a structure for interacting with the underlying
@@ -88,28 +100,13 @@ struct pvr2_hdw;
88struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, 100struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
89 const struct usb_device_id *devid); 101 const struct usb_device_id *devid);
90 102
91/* Poll for background activity (if any) */
92void pvr2_hdw_poll(struct pvr2_hdw *);
93
94/* Trigger a poll to take place later at a convenient time */
95void pvr2_hdw_poll_trigger_unlocked(struct pvr2_hdw *);
96
97/* Register a callback used to trigger a future poll */
98void pvr2_hdw_setup_poll_trigger(struct pvr2_hdw *,
99 void (*func)(void *),
100 void *data);
101
102/* Destroy hardware interaction structure */ 103/* Destroy hardware interaction structure */
103void pvr2_hdw_destroy(struct pvr2_hdw *); 104void pvr2_hdw_destroy(struct pvr2_hdw *);
104 105
105/* Set up the structure and attempt to put the device into a usable state. 106/* Register a function to be called whenever the master state changes. */
106 This can be a time-consuming operation, which is why it is not done 107void pvr2_hdw_set_state_callback(struct pvr2_hdw *,
107 internally as part of the create() step. Return value is exactly the 108 void (*callback_func)(void *),
108 same as pvr2_hdw_init_ok(). */ 109 void *callback_data);
109int pvr2_hdw_setup(struct pvr2_hdw *);
110
111/* Initialization succeeded */
112int pvr2_hdw_init_ok(struct pvr2_hdw *);
113 110
114/* Return true if in the ready (normal) state */ 111/* Return true if in the ready (normal) state */
115int pvr2_hdw_dev_ok(struct pvr2_hdw *); 112int pvr2_hdw_dev_ok(struct pvr2_hdw *);
@@ -161,12 +158,21 @@ int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
161/* Query device and see if it thinks it is on a high-speed USB link */ 158/* Query device and see if it thinks it is on a high-speed USB link */
162int pvr2_hdw_is_hsm(struct pvr2_hdw *); 159int pvr2_hdw_is_hsm(struct pvr2_hdw *);
163 160
161/* Return a string token representative of the hardware type */
162const char *pvr2_hdw_get_type(struct pvr2_hdw *);
163
164/* Return a single line description of the hardware type */
165const char *pvr2_hdw_get_desc(struct pvr2_hdw *);
166
164/* Turn streaming on/off */ 167/* Turn streaming on/off */
165int pvr2_hdw_set_streaming(struct pvr2_hdw *,int); 168int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
166 169
167/* Find out if streaming is on */ 170/* Find out if streaming is on */
168int pvr2_hdw_get_streaming(struct pvr2_hdw *); 171int pvr2_hdw_get_streaming(struct pvr2_hdw *);
169 172
173/* Retrieve driver overall state */
174int pvr2_hdw_get_state(struct pvr2_hdw *);
175
170/* Configure the type of stream to generate */ 176/* Configure the type of stream to generate */
171int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config); 177int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
172 178
@@ -177,26 +183,6 @@ struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
177int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std, 183int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
178 unsigned int idx); 184 unsigned int idx);
179 185
180/* Enable / disable various pieces of hardware. Items to change are
181 identified by bit positions within msk, and new state for each item is
182 identified by corresponding bit positions within val. */
183void pvr2_hdw_subsys_bit_chg(struct pvr2_hdw *hdw,
184 unsigned long msk,unsigned long val);
185
186/* Retrieve mask indicating which pieces of hardware are currently enabled
187 / configured. */
188unsigned long pvr2_hdw_subsys_get(struct pvr2_hdw *);
189
190/* Adjust mask of what get shut down when streaming is stopped. This is a
191 debugging aid. */
192void pvr2_hdw_subsys_stream_bit_chg(struct pvr2_hdw *hdw,
193 unsigned long msk,unsigned long val);
194
195/* Retrieve mask indicating which pieces of hardware are disabled when
196 streaming is turned off. */
197unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *);
198
199
200/* Enable / disable retrieval of CPU firmware or prom contents. This must 186/* Enable / disable retrieval of CPU firmware or prom contents. This must
201 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing 187 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing
202 this may prevent the device from running (and leaving this mode may 188 this may prevent the device from running (and leaving this mode may
@@ -253,6 +239,9 @@ void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
253/* Execute a USB-commanded device reset */ 239/* Execute a USB-commanded device reset */
254void pvr2_hdw_device_reset(struct pvr2_hdw *); 240void pvr2_hdw_device_reset(struct pvr2_hdw *);
255 241
242/* Reset worker's error trapping circuit breaker */
243int pvr2_hdw_untrip(struct pvr2_hdw *);
244
256/* Execute hard reset command (after this point it's likely that the 245/* Execute hard reset command (after this point it's likely that the
257 encoder will have to be reconfigured). This also clears the "useless" 246 encoder will have to be reconfigured). This also clears the "useless"
258 state. */ 247 state. */
@@ -275,11 +264,21 @@ int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
275struct pvr2_hdw_debug_info { 264struct pvr2_hdw_debug_info {
276 int big_lock_held; 265 int big_lock_held;
277 int ctl_lock_held; 266 int ctl_lock_held;
278 int flag_ok;
279 int flag_disconnected; 267 int flag_disconnected;
280 int flag_init_ok; 268 int flag_init_ok;
281 int flag_streaming_enabled; 269 int flag_ok;
282 unsigned long subsys_flags; 270 int fw1_state;
271 int flag_decoder_missed;
272 int flag_tripped;
273 int state_encoder_ok;
274 int state_encoder_run;
275 int state_decoder_run;
276 int state_usbstream_run;
277 int state_decoder_quiescent;
278 int state_pipeline_config;
279 int state_pipeline_req;
280 int state_pipeline_pause;
281 int state_pipeline_idle;
283 int cmd_debug_state; 282 int cmd_debug_state;
284 int cmd_debug_write_len; 283 int cmd_debug_write_len;
285 int cmd_debug_read_len; 284 int cmd_debug_read_len;
@@ -295,8 +294,20 @@ struct pvr2_hdw_debug_info {
295 diagnosing lockups. Note that this operation is completed without any 294 diagnosing lockups. Note that this operation is completed without any
296 kind of locking and so it is not atomic and may yield inconsistent 295 kind of locking and so it is not atomic and may yield inconsistent
297 results. This is *purely* a debugging aid. */ 296 results. This is *purely* a debugging aid. */
298void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw, 297void pvr2_hdw_get_debug_info_unlocked(const struct pvr2_hdw *hdw,
299 struct pvr2_hdw_debug_info *); 298 struct pvr2_hdw_debug_info *);
299
300/* Intrusively retrieve internal state info - this is useful for
301 diagnosing overall driver state. This operation synchronizes against
302 the overall driver mutex - so if there are locking problems this will
303 likely hang! This is *purely* a debugging aid. */
304void pvr2_hdw_get_debug_info_locked(struct pvr2_hdw *hdw,
305 struct pvr2_hdw_debug_info *);
306
307/* Report out several lines of text that describes driver internal state.
308 Results are written into the passed-in buffer. */
309unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
310 char *buf_ptr,unsigned int buf_size);
300 311
301/* Cause modules to log their state once */ 312/* Cause modules to log their state once */
302void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw); 313void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
@@ -306,9 +317,6 @@ void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
306 a debugging aid. */ 317 a debugging aid. */
307int pvr2_upload_firmware2(struct pvr2_hdw *hdw); 318int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
308 319
309/* List of device types that we can match */
310extern struct usb_device_id pvr2_device_table[];
311
312#endif /* __PVRUSB2_HDW_H */ 320#endif /* __PVRUSB2_HDW_H */
313 321
314/* 322/*
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index c817c864e6a0..62867fa3517a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -895,7 +895,7 @@ static int pvr2_i2c_attach_inform(struct i2c_client *client)
895 list_add_tail(&cp->list,&hdw->i2c_clients); 895 list_add_tail(&cp->list,&hdw->i2c_clients);
896 hdw->i2c_pend_types |= PVR2_I2C_PEND_DETECT; 896 hdw->i2c_pend_types |= PVR2_I2C_PEND_DETECT;
897 } while (0); mutex_unlock(&hdw->i2c_list_lock); 897 } while (0); mutex_unlock(&hdw->i2c_list_lock);
898 if (fl) pvr2_hdw_poll_trigger_unlocked(hdw); 898 if (fl) queue_work(hdw->workqueue,&hdw->worki2csync);
899 return 0; 899 return 0;
900} 900}
901 901
@@ -980,14 +980,16 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
980 printk(KERN_INFO "%s: IR disabled\n",hdw->name); 980 printk(KERN_INFO "%s: IR disabled\n",hdw->name);
981 hdw->i2c_func[0x18] = i2c_black_hole; 981 hdw->i2c_func[0x18] = i2c_black_hole;
982 } else if (ir_mode[hdw->unit_number] == 1) { 982 } else if (ir_mode[hdw->unit_number] == 1) {
983 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) { 983 if (hdw->hdw_desc->flag_has_hauppauge_custom_ir) {
984 hdw->i2c_func[0x18] = i2c_24xxx_ir; 984 hdw->i2c_func[0x18] = i2c_24xxx_ir;
985 } 985 }
986 } 986 }
987 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) { 987 if (hdw->hdw_desc->flag_has_cx25840) {
988 hdw->i2c_func[0x1b] = i2c_hack_wm8775;
989 hdw->i2c_func[0x44] = i2c_hack_cx25840; 988 hdw->i2c_func[0x44] = i2c_hack_cx25840;
990 } 989 }
990 if (hdw->hdw_desc->flag_has_wm8775) {
991 hdw->i2c_func[0x1b] = i2c_hack_wm8775;
992 }
991 993
992 // Configure the adapter and set up everything else related to it. 994 // Configure the adapter and set up everything else related to it.
993 memcpy(&hdw->i2c_adap,&pvr2_i2c_adap_template,sizeof(hdw->i2c_adap)); 995 memcpy(&hdw->i2c_adap,&pvr2_i2c_adap_template,sizeof(hdw->i2c_adap));
diff --git a/drivers/media/video/pvrusb2/pvrusb2-main.c b/drivers/media/video/pvrusb2/pvrusb2-main.c
index 11b3b2e84b90..b63b2265503a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-main.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-main.c
@@ -28,6 +28,7 @@
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29 29
30#include "pvrusb2-hdw.h" 30#include "pvrusb2-hdw.h"
31#include "pvrusb2-devattr.h"
31#include "pvrusb2-context.h" 32#include "pvrusb2-context.h"
32#include "pvrusb2-debug.h" 33#include "pvrusb2-debug.h"
33#include "pvrusb2-v4l2.h" 34#include "pvrusb2-v4l2.h"
@@ -148,11 +149,6 @@ static void __exit pvr_exit(void)
148module_init(pvr_init); 149module_init(pvr_init);
149module_exit(pvr_exit); 150module_exit(pvr_exit);
150 151
151/* Mike Isely <mcisely@pobox.com> 11-Mar-2006: See pvrusb2-hdw.c for
152 MODULE_DEVICE_TABLE(). We have to declare that attribute there
153 because that's where the device table actually is now and it seems
154 that certain gcc configurations get angry if MODULE_DEVICE_TABLE()
155 is used on what ends up being an external symbol. */
156MODULE_AUTHOR(DRIVER_AUTHOR); 152MODULE_AUTHOR(DRIVER_AUTHOR);
157MODULE_DESCRIPTION(DRIVER_DESC); 153MODULE_DESCRIPTION(DRIVER_DESC);
158MODULE_LICENSE("GPL"); 154MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/pvrusb2/pvrusb2-std.c b/drivers/media/video/pvrusb2/pvrusb2-std.c
index 63e55bb59fcb..da309288daa4 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-std.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-std.c
@@ -50,6 +50,10 @@ struct std_name {
50 V4L2_STD_NTSC_M_KR| \ 50 V4L2_STD_NTSC_M_KR| \
51 V4L2_STD_NTSC_443) 51 V4L2_STD_NTSC_443)
52 52
53#define CSTD_ATSC \
54 (V4L2_STD_ATSC_8_VSB| \
55 V4L2_STD_ATSC_16_VSB)
56
53#define CSTD_SECAM \ 57#define CSTD_SECAM \
54 (V4L2_STD_SECAM_B| \ 58 (V4L2_STD_SECAM_B| \
55 V4L2_STD_SECAM_D| \ 59 V4L2_STD_SECAM_D| \
@@ -82,6 +86,7 @@ static const struct std_name std_groups[] = {
82 {"PAL",CSTD_PAL}, 86 {"PAL",CSTD_PAL},
83 {"NTSC",CSTD_NTSC}, 87 {"NTSC",CSTD_NTSC},
84 {"SECAM",CSTD_SECAM}, 88 {"SECAM",CSTD_SECAM},
89 {"ATSC",CSTD_ATSC},
85}; 90};
86 91
87/* Mapping of standard bits to modulation system */ 92/* Mapping of standard bits to modulation system */
@@ -104,6 +109,8 @@ static const struct std_name std_items[] = {
104 {"N",TSTD_N}, 109 {"N",TSTD_N},
105 {"Nc",TSTD_Nc}, 110 {"Nc",TSTD_Nc},
106 {"60",TSTD_60}, 111 {"60",TSTD_60},
112 {"8VSB",V4L2_STD_ATSC_8_VSB},
113 {"16VSB",V4L2_STD_ATSC_16_VSB},
107}; 114};
108 115
109 116
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index 3c57a7d8200b..7a1cd878e31a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -43,10 +43,14 @@ struct pvr2_sysfs {
43 struct device_attribute attr_v4l_radio_minor_number; 43 struct device_attribute attr_v4l_radio_minor_number;
44 struct device_attribute attr_unit_number; 44 struct device_attribute attr_unit_number;
45 struct device_attribute attr_bus_info; 45 struct device_attribute attr_bus_info;
46 struct device_attribute attr_hdw_name;
47 struct device_attribute attr_hdw_desc;
46 int v4l_minor_number_created_ok; 48 int v4l_minor_number_created_ok;
47 int v4l_radio_minor_number_created_ok; 49 int v4l_radio_minor_number_created_ok;
48 int unit_number_created_ok; 50 int unit_number_created_ok;
49 int bus_info_created_ok; 51 int bus_info_created_ok;
52 int hdw_name_created_ok;
53 int hdw_desc_created_ok;
50}; 54};
51 55
52#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 56#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
@@ -712,6 +716,14 @@ static void class_dev_destroy(struct pvr2_sysfs *sfp)
712 pvr2_sysfs_tear_down_debugifc(sfp); 716 pvr2_sysfs_tear_down_debugifc(sfp);
713#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 717#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
714 pvr2_sysfs_tear_down_controls(sfp); 718 pvr2_sysfs_tear_down_controls(sfp);
719 if (sfp->hdw_desc_created_ok) {
720 device_remove_file(sfp->class_dev,
721 &sfp->attr_hdw_desc);
722 }
723 if (sfp->hdw_name_created_ok) {
724 device_remove_file(sfp->class_dev,
725 &sfp->attr_hdw_name);
726 }
715 if (sfp->bus_info_created_ok) { 727 if (sfp->bus_info_created_ok) {
716 device_remove_file(sfp->class_dev, 728 device_remove_file(sfp->class_dev,
717 &sfp->attr_bus_info); 729 &sfp->attr_bus_info);
@@ -758,6 +770,28 @@ static ssize_t bus_info_show(struct device *class_dev,
758} 770}
759 771
760 772
773static ssize_t hdw_name_show(struct device *class_dev,
774 struct device_attribute *attr, char *buf)
775{
776 struct pvr2_sysfs *sfp;
777 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
778 if (!sfp) return -EINVAL;
779 return scnprintf(buf,PAGE_SIZE,"%s\n",
780 pvr2_hdw_get_type(sfp->channel.hdw));
781}
782
783
784static ssize_t hdw_desc_show(struct device *class_dev,
785 struct device_attribute *attr, char *buf)
786{
787 struct pvr2_sysfs *sfp;
788 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
789 if (!sfp) return -EINVAL;
790 return scnprintf(buf,PAGE_SIZE,"%s\n",
791 pvr2_hdw_get_desc(sfp->channel.hdw));
792}
793
794
761static ssize_t v4l_radio_minor_number_show(struct device *class_dev, 795static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
762 struct device_attribute *attr, 796 struct device_attribute *attr,
763 char *buf) 797 char *buf)
@@ -871,6 +905,32 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
871 sfp->bus_info_created_ok = !0; 905 sfp->bus_info_created_ok = !0;
872 } 906 }
873 907
908 sfp->attr_hdw_name.attr.name = "device_hardware_type";
909 sfp->attr_hdw_name.attr.mode = S_IRUGO;
910 sfp->attr_hdw_name.show = hdw_name_show;
911 sfp->attr_hdw_name.store = NULL;
912 ret = device_create_file(sfp->class_dev,
913 &sfp->attr_hdw_name);
914 if (ret < 0) {
915 printk(KERN_WARNING "%s: device_create_file error: %d\n",
916 __FUNCTION__, ret);
917 } else {
918 sfp->hdw_name_created_ok = !0;
919 }
920
921 sfp->attr_hdw_desc.attr.name = "device_hardware_description";
922 sfp->attr_hdw_desc.attr.mode = S_IRUGO;
923 sfp->attr_hdw_desc.show = hdw_desc_show;
924 sfp->attr_hdw_desc.store = NULL;
925 ret = device_create_file(sfp->class_dev,
926 &sfp->attr_hdw_desc);
927 if (ret < 0) {
928 printk(KERN_WARNING "%s: device_create_file error: %d\n",
929 __FUNCTION__, ret);
930 } else {
931 sfp->hdw_desc_created_ok = !0;
932 }
933
874 pvr2_sysfs_add_controls(sfp); 934 pvr2_sysfs_add_controls(sfp);
875#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 935#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
876 pvr2_sysfs_add_debugifc(sfp); 936 pvr2_sysfs_add_debugifc(sfp);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index 7a596ea7cfe6..8f0587ebd4bd 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -205,6 +205,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
205 memcpy(cap, &pvr_capability, sizeof(struct v4l2_capability)); 205 memcpy(cap, &pvr_capability, sizeof(struct v4l2_capability));
206 strlcpy(cap->bus_info,pvr2_hdw_get_bus_info(hdw), 206 strlcpy(cap->bus_info,pvr2_hdw_get_bus_info(hdw),
207 sizeof(cap->bus_info)); 207 sizeof(cap->bus_info));
208 strlcpy(cap->card,pvr2_hdw_get_desc(hdw),sizeof(cap->card));
208 209
209 ret = 0; 210 ret = 0;
210 break; 211 break;
@@ -1015,10 +1016,8 @@ static int pvr2_v4l2_iosetup(struct pvr2_v4l2_fh *fh)
1015 sp = fh->dev_info->stream->stream; 1016 sp = fh->dev_info->stream->stream;
1016 pvr2_stream_set_callback(sp,(pvr2_stream_callback)pvr2_v4l2_notify,fh); 1017 pvr2_stream_set_callback(sp,(pvr2_stream_callback)pvr2_v4l2_notify,fh);
1017 pvr2_hdw_set_stream_type(hdw,fh->dev_info->config); 1018 pvr2_hdw_set_stream_type(hdw,fh->dev_info->config);
1018 pvr2_hdw_set_streaming(hdw,!0); 1019 if ((ret = pvr2_hdw_set_streaming(hdw,!0)) < 0) return ret;
1019 ret = pvr2_ioread_set_enabled(fh->rhp,!0); 1020 return pvr2_ioread_set_enabled(fh->rhp,!0);
1020
1021 return ret;
1022} 1021}
1023 1022
1024 1023
diff --git a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
index 61efa6f02200..7c47345501b6 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
@@ -49,29 +49,50 @@ struct pvr2_v4l_decoder {
49}; 49};
50 50
51 51
52struct routing_scheme {
53 const int *def;
54 unsigned int cnt;
55};
56
57
58static const int routing_scheme0[] = {
59 [PVR2_CVAL_INPUT_TV] = SAA7115_COMPOSITE4,
60 /* In radio mode, we mute the video, but point at one
61 spot just to stay consistent */
62 [PVR2_CVAL_INPUT_RADIO] = SAA7115_COMPOSITE5,
63 [PVR2_CVAL_INPUT_COMPOSITE] = SAA7115_COMPOSITE5,
64 [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2,
65};
66
67static const struct routing_scheme routing_schemes[] = {
68 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
69 .def = routing_scheme0,
70 .cnt = ARRAY_SIZE(routing_scheme0),
71 },
72};
73
52static void set_input(struct pvr2_v4l_decoder *ctxt) 74static void set_input(struct pvr2_v4l_decoder *ctxt)
53{ 75{
54 struct pvr2_hdw *hdw = ctxt->hdw; 76 struct pvr2_hdw *hdw = ctxt->hdw;
55 struct v4l2_routing route; 77 struct v4l2_routing route;
78 const struct routing_scheme *sp;
79 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
56 80
57 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_input(%d)",hdw->input_val); 81 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_input(%d)",hdw->input_val);
58 switch(hdw->input_val) { 82
59 case PVR2_CVAL_INPUT_TV: 83 if ((sid < ARRAY_SIZE(routing_schemes)) &&
60 route.input = SAA7115_COMPOSITE4; 84 ((sp = routing_schemes + sid) != 0) &&
61 break; 85 (hdw->input_val >= 0) &&
62 case PVR2_CVAL_INPUT_COMPOSITE: 86 (hdw->input_val < sp->cnt)) {
63 route.input = SAA7115_COMPOSITE5; 87 route.input = sp->def[hdw->input_val];
64 break; 88 } else {
65 case PVR2_CVAL_INPUT_SVIDEO: 89 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
66 route.input = SAA7115_SVIDEO2; 90 "*** WARNING *** i2c v4l2 set_input:"
67 break; 91 " Invalid routing scheme (%u) and/or input (%d)",
68 case PVR2_CVAL_INPUT_RADIO: 92 sid,hdw->input_val);
69 // In radio mode, we mute the video, but point at one
70 // spot just to stay consistent
71 route.input = SAA7115_COMPOSITE5;
72 default:
73 return; 93 return;
74 } 94 }
95
75 route.output = 0; 96 route.output = 0;
76 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_VIDEO_ROUTING,&route); 97 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_VIDEO_ROUTING,&route);
77} 98}
@@ -129,7 +150,7 @@ static const struct pvr2_v4l_decoder_ops decoder_ops[] = {
129static void decoder_detach(struct pvr2_v4l_decoder *ctxt) 150static void decoder_detach(struct pvr2_v4l_decoder *ctxt)
130{ 151{
131 ctxt->client->handler = NULL; 152 ctxt->client->handler = NULL;
132 ctxt->hdw->decoder_ctrl = NULL; 153 pvr2_hdw_set_decoder(ctxt->hdw,NULL);
133 kfree(ctxt); 154 kfree(ctxt);
134} 155}
135 156
@@ -217,7 +238,7 @@ int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *hdw,
217 ctxt->client = cp; 238 ctxt->client = cp;
218 ctxt->hdw = hdw; 239 ctxt->hdw = hdw;
219 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1; 240 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
220 hdw->decoder_ctrl = &ctxt->ctrl; 241 pvr2_hdw_set_decoder(hdw,&ctxt->ctrl);
221 cp->handler = &ctxt->handler; 242 cp->handler = &ctxt->handler;
222 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up", 243 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up",
223 cp->client->addr); 244 cp->client->addr);
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index 2d18f0069821..41e5e518a47e 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -46,6 +46,7 @@
46#include <linux/videodev2.h> 46#include <linux/videodev2.h>
47#include <media/v4l2-common.h> 47#include <media/v4l2-common.h>
48#include <media/v4l2-chip-ident.h> 48#include <media/v4l2-chip-ident.h>
49#include <media/v4l2-i2c-drv-legacy.h>
49#include <media/saa7115.h> 50#include <media/saa7115.h>
50#include <asm/div64.h> 51#include <asm/div64.h>
51 52
@@ -1230,7 +1231,7 @@ static void saa711x_decode_vbi_line(struct i2c_client *client,
1230 1231
1231/* ============ SAA7115 AUDIO settings (end) ============= */ 1232/* ============ SAA7115 AUDIO settings (end) ============= */
1232 1233
1233static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *arg) 1234static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *arg)
1234{ 1235{
1235 struct saa711x_state *state = i2c_get_clientdata(client); 1236 struct saa711x_state *state = i2c_get_clientdata(client);
1236 1237
@@ -1449,26 +1450,17 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
1449 1450
1450/* ----------------------------------------------------------------------- */ 1451/* ----------------------------------------------------------------------- */
1451 1452
1452static struct i2c_driver i2c_driver_saa711x; 1453static int saa7115_probe(struct i2c_client *client)
1453
1454static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1455{ 1454{
1456 struct i2c_client *client;
1457 struct saa711x_state *state; 1455 struct saa711x_state *state;
1458 int i; 1456 int i;
1459 char name[17]; 1457 char name[17];
1460 u8 chip_id; 1458 u8 chip_id;
1461 1459
1462 /* Check if the adapter supports the needed features */ 1460 /* Check if the adapter supports the needed features */
1463 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1461 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1464 return 0; 1462 return -EIO;
1465 1463
1466 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
1467 if (client == 0)
1468 return -ENOMEM;
1469 client->addr = address;
1470 client->adapter = adapter;
1471 client->driver = &i2c_driver_saa711x;
1472 snprintf(client->name, sizeof(client->name) - 1, "saa7115"); 1464 snprintf(client->name, sizeof(client->name) - 1, "saa7115");
1473 1465
1474 for (i = 0; i < 0x0f; i++) { 1466 for (i = 0; i < 0x0f; i++) {
@@ -1485,18 +1477,16 @@ static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1485 /* Check whether this chip is part of the saa711x series */ 1477 /* Check whether this chip is part of the saa711x series */
1486 if (memcmp(name, "1f711", 5)) { 1478 if (memcmp(name, "1f711", 5)) {
1487 v4l_dbg(1, debug, client, "chip found @ 0x%x (ID %s) does not match a known saa711x chip.\n", 1479 v4l_dbg(1, debug, client, "chip found @ 0x%x (ID %s) does not match a known saa711x chip.\n",
1488 address << 1, name); 1480 client->addr << 1, name);
1489 kfree(client); 1481 return -ENODEV;
1490 return 0;
1491 } 1482 }
1492 1483
1493 snprintf(client->name, sizeof(client->name) - 1, "saa711%d",chip_id); 1484 snprintf(client->name, sizeof(client->name) - 1, "saa711%d",chip_id);
1494 v4l_info(client, "saa711%d found (%s) @ 0x%x (%s)\n", chip_id, name, address << 1, adapter->name); 1485 v4l_info(client, "saa711%d found (%s) @ 0x%x (%s)\n", chip_id, name, client->addr << 1, client->adapter->name);
1495 1486
1496 state = kzalloc(sizeof(struct saa711x_state), GFP_KERNEL); 1487 state = kzalloc(sizeof(struct saa711x_state), GFP_KERNEL);
1497 i2c_set_clientdata(client, state); 1488 i2c_set_clientdata(client, state);
1498 if (state == NULL) { 1489 if (state == NULL) {
1499 kfree(client);
1500 return -ENOMEM; 1490 return -ENOMEM;
1501 } 1491 }
1502 state->input = -1; 1492 state->input = -1;
@@ -1549,59 +1539,25 @@ static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1549 saa711x_writeregs(client, saa7115_init_misc); 1539 saa711x_writeregs(client, saa7115_init_misc);
1550 saa711x_set_v4lstd(client, V4L2_STD_NTSC); 1540 saa711x_set_v4lstd(client, V4L2_STD_NTSC);
1551 1541
1552 i2c_attach_client(client);
1553
1554 v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n", 1542 v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n",
1555 saa711x_read(client, R_1E_STATUS_BYTE_1_VD_DEC), saa711x_read(client, R_1F_STATUS_BYTE_2_VD_DEC)); 1543 saa711x_read(client, R_1E_STATUS_BYTE_1_VD_DEC), saa711x_read(client, R_1F_STATUS_BYTE_2_VD_DEC));
1556
1557 return 0; 1544 return 0;
1558} 1545}
1559 1546
1560static int saa711x_probe(struct i2c_adapter *adapter) 1547/* ----------------------------------------------------------------------- */
1561{
1562 if (adapter->class & I2C_CLASS_TV_ANALOG || adapter->class & I2C_CLASS_TV_DIGITAL)
1563 return i2c_probe(adapter, &addr_data, &saa711x_attach);
1564 return 0;
1565}
1566 1548
1567static int saa711x_detach(struct i2c_client *client) 1549static int saa7115_remove(struct i2c_client *client)
1568{ 1550{
1569 struct saa711x_state *state = i2c_get_clientdata(client); 1551 kfree(i2c_get_clientdata(client));
1570 int err;
1571
1572 err = i2c_detach_client(client);
1573 if (err) {
1574 return err;
1575 }
1576
1577 kfree(state);
1578 kfree(client);
1579 return 0; 1552 return 0;
1580} 1553}
1581 1554
1582/* ----------------------------------------------------------------------- */ 1555static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1583 1556 .name = "saa7115",
1584/* i2c implementation */ 1557 .driverid = I2C_DRIVERID_SAA711X,
1585static struct i2c_driver i2c_driver_saa711x = { 1558 .command = saa7115_command,
1586 .driver = { 1559 .probe = saa7115_probe,
1587 .name = "saa7115", 1560 .remove = saa7115_remove,
1588 }, 1561 .legacy_class = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
1589 .id = I2C_DRIVERID_SAA711X,
1590 .attach_adapter = saa711x_probe,
1591 .detach_client = saa711x_detach,
1592 .command = saa711x_command,
1593}; 1562};
1594 1563
1595
1596static int __init saa711x_init_module(void)
1597{
1598 return i2c_add_driver(&i2c_driver_saa711x);
1599}
1600
1601static void __exit saa711x_cleanup_module(void)
1602{
1603 i2c_del_driver(&i2c_driver_saa711x);
1604}
1605
1606module_init(saa711x_init_module);
1607module_exit(saa711x_cleanup_module);
diff --git a/drivers/media/video/saa7127.c b/drivers/media/video/saa7127.c
index e35ef321ec71..06c88db656b4 100644
--- a/drivers/media/video/saa7127.c
+++ b/drivers/media/video/saa7127.c
@@ -55,10 +55,11 @@
55#include <linux/videodev2.h> 55#include <linux/videodev2.h>
56#include <media/v4l2-common.h> 56#include <media/v4l2-common.h>
57#include <media/v4l2-chip-ident.h> 57#include <media/v4l2-chip-ident.h>
58#include <media/v4l2-i2c-drv.h>
58#include <media/saa7127.h> 59#include <media/saa7127.h>
59 60
60static int debug = 0; 61static int debug;
61static int test_image = 0; 62static int test_image;
62 63
63MODULE_DESCRIPTION("Philips SAA7127/9 video encoder driver"); 64MODULE_DESCRIPTION("Philips SAA7127/9 video encoder driver");
64MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil"); 65MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil");
@@ -68,10 +69,6 @@ module_param(test_image, int, 0644);
68MODULE_PARM_DESC(debug, "debug level (0-2)"); 69MODULE_PARM_DESC(debug, "debug level (0-2)");
69MODULE_PARM_DESC(test_image, "test_image (0-1)"); 70MODULE_PARM_DESC(test_image, "test_image (0-1)");
70 71
71static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
72
73
74I2C_CLIENT_INSMOD;
75 72
76/* 73/*
77 * SAA7127 registers 74 * SAA7127 registers
@@ -360,9 +357,10 @@ static int saa7127_set_cc(struct i2c_client *client, struct v4l2_sliced_vbi_data
360 if (enable && (data->field != 0 || data->line != 21)) 357 if (enable && (data->field != 0 || data->line != 21))
361 return -EINVAL; 358 return -EINVAL;
362 if (state->cc_enable != enable) { 359 if (state->cc_enable != enable) {
363 v4l_dbg(1, debug, client, "Turn CC %s\n", enable ? "on" : "off"); 360 v4l_dbg(1, debug, client,
361 "Turn CC %s\n", enable ? "on" : "off");
364 saa7127_write(client, SAA7127_REG_CLOSED_CAPTION, 362 saa7127_write(client, SAA7127_REG_CLOSED_CAPTION,
365 (state->xds_enable << 7) | (enable << 6) | 0x11); 363 (state->xds_enable << 7) | (enable << 6) | 0x11);
366 state->cc_enable = enable; 364 state->cc_enable = enable;
367 } 365 }
368 if (!enable) 366 if (!enable)
@@ -420,7 +418,8 @@ static int saa7127_set_wss(struct i2c_client *client, struct v4l2_sliced_vbi_dat
420 418
421 saa7127_write(client, 0x26, data->data[0]); 419 saa7127_write(client, 0x26, data->data[0]);
422 saa7127_write(client, 0x27, 0x80 | (data->data[1] & 0x3f)); 420 saa7127_write(client, 0x27, 0x80 | (data->data[1] & 0x3f));
423 v4l_dbg(1, debug, client, "WSS mode: %s\n", wss_strs[data->data[0] & 0xf]); 421 v4l_dbg(1, debug, client,
422 "WSS mode: %s\n", wss_strs[data->data[0] & 0xf]);
424 state->wss_mode = (data->data[1] & 0x3f) << 8 | data->data[0]; 423 state->wss_mode = (data->data[1] & 0x3f) << 8 | data->data[0];
425 return 0; 424 return 0;
426} 425}
@@ -507,7 +506,8 @@ static int saa7127_set_output_type(struct i2c_client *client, int output)
507 default: 506 default:
508 return -EINVAL; 507 return -EINVAL;
509 } 508 }
510 v4l_dbg(1, debug, client, "Selecting %s output type\n", output_strs[output]); 509 v4l_dbg(1, debug, client,
510 "Selecting %s output type\n", output_strs[output]);
511 511
512 /* Configure Encoder */ 512 /* Configure Encoder */
513 saa7127_write(client, 0x2d, state->reg_2d); 513 saa7127_write(client, 0x2d, state->reg_2d);
@@ -569,12 +569,10 @@ static int saa7127_command(struct i2c_client *client,
569 { 569 {
570 int rc = 0; 570 int rc = 0;
571 571
572 if (state->input_type != route->input) { 572 if (state->input_type != route->input)
573 rc = saa7127_set_input_type(client, route->input); 573 rc = saa7127_set_input_type(client, route->input);
574 } 574 if (rc == 0 && state->output_type != route->output)
575 if (rc == 0 && state->output_type != route->output) {
576 rc = saa7127_set_output_type(client, route->output); 575 rc = saa7127_set_output_type(client, route->output);
577 }
578 return rc; 576 return rc;
579 } 577 }
580 578
@@ -620,7 +618,8 @@ static int saa7127_command(struct i2c_client *client,
620 { 618 {
621 struct v4l2_register *reg = arg; 619 struct v4l2_register *reg = arg;
622 620
623 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip)) 621 if (!v4l2_chip_match_i2c_client(client,
622 reg->match_type, reg->match_chip))
624 return -EINVAL; 623 return -EINVAL;
625 if (!capable(CAP_SYS_ADMIN)) 624 if (!capable(CAP_SYS_ADMIN))
626 return -EPERM; 625 return -EPERM;
@@ -637,16 +636,16 @@ static int saa7127_command(struct i2c_client *client,
637 struct v4l2_sliced_vbi_data *data = arg; 636 struct v4l2_sliced_vbi_data *data = arg;
638 637
639 switch (data->id) { 638 switch (data->id) {
640 case V4L2_SLICED_WSS_625: 639 case V4L2_SLICED_WSS_625:
641 return saa7127_set_wss(client, data); 640 return saa7127_set_wss(client, data);
642 case V4L2_SLICED_VPS: 641 case V4L2_SLICED_VPS:
643 return saa7127_set_vps(client, data); 642 return saa7127_set_vps(client, data);
644 case V4L2_SLICED_CAPTION_525: 643 case V4L2_SLICED_CAPTION_525:
645 if (data->field == 0) 644 if (data->field == 0)
646 return saa7127_set_cc(client, data); 645 return saa7127_set_cc(client, data);
647 return saa7127_set_xds(client, data); 646 return saa7127_set_xds(client, data);
648 default: 647 default:
649 return -EINVAL; 648 return -EINVAL;
650 } 649 }
651 break; 650 break;
652 } 651 }
@@ -662,31 +661,20 @@ static int saa7127_command(struct i2c_client *client,
662 661
663/* ----------------------------------------------------------------------- */ 662/* ----------------------------------------------------------------------- */
664 663
665static struct i2c_driver i2c_driver_saa7127; 664static int saa7127_probe(struct i2c_client *client)
666
667/* ----------------------------------------------------------------------- */
668
669static int saa7127_attach(struct i2c_adapter *adapter, int address, int kind)
670{ 665{
671 struct i2c_client *client;
672 struct saa7127_state *state; 666 struct saa7127_state *state;
673 struct v4l2_sliced_vbi_data vbi = { 0, 0, 0, 0 }; /* set to disabled */ 667 struct v4l2_sliced_vbi_data vbi = { 0, 0, 0, 0 }; /* set to disabled */
674 int read_result = 0; 668 int read_result = 0;
675 669
676 /* Check if the adapter supports the needed features */ 670 /* Check if the adapter supports the needed features */
677 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 671 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
678 return 0; 672 return -EIO;
679
680 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
681 if (client == 0)
682 return -ENOMEM;
683 673
684 client->addr = address;
685 client->adapter = adapter;
686 client->driver = &i2c_driver_saa7127;
687 snprintf(client->name, sizeof(client->name) - 1, "saa7127"); 674 snprintf(client->name, sizeof(client->name) - 1, "saa7127");
688 675
689 v4l_dbg(1, debug, client, "detecting saa7127 client on address 0x%x\n", address << 1); 676 v4l_dbg(1, debug, client, "detecting saa7127 client on address 0x%x\n",
677 client->addr << 1);
690 678
691 /* First test register 0: Bits 5-7 are a version ID (should be 0), 679 /* First test register 0: Bits 5-7 are a version ID (should be 0),
692 and bit 2 should also be 0. 680 and bit 2 should also be 0.
@@ -696,15 +684,12 @@ static int saa7127_attach(struct i2c_adapter *adapter, int address, int kind)
696 if ((saa7127_read(client, 0) & 0xe4) != 0 || 684 if ((saa7127_read(client, 0) & 0xe4) != 0 ||
697 (saa7127_read(client, 0x29) & 0x3f) != 0x1d) { 685 (saa7127_read(client, 0x29) & 0x3f) != 0x1d) {
698 v4l_dbg(1, debug, client, "saa7127 not found\n"); 686 v4l_dbg(1, debug, client, "saa7127 not found\n");
699 kfree(client); 687 return -ENODEV;
700 return 0;
701 } 688 }
702 state = kzalloc(sizeof(struct saa7127_state), GFP_KERNEL); 689 state = kzalloc(sizeof(struct saa7127_state), GFP_KERNEL);
703 690
704 if (state == NULL) { 691 if (state == NULL)
705 kfree(client); 692 return -ENOMEM;
706 return (-ENOMEM);
707 }
708 693
709 i2c_set_clientdata(client, state); 694 i2c_set_clientdata(client, state);
710 695
@@ -718,91 +703,48 @@ static int saa7127_attach(struct i2c_adapter *adapter, int address, int kind)
718 saa7127_set_wss(client, &vbi); 703 saa7127_set_wss(client, &vbi);
719 saa7127_set_cc(client, &vbi); 704 saa7127_set_cc(client, &vbi);
720 saa7127_set_xds(client, &vbi); 705 saa7127_set_xds(client, &vbi);
721 if (test_image == 1) { 706 if (test_image == 1)
722 /* The Encoder has an internal Colorbar generator */ 707 /* The Encoder has an internal Colorbar generator */
723 /* This can be used for debugging */ 708 /* This can be used for debugging */
724 saa7127_set_input_type(client, SAA7127_INPUT_TYPE_TEST_IMAGE); 709 saa7127_set_input_type(client, SAA7127_INPUT_TYPE_TEST_IMAGE);
725 } else { 710 else
726 saa7127_set_input_type(client, SAA7127_INPUT_TYPE_NORMAL); 711 saa7127_set_input_type(client, SAA7127_INPUT_TYPE_NORMAL);
727 }
728 saa7127_set_video_enable(client, 1); 712 saa7127_set_video_enable(client, 1);
729 713
730 /* Detect if it's an saa7129 */ 714 /* Detect if it's an saa7129 */
731 read_result = saa7127_read(client, SAA7129_REG_FADE_KEY_COL2); 715 read_result = saa7127_read(client, SAA7129_REG_FADE_KEY_COL2);
732 saa7127_write(client, SAA7129_REG_FADE_KEY_COL2, 0xaa); 716 saa7127_write(client, SAA7129_REG_FADE_KEY_COL2, 0xaa);
733 if (saa7127_read(client, SAA7129_REG_FADE_KEY_COL2) == 0xaa) { 717 if (saa7127_read(client, SAA7129_REG_FADE_KEY_COL2) == 0xaa) {
734 v4l_info(client, "saa7129 found @ 0x%x (%s)\n", address << 1, adapter->name); 718 v4l_info(client, "saa7129 found @ 0x%x (%s)\n",
719 client->addr << 1, client->adapter->name);
735 saa7127_write(client, SAA7129_REG_FADE_KEY_COL2, read_result); 720 saa7127_write(client, SAA7129_REG_FADE_KEY_COL2, read_result);
736 saa7127_write_inittab(client, saa7129_init_config_extra); 721 saa7127_write_inittab(client, saa7129_init_config_extra);
737 state->ident = V4L2_IDENT_SAA7129; 722 state->ident = V4L2_IDENT_SAA7129;
738 } else { 723 } else {
739 v4l_info(client, "saa7127 found @ 0x%x (%s)\n", address << 1, adapter->name); 724 v4l_info(client, "saa7127 found @ 0x%x (%s)\n",
725 client->addr << 1, client->adapter->name);
740 state->ident = V4L2_IDENT_SAA7127; 726 state->ident = V4L2_IDENT_SAA7127;
741 } 727 }
742
743 i2c_attach_client(client);
744
745 return 0; 728 return 0;
746} 729}
747 730
748/* ----------------------------------------------------------------------- */ 731/* ----------------------------------------------------------------------- */
749 732
750static int saa7127_probe(struct i2c_adapter *adapter) 733static int saa7127_remove(struct i2c_client *client)
751{ 734{
752 if (adapter->class & I2C_CLASS_TV_ANALOG)
753 return i2c_probe(adapter, &addr_data, saa7127_attach);
754 return 0;
755}
756
757/* ----------------------------------------------------------------------- */
758
759static int saa7127_detach(struct i2c_client *client)
760{
761 struct saa7127_state *state = i2c_get_clientdata(client);
762 int err;
763
764 /* Turn off TV output */ 735 /* Turn off TV output */
765 saa7127_set_video_enable(client, 0); 736 saa7127_set_video_enable(client, 0);
766 737 kfree(i2c_get_clientdata(client));
767 err = i2c_detach_client(client);
768
769 if (err) {
770 return err;
771 }
772
773 kfree(state);
774 kfree(client);
775 return 0; 738 return 0;
776} 739}
777 740
778/* ----------------------------------------------------------------------- */ 741/* ----------------------------------------------------------------------- */
779 742
780static struct i2c_driver i2c_driver_saa7127 = { 743static struct v4l2_i2c_driver_data v4l2_i2c_data = {
781 .driver = { 744 .name = "saa7127",
782 .name = "saa7127", 745 .driverid = I2C_DRIVERID_SAA7127,
783 },
784 .id = I2C_DRIVERID_SAA7127,
785 .attach_adapter = saa7127_probe,
786 .detach_client = saa7127_detach,
787 .command = saa7127_command, 746 .command = saa7127_command,
747 .probe = saa7127_probe,
748 .remove = saa7127_remove,
788}; 749};
789 750
790
791/* ----------------------------------------------------------------------- */
792
793static int __init saa7127_init_module(void)
794{
795 return i2c_add_driver(&i2c_driver_saa7127);
796}
797
798/* ----------------------------------------------------------------------- */
799
800static void __exit saa7127_cleanup_module(void)
801{
802 i2c_del_driver(&i2c_driver_saa7127);
803}
804
805/* ----------------------------------------------------------------------- */
806
807module_init(saa7127_init_module);
808module_exit(saa7127_cleanup_module);
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 3aa8cb2b860a..96bc3b1298a2 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -4,6 +4,7 @@ config VIDEO_SAA7134
4 select VIDEOBUF_DMA_SG 4 select VIDEOBUF_DMA_SG
5 select VIDEO_IR 5 select VIDEO_IR
6 select VIDEO_TUNER 6 select VIDEO_TUNER
7 select VIDEO_TVEEPROM
7 select CRC32 8 select CRC32
8 ---help--- 9 ---help---
9 This is a video4linux driver for Philips SAA713x based 10 This is a video4linux driver for Philips SAA713x based
@@ -23,18 +24,6 @@ config VIDEO_SAA7134_ALSA
23 To compile this driver as a module, choose M here: the 24 To compile this driver as a module, choose M here: the
24 module will be called saa7134-alsa. 25 module will be called saa7134-alsa.
25 26
26config VIDEO_SAA7134_OSS
27 tristate "Philips SAA7134 DMA audio support (OSS, DEPRECATED)"
28 depends on VIDEO_SAA7134 && SOUND_PRIME && !VIDEO_SAA7134_ALSA
29 ---help---
30 This is a video4linux driver for direct (DMA) audio in
31 Philips SAA713x based TV cards using OSS
32
33 This is deprecated in favor of the ALSA module
34
35 To compile this driver as a module, choose M here: the
36 module will be called saa7134-oss.
37
38config VIDEO_SAA7134_DVB 27config VIDEO_SAA7134_DVB
39 tristate "DVB/ATSC Support for saa7134 based TV cards" 28 tristate "DVB/ATSC Support for saa7134 based TV cards"
40 depends on VIDEO_SAA7134 && DVB_CORE 29 depends on VIDEO_SAA7134 && DVB_CORE
diff --git a/drivers/media/video/saa7134/Makefile b/drivers/media/video/saa7134/Makefile
index c85c8a8ec361..9aff937ba7a5 100644
--- a/drivers/media/video/saa7134/Makefile
+++ b/drivers/media/video/saa7134/Makefile
@@ -7,7 +7,6 @@ obj-$(CONFIG_VIDEO_SAA7134) += saa7134.o saa7134-empress.o \
7 saa6752hs.o 7 saa6752hs.o
8 8
9obj-$(CONFIG_VIDEO_SAA7134_ALSA) += saa7134-alsa.o 9obj-$(CONFIG_VIDEO_SAA7134_ALSA) += saa7134-alsa.o
10obj-$(CONFIG_VIDEO_SAA7134_OSS) += saa7134-oss.o
11 10
12obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o 11obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o
13 12
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index 4878f3067787..ba2531034a91 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -1077,24 +1077,14 @@ static int saa7134_alsa_init(void)
1077 struct saa7134_dev *dev = NULL; 1077 struct saa7134_dev *dev = NULL;
1078 struct list_head *list; 1078 struct list_head *list;
1079 1079
1080 if (!saa7134_dmasound_init && !saa7134_dmasound_exit) { 1080 saa7134_dmasound_init = alsa_device_init;
1081 saa7134_dmasound_init = alsa_device_init; 1081 saa7134_dmasound_exit = alsa_device_exit;
1082 saa7134_dmasound_exit = alsa_device_exit;
1083 } else {
1084 printk(KERN_WARNING "saa7134 ALSA: can't load, DMA sound handler already assigned (probably to OSS)\n");
1085 return -EBUSY;
1086 }
1087 1082
1088 printk(KERN_INFO "saa7134 ALSA driver for DMA sound loaded\n"); 1083 printk(KERN_INFO "saa7134 ALSA driver for DMA sound loaded\n");
1089 1084
1090 list_for_each(list,&saa7134_devlist) { 1085 list_for_each(list,&saa7134_devlist) {
1091 dev = list_entry(list, struct saa7134_dev, devlist); 1086 dev = list_entry(list, struct saa7134_dev, devlist);
1092 if (dev->dmasound.priv_data == NULL) { 1087 alsa_device_init(dev);
1093 alsa_device_init(dev);
1094 } else {
1095 printk(KERN_ERR "saa7134 ALSA: DMA sound is being handled by OSS. ignoring %s\n",dev->name);
1096 return -EBUSY;
1097 }
1098 } 1088 }
1099 1089
1100 if (dev == NULL) 1090 if (dev == NULL)
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 98c1b084a716..7d7f383b404f 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -26,6 +26,7 @@
26#include "saa7134-reg.h" 26#include "saa7134-reg.h"
27#include "saa7134.h" 27#include "saa7134.h"
28#include <media/v4l2-common.h> 28#include <media/v4l2-common.h>
29#include <media/tveeprom.h>
29 30
30/* commly used strings */ 31/* commly used strings */
31static char name_mute[] = "mute"; 32static char name_mute[] = "mute";
@@ -349,6 +350,10 @@ struct saa7134_board saa7134_boards[] = {
349 .name = name_radio, 350 .name = name_radio,
350 .amux = LINE2, 351 .amux = LINE2,
351 }, 352 },
353 .mute = {
354 .name = name_mute,
355 .amux = TV,
356 },
352 }, 357 },
353 [SAA7134_BOARD_TVSTATION_RDS] = { 358 [SAA7134_BOARD_TVSTATION_RDS] = {
354 /* Typhoon TV Tuner RDS: Art.Nr. 50694 */ 359 /* Typhoon TV Tuner RDS: Art.Nr. 50694 */
@@ -565,6 +570,10 @@ struct saa7134_board saa7134_boards[] = {
565 .radio = { 570 .radio = {
566 .name = name_radio, 571 .name = name_radio,
567 .amux = LINE2, 572 .amux = LINE2,
573 },
574 .mute = {
575 .name = name_mute,
576 .amux = TV,
568 }, 577 },
569 }, 578 },
570 [SAA7134_BOARD_TYPHOON_90031] = { 579 [SAA7134_BOARD_TYPHOON_90031] = {
@@ -3553,6 +3562,356 @@ struct saa7134_board saa7134_boards[] = {
3553 .tv = 1, 3562 .tv = 1,
3554 }}, 3563 }},
3555 }, 3564 },
3565 [SAA7134_BOARD_BEHOLD_401] = {
3566 .name = "Beholder BeholdTV 401",
3567 .audio_clock = 0x00187de7,
3568 .tuner_type = TUNER_PHILIPS_FQ1216ME,
3569 .radio_type = UNSET,
3570 .tuner_addr = ADDR_UNSET,
3571 .radio_addr = ADDR_UNSET,
3572 .inputs = {{
3573 .name = name_svideo,
3574 .vmux = 8,
3575 .amux = LINE1,
3576 },{
3577 .name = name_comp1,
3578 .vmux = 1,
3579 .amux = LINE1,
3580 },{
3581 .name = name_tv,
3582 .vmux = 3,
3583 .amux = LINE2,
3584 .tv = 1,
3585 }},
3586 .mute = {
3587 .name = name_mute,
3588 .amux = LINE1,
3589 },
3590 },
3591 [SAA7134_BOARD_BEHOLD_403] = {
3592 .name = "Beholder BeholdTV 403",
3593 .audio_clock = 0x00187de7,
3594 .tuner_type = TUNER_PHILIPS_FQ1216ME,
3595 .radio_type = UNSET,
3596 .tuner_addr = ADDR_UNSET,
3597 .radio_addr = ADDR_UNSET,
3598 .inputs = {{
3599 .name = name_svideo,
3600 .vmux = 8,
3601 .amux = LINE1,
3602 },{
3603 .name = name_comp1,
3604 .vmux = 1,
3605 .amux = LINE1,
3606 },{
3607 .name = name_tv,
3608 .vmux = 3,
3609 .amux = LINE2,
3610 .tv = 1,
3611 }},
3612 },
3613 [SAA7134_BOARD_BEHOLD_403FM] = {
3614 .name = "Beholder BeholdTV 403 FM",
3615 .audio_clock = 0x00187de7,
3616 .tuner_type = TUNER_PHILIPS_FQ1216ME,
3617 .radio_type = UNSET,
3618 .tuner_addr = ADDR_UNSET,
3619 .radio_addr = ADDR_UNSET,
3620 .inputs = {{
3621 .name = name_svideo,
3622 .vmux = 8,
3623 .amux = LINE1,
3624 },{
3625 .name = name_comp1,
3626 .vmux = 1,
3627 .amux = LINE1,
3628 },{
3629 .name = name_tv,
3630 .vmux = 3,
3631 .amux = LINE2,
3632 .tv = 1,
3633 }},
3634 .radio = {
3635 .name = name_radio,
3636 .amux = LINE2,
3637 },
3638 },
3639 [SAA7134_BOARD_BEHOLD_405] = {
3640 .name = "Beholder BeholdTV 405",
3641 .audio_clock = 0x00187de7,
3642 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
3643 .radio_type = UNSET,
3644 .tuner_addr = ADDR_UNSET,
3645 .radio_addr = ADDR_UNSET,
3646 .tda9887_conf = TDA9887_PRESENT,
3647 .inputs = {{
3648 .name = name_svideo,
3649 .vmux = 8,
3650 .amux = LINE1,
3651 },{
3652 .name = name_comp1,
3653 .vmux = 3,
3654 .amux = LINE1,
3655 },{
3656 .name = name_tv,
3657 .vmux = 3,
3658 .amux = LINE2,
3659 .tv = 1,
3660 }},
3661 },
3662 [SAA7134_BOARD_BEHOLD_405FM] = {
3663 /* Sergey <skiv@orel.ru> */
3664 .name = "Beholder BeholdTV 405 FM",
3665 .audio_clock = 0x00187de7,
3666 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
3667 .radio_type = UNSET,
3668 .tuner_addr = ADDR_UNSET,
3669 .radio_addr = ADDR_UNSET,
3670 .tda9887_conf = TDA9887_PRESENT,
3671 .inputs = {{
3672 .name = name_svideo,
3673 .vmux = 8,
3674 .amux = LINE1,
3675 },{
3676 .name = name_comp1,
3677 .vmux = 3,
3678 .amux = LINE1,
3679 },{
3680 .name = name_tv,
3681 .vmux = 3,
3682 .amux = LINE2,
3683 .tv = 1,
3684 }},
3685 .radio = {
3686 .name = name_radio,
3687 .amux = LINE2,
3688 },
3689 },
3690 [SAA7134_BOARD_BEHOLD_407] = {
3691 .name = "Beholder BeholdTV 407",
3692 .audio_clock = 0x00187de7,
3693 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
3694 .radio_type = UNSET,
3695 .tuner_addr = ADDR_UNSET,
3696 .radio_addr = ADDR_UNSET,
3697 .tda9887_conf = TDA9887_PRESENT,
3698 .gpiomask = 0xc0c000,
3699 .inputs = {{
3700 .name = name_svideo,
3701 .vmux = 8,
3702 .amux = LINE1,
3703 .gpio = 0xc0c000,
3704 },{
3705 .name = name_comp1,
3706 .vmux = 1,
3707 .amux = LINE1,
3708 .gpio = 0xc0c000,
3709 },{
3710 .name = name_tv,
3711 .vmux = 3,
3712 .amux = TV,
3713 .tv = 1,
3714 .gpio = 0xc0c000,
3715 }},
3716 },
3717 [SAA7134_BOARD_BEHOLD_407FM] = {
3718 .name = "Beholder BeholdTV 407 FM",
3719 .audio_clock = 0x00187de7,
3720 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
3721 .radio_type = UNSET,
3722 .tuner_addr = ADDR_UNSET,
3723 .radio_addr = ADDR_UNSET,
3724 .tda9887_conf = TDA9887_PRESENT,
3725 .gpiomask = 0xc0c000,
3726 .inputs = {{
3727 .name = name_svideo,
3728 .vmux = 8,
3729 .amux = LINE1,
3730 .gpio = 0xc0c000,
3731 },{
3732 .name = name_comp1,
3733 .vmux = 1,
3734 .amux = LINE1,
3735 .gpio = 0xc0c000,
3736 },{
3737 .name = name_tv,
3738 .vmux = 3,
3739 .amux = TV,
3740 .tv = 1,
3741 .gpio = 0xc0c000,
3742 }},
3743 .radio = {
3744 .name = name_radio,
3745 .amux = LINE2,
3746 .gpio = 0xc0c000,
3747 },
3748 },
3749 [SAA7134_BOARD_BEHOLD_409] = {
3750 .name = "Beholder BeholdTV 409",
3751 .audio_clock = 0x00187de7,
3752 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
3753 .radio_type = UNSET,
3754 .tuner_addr = ADDR_UNSET,
3755 .radio_addr = ADDR_UNSET,
3756 .tda9887_conf = TDA9887_PRESENT,
3757 .inputs = {{
3758 .name = name_tv,
3759 .vmux = 3,
3760 .amux = TV,
3761 .tv = 1,
3762 },{
3763 .name = name_comp1,
3764 .vmux = 1,
3765 .amux = LINE1,
3766 },{
3767 .name = name_svideo,
3768 .vmux = 8,
3769 .amux = LINE1,
3770 }},
3771 },
3772 [SAA7134_BOARD_BEHOLD_505FM] = {
3773 .name = "Beholder BeholdTV 505 FM/RDS",
3774 .audio_clock = 0x00200000,
3775 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
3776 .radio_type = UNSET,
3777 .tuner_addr = ADDR_UNSET,
3778 .radio_addr = ADDR_UNSET,
3779 .tda9887_conf = TDA9887_PRESENT,
3780 .inputs = {{
3781 .name = name_tv,
3782 .vmux = 3,
3783 .amux = LINE2,
3784 .tv = 1,
3785 },{
3786 .name = name_comp1,
3787 .vmux = 1,
3788 .amux = LINE1,
3789 },{
3790 .name = name_svideo,
3791 .vmux = 8,
3792 .amux = LINE1,
3793 }},
3794 .mute = {
3795 .name = name_mute,
3796 .amux = LINE1,
3797 },
3798 .radio = {
3799 .name = name_radio,
3800 .amux = LINE2,
3801 },
3802 },
3803 [SAA7134_BOARD_BEHOLD_507_9FM] = {
3804 .name = "Beholder BeholdTV 507 FM/RDS / BeholdTV 509 FM",
3805 .audio_clock = 0x00187de7,
3806 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
3807 .radio_type = UNSET,
3808 .tuner_addr = ADDR_UNSET,
3809 .radio_addr = ADDR_UNSET,
3810 .tda9887_conf = TDA9887_PRESENT,
3811 .inputs = {{
3812 .name = name_tv,
3813 .vmux = 3,
3814 .amux = TV,
3815 .tv = 1,
3816 },{
3817 .name = name_comp1,
3818 .vmux = 1,
3819 .amux = LINE1,
3820 },{
3821 .name = name_svideo,
3822 .vmux = 8,
3823 .amux = LINE1,
3824 }},
3825 .radio = {
3826 .name = name_radio,
3827 .amux = LINE2,
3828 },
3829 },
3830 [SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM] = {
3831 .name = "Beholder BeholdTV Columbus TVFM",
3832 .audio_clock = 0x00187de7,
3833 .tuner_type = TUNER_ALPS_TSBE5_PAL,
3834 .radio_type = UNSET,
3835 .tuner_addr = ADDR_UNSET,
3836 .radio_addr = ADDR_UNSET,
3837 .tda9887_conf = TDA9887_PRESENT,
3838 .inputs = {{
3839 .name = name_tv,
3840 .vmux = 3,
3841 .amux = TV,
3842 .tv = 1,
3843 },{
3844 .name = name_comp1,
3845 .vmux = 1,
3846 .amux = LINE1,
3847 },{
3848 .name = name_svideo,
3849 .vmux = 8,
3850 .amux = LINE1,
3851 }},
3852 .radio = {
3853 .name = name_radio,
3854 .amux = LINE2,
3855 },
3856 },
3857 [SAA7134_BOARD_BEHOLD_607_9FM] = {
3858 /* Andrey Melnikoff <temnota@kmv.ru> */
3859 .name = "Beholder BeholdTV 607 / BeholdTV 609",
3860 .audio_clock = 0x00187de7,
3861 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
3862 .radio_type = UNSET,
3863 .tuner_addr = ADDR_UNSET,
3864 .radio_addr = ADDR_UNSET,
3865 .tda9887_conf = TDA9887_PRESENT,
3866 .inputs = {{
3867 .name = name_tv,
3868 .vmux = 3,
3869 .amux = TV,
3870 .tv = 1,
3871 },{
3872 .name = name_comp1,
3873 .vmux = 1,
3874 .amux = LINE1,
3875 },{
3876 .name = name_svideo,
3877 .vmux = 8,
3878 .amux = LINE1,
3879 }},
3880 .radio = {
3881 .name = name_radio,
3882 .amux = LINE2,
3883 },
3884 },
3885 [SAA7134_BOARD_BEHOLD_M6] = {
3886 /* Igor Kuznetsov <igk@igk.ru> */
3887 /* Andrey Melnikoff <temnota@kmv.ru> */
3888 .name = "Beholder BeholdTV M6 / BeholdTV M6 Extra",
3889 .audio_clock = 0x00187de7,
3890 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
3891 .radio_type = UNSET,
3892 .tuner_addr = ADDR_UNSET,
3893 .radio_addr = ADDR_UNSET,
3894 .tda9887_conf = TDA9887_PRESENT,
3895 .inputs = {{
3896 .name = name_tv,
3897 .vmux = 3,
3898 .amux = TV,
3899 .tv = 1,
3900 },{
3901 .name = name_comp1,
3902 .vmux = 1,
3903 .amux = LINE1,
3904 },{
3905 .name = name_svideo,
3906 .vmux = 8,
3907 .amux = LINE1,
3908 }},
3909 .radio = {
3910 .name = name_radio,
3911 .amux = LINE2,
3912 },
3913 .mpeg = SAA7134_MPEG_EMPRESS,
3914 },
3556}; 3915};
3557 3916
3558const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 3917const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -4033,7 +4392,13 @@ struct pci_device_id saa7134_pci_tbl[] = {
4033 .vendor = PCI_VENDOR_ID_PHILIPS, 4392 .vendor = PCI_VENDOR_ID_PHILIPS,
4034 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 4393 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4035 .subvendor = 0x1462, 4394 .subvendor = 0x1462,
4036 .subdevice = 0x6231, 4395 .subdevice = 0x6231, /* tda8275a, ks003 IR */
4396 .driver_data = SAA7134_BOARD_MSI_TVATANYWHERE_PLUS,
4397 },{
4398 .vendor = PCI_VENDOR_ID_PHILIPS,
4399 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4400 .subvendor = 0x1462,
4401 .subdevice = 0x8624, /* tda8275, ks003 IR */
4037 .driver_data = SAA7134_BOARD_MSI_TVATANYWHERE_PLUS, 4402 .driver_data = SAA7134_BOARD_MSI_TVATANYWHERE_PLUS,
4038 },{ 4403 },{
4039 .vendor = PCI_VENDOR_ID_PHILIPS, 4404 .vendor = PCI_VENDOR_ID_PHILIPS,
@@ -4207,11 +4572,41 @@ struct pci_device_id saa7134_pci_tbl[] = {
4207 .vendor = PCI_VENDOR_ID_PHILIPS, 4572 .vendor = PCI_VENDOR_ID_PHILIPS,
4208 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 4573 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4209 .subvendor = 0x0070, 4574 .subvendor = 0x0070,
4575 .subdevice = 0x6700,
4576 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110,
4577 },{
4578 .vendor = PCI_VENDOR_ID_PHILIPS,
4579 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4580 .subvendor = 0x0070,
4210 .subdevice = 0x6701, 4581 .subdevice = 0x6701,
4211 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110, 4582 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110,
4212 },{ 4583 },{
4213 .vendor = PCI_VENDOR_ID_PHILIPS, 4584 .vendor = PCI_VENDOR_ID_PHILIPS,
4214 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 4585 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4586 .subvendor = 0x0070,
4587 .subdevice = 0x6702,
4588 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110,
4589 },{
4590 .vendor = PCI_VENDOR_ID_PHILIPS,
4591 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4592 .subvendor = 0x0070,
4593 .subdevice = 0x6703,
4594 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110,
4595 },{
4596 .vendor = PCI_VENDOR_ID_PHILIPS,
4597 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4598 .subvendor = 0x0070,
4599 .subdevice = 0x6704,
4600 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110,
4601 },{
4602 .vendor = PCI_VENDOR_ID_PHILIPS,
4603 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4604 .subvendor = 0x0070,
4605 .subdevice = 0x6705,
4606 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110,
4607 },{
4608 .vendor = PCI_VENDOR_ID_PHILIPS,
4609 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4215 .subvendor = 0x153b, 4610 .subvendor = 0x153b,
4216 .subdevice = 0x1172, 4611 .subdevice = 0x1172,
4217 .driver_data = SAA7134_BOARD_CINERGY_HT_PCMCIA, 4612 .driver_data = SAA7134_BOARD_CINERGY_HT_PCMCIA,
@@ -4289,6 +4684,162 @@ struct pci_device_id saa7134_pci_tbl[] = {
4289 .driver_data = SAA7134_BOARD_AVERMEDIA_SUPER_007, 4684 .driver_data = SAA7134_BOARD_AVERMEDIA_SUPER_007,
4290 },{ 4685 },{
4291 .vendor = PCI_VENDOR_ID_PHILIPS, 4686 .vendor = PCI_VENDOR_ID_PHILIPS,
4687 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
4688 .subvendor = 0x0000,
4689 .subdevice = 0x4016,
4690 .driver_data = SAA7134_BOARD_BEHOLD_401,
4691 },{
4692 .vendor = PCI_VENDOR_ID_PHILIPS,
4693 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4694 .subvendor = 0x0000,
4695 .subdevice = 0x4036,
4696 .driver_data = SAA7134_BOARD_BEHOLD_403,
4697 },{
4698 .vendor = PCI_VENDOR_ID_PHILIPS,
4699 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4700 .subvendor = 0x0000,
4701 .subdevice = 0x4037,
4702 .driver_data = SAA7134_BOARD_BEHOLD_403FM,
4703 },{
4704 .vendor = PCI_VENDOR_ID_PHILIPS,
4705 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
4706 .subvendor = 0x0000,
4707 .subdevice = 0x4050,
4708 .driver_data = SAA7134_BOARD_BEHOLD_405,
4709 },{
4710 .vendor = PCI_VENDOR_ID_PHILIPS,
4711 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
4712 .subvendor = 0x0000,
4713 .subdevice = 0x4051,
4714 .driver_data = SAA7134_BOARD_BEHOLD_405FM,
4715 },{
4716 .vendor = PCI_VENDOR_ID_PHILIPS,
4717 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4718 .subvendor = 0x0000,
4719 .subdevice = 0x4070,
4720 .driver_data = SAA7134_BOARD_BEHOLD_407,
4721 },{
4722 .vendor = PCI_VENDOR_ID_PHILIPS,
4723 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4724 .subvendor = 0x0000,
4725 .subdevice = 0x4071,
4726 .driver_data = SAA7134_BOARD_BEHOLD_407FM,
4727 },{
4728 .vendor = PCI_VENDOR_ID_PHILIPS,
4729 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4730 .subvendor = 0x0000,
4731 .subdevice = 0x4090,
4732 .driver_data = SAA7134_BOARD_BEHOLD_409,
4733 },{
4734 .vendor = PCI_VENDOR_ID_PHILIPS,
4735 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
4736 .subvendor = 0x0000,
4737 .subdevice = 0x5051,
4738 .driver_data = SAA7134_BOARD_BEHOLD_505FM,
4739 },{
4740 .vendor = PCI_VENDOR_ID_PHILIPS,
4741 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
4742 .subvendor = 0x0000,
4743 .subdevice = 0x505B,
4744 .driver_data = SAA7134_BOARD_BEHOLD_505FM,
4745 },{
4746 .vendor = PCI_VENDOR_ID_PHILIPS,
4747 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
4748 .subvendor = 0x5ace,
4749 .subdevice = 0x5050,
4750 .driver_data = SAA7134_BOARD_BEHOLD_505FM,
4751 },{
4752 .vendor = PCI_VENDOR_ID_PHILIPS,
4753 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4754 .subvendor = 0x0000,
4755 .subdevice = 0x5071,
4756 .driver_data = SAA7134_BOARD_BEHOLD_507_9FM,
4757 },{
4758 .vendor = PCI_VENDOR_ID_PHILIPS,
4759 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4760 .subvendor = 0x0000,
4761 .subdevice = 0x507B,
4762 .driver_data = SAA7134_BOARD_BEHOLD_507_9FM,
4763 },{
4764 .vendor = PCI_VENDOR_ID_PHILIPS,
4765 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4766 .subvendor = 0x5ace,
4767 .subdevice = 0x5070,
4768 .driver_data = SAA7134_BOARD_BEHOLD_507_9FM,
4769 },{
4770 .vendor = PCI_VENDOR_ID_PHILIPS,
4771 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4772 .subvendor = 0x5ace,
4773 .subdevice = 0x5090,
4774 .driver_data = SAA7134_BOARD_BEHOLD_507_9FM,
4775 },{
4776 .vendor = PCI_VENDOR_ID_PHILIPS,
4777 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4778 .subvendor = 0x0000,
4779 .subdevice = 0x5201,
4780 .driver_data = SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM,
4781 },{
4782 .vendor = PCI_VENDOR_ID_PHILIPS,
4783 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4784 .subvendor = 0x5ace,
4785 .subdevice = 0x6070,
4786 .driver_data = SAA7134_BOARD_BEHOLD_607_9FM,
4787 },{
4788 .vendor = PCI_VENDOR_ID_PHILIPS,
4789 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4790 .subvendor = 0x5ace,
4791 .subdevice = 0x6071,
4792 .driver_data = SAA7134_BOARD_BEHOLD_607_9FM,
4793 },{
4794 .vendor = PCI_VENDOR_ID_PHILIPS,
4795 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4796 .subvendor = 0x5ace,
4797 .subdevice = 0x6072,
4798 .driver_data = SAA7134_BOARD_BEHOLD_607_9FM,
4799 },{
4800 .vendor = PCI_VENDOR_ID_PHILIPS,
4801 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4802 .subvendor = 0x5ace,
4803 .subdevice = 0x6073,
4804 .driver_data = SAA7134_BOARD_BEHOLD_607_9FM,
4805 },{
4806 .vendor = PCI_VENDOR_ID_PHILIPS,
4807 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4808 .subvendor = 0x5ace,
4809 .subdevice = 0x6090,
4810 .driver_data = SAA7134_BOARD_BEHOLD_607_9FM,
4811 },{
4812 .vendor = PCI_VENDOR_ID_PHILIPS,
4813 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4814 .subvendor = 0x5ace,
4815 .subdevice = 0x6091,
4816 .driver_data = SAA7134_BOARD_BEHOLD_607_9FM,
4817 },{
4818 .vendor = PCI_VENDOR_ID_PHILIPS,
4819 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4820 .subvendor = 0x5ace,
4821 .subdevice = 0x6092,
4822 .driver_data = SAA7134_BOARD_BEHOLD_607_9FM,
4823 },{
4824 .vendor = PCI_VENDOR_ID_PHILIPS,
4825 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4826 .subvendor = 0x5ace,
4827 .subdevice = 0x6093,
4828 .driver_data = SAA7134_BOARD_BEHOLD_607_9FM,
4829 },{
4830 .vendor = PCI_VENDOR_ID_PHILIPS,
4831 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4832 .subvendor = 0x5ace,
4833 .subdevice = 0x6190,
4834 .driver_data = SAA7134_BOARD_BEHOLD_M6,
4835 },{
4836 .vendor = PCI_VENDOR_ID_PHILIPS,
4837 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4838 .subvendor = 0x5ace,
4839 .subdevice = 0x6193,
4840 .driver_data = SAA7134_BOARD_BEHOLD_M6,
4841 },{
4842 .vendor = PCI_VENDOR_ID_PHILIPS,
4292 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 4843 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4293 .subvendor = 0x4e42, 4844 .subvendor = 0x4e42,
4294 .subdevice = 0x3502, 4845 .subdevice = 0x3502,
@@ -4351,6 +4902,34 @@ static void board_flyvideo(struct saa7134_dev *dev)
4351 4902
4352/* ----------------------------------------------------------- */ 4903/* ----------------------------------------------------------- */
4353 4904
4905static void hauppauge_eeprom(struct saa7134_dev *dev, u8 *eeprom_data)
4906{
4907 struct tveeprom tv;
4908
4909 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
4910
4911 /* Make sure we support the board model */
4912 switch (tv.model) {
4913 case 67019: /* WinTV-HVR1110 (Retail, IR Blaster, hybrid, FM, SVid/Comp, 3.5mm audio in) */
4914 case 67109: /* WinTV-HVR1000 (Retail, IR Receive, analog, no FM, SVid/Comp, 3.5mm audio in) */
4915 case 67559: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */
4916 case 67569: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM) */
4917 case 67579: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM) */
4918 case 67589: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM, SVid/Comp, RCA aud) */
4919 case 67599: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM, SVid/Comp, RCA aud) */
4920 break;
4921 default:
4922 printk(KERN_WARNING "%s: warning: "
4923 "unknown hauppauge model #%d\n", dev->name, tv.model);
4924 break;
4925 }
4926
4927 printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
4928 dev->name, tv.model);
4929}
4930
4931/* ----------------------------------------------------------- */
4932
4354int saa7134_board_init1(struct saa7134_dev *dev) 4933int saa7134_board_init1(struct saa7134_dev *dev)
4355{ 4934{
4356 /* Always print gpio, often manufacturers encode tuner type and other info. */ 4935 /* Always print gpio, often manufacturers encode tuner type and other info. */
@@ -4406,6 +4985,16 @@ int saa7134_board_init1(struct saa7134_dev *dev)
4406 case SAA7134_BOARD_ENCORE_ENLTV: 4985 case SAA7134_BOARD_ENCORE_ENLTV:
4407 case SAA7134_BOARD_ENCORE_ENLTV_FM: 4986 case SAA7134_BOARD_ENCORE_ENLTV_FM:
4408 case SAA7134_BOARD_10MOONSTVMASTER3: 4987 case SAA7134_BOARD_10MOONSTVMASTER3:
4988 case SAA7134_BOARD_BEHOLD_401:
4989 case SAA7134_BOARD_BEHOLD_403:
4990 case SAA7134_BOARD_BEHOLD_403FM:
4991 case SAA7134_BOARD_BEHOLD_405:
4992 case SAA7134_BOARD_BEHOLD_405FM:
4993 case SAA7134_BOARD_BEHOLD_407:
4994 case SAA7134_BOARD_BEHOLD_407FM:
4995 case SAA7134_BOARD_BEHOLD_409:
4996 case SAA7134_BOARD_BEHOLD_505FM:
4997 case SAA7134_BOARD_BEHOLD_507_9FM:
4409 dev->has_remote = SAA7134_REMOTE_GPIO; 4998 dev->has_remote = SAA7134_REMOTE_GPIO;
4410 break; 4999 break;
4411 case SAA7134_BOARD_FLYDVBS_LR300: 5000 case SAA7134_BOARD_FLYDVBS_LR300:
@@ -4445,6 +5034,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
4445 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x08000000, 0x00000000); 5034 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x08000000, 0x00000000);
4446 break; 5035 break;
4447 case SAA7134_BOARD_AVERMEDIA_CARDBUS: 5036 case SAA7134_BOARD_AVERMEDIA_CARDBUS:
5037 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
4448 /* power-up tuner chip */ 5038 /* power-up tuner chip */
4449 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0xffffffff, 0xffffffff); 5039 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0xffffffff, 0xffffffff);
4450 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0xffffffff, 0xffffffff); 5040 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0xffffffff, 0xffffffff);
@@ -4466,6 +5056,8 @@ int saa7134_board_init1(struct saa7134_dev *dev)
4466 case SAA7134_BOARD_PINNACLE_PCTV_310i: 5056 case SAA7134_BOARD_PINNACLE_PCTV_310i:
4467 case SAA7134_BOARD_UPMOST_PURPLE_TV: 5057 case SAA7134_BOARD_UPMOST_PURPLE_TV:
4468 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 5058 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
5059 case SAA7134_BOARD_BEHOLD_607_9FM:
5060 case SAA7134_BOARD_BEHOLD_M6:
4469 dev->has_remote = SAA7134_REMOTE_I2C; 5061 dev->has_remote = SAA7134_REMOTE_I2C;
4470 break; 5062 break;
4471 case SAA7134_BOARD_AVERMEDIA_A169_B: 5063 case SAA7134_BOARD_AVERMEDIA_A169_B:
@@ -4477,6 +5069,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
4477 break; 5069 break;
4478 case SAA7134_BOARD_AVERMEDIA_M102: 5070 case SAA7134_BOARD_AVERMEDIA_M102:
4479 /* enable tuner */ 5071 /* enable tuner */
5072 dev->has_remote = SAA7134_REMOTE_GPIO;
4480 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x8c040007, 0x8c040007); 5073 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x8c040007, 0x8c040007);
4481 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x0c0007cd, 0x0c0007cd); 5074 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x0c0007cd, 0x0c0007cd);
4482 break; 5075 break;
@@ -4570,8 +5163,17 @@ int saa7134_board_init2(struct saa7134_dev *dev)
4570 5163
4571 printk(KERN_INFO "%s Tuner type is %d\n", dev->name, dev->tuner_type); 5164 printk(KERN_INFO "%s Tuner type is %d\n", dev->name, dev->tuner_type);
4572 if (dev->tuner_type == TUNER_PHILIPS_FMD1216ME_MK3) { 5165 if (dev->tuner_type == TUNER_PHILIPS_FMD1216ME_MK3) {
4573 dev->tda9887_conf = TDA9887_PRESENT | TDA9887_PORT1_ACTIVE | TDA9887_PORT2_ACTIVE; 5166 struct v4l2_priv_tun_config tda9887_cfg;
4574 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG, &dev->tda9887_conf); 5167
5168 tda9887_cfg.tuner = TUNER_TDA9887;
5169 tda9887_cfg.priv = &dev->tda9887_conf;
5170
5171 dev->tda9887_conf = TDA9887_PRESENT |
5172 TDA9887_PORT1_ACTIVE |
5173 TDA9887_PORT2_ACTIVE;
5174
5175 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG,
5176 &tda9887_cfg);
4575 } 5177 }
4576 5178
4577 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV; 5179 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
@@ -4601,7 +5203,6 @@ int saa7134_board_init2(struct saa7134_dev *dev)
4601 break; 5203 break;
4602 case SAA7134_BOARD_PHILIPS_TIGER: 5204 case SAA7134_BOARD_PHILIPS_TIGER:
4603 case SAA7134_BOARD_PHILIPS_TIGER_S: 5205 case SAA7134_BOARD_PHILIPS_TIGER_S:
4604 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
4605 { 5206 {
4606 u8 data[] = { 0x3c, 0x33, 0x60}; 5207 u8 data[] = { 0x3c, 0x33, 0x60};
4607 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)}; 5208 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
@@ -4622,13 +5223,16 @@ int saa7134_board_init2(struct saa7134_dev *dev)
4622 i2c_transfer(&dev->i2c_adap, &msg, 1); 5223 i2c_transfer(&dev->i2c_adap, &msg, 1);
4623 } 5224 }
4624 break; 5225 break;
5226 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
5227 hauppauge_eeprom(dev, dev->eedata+0x80);
5228 /* break intentionally omitted */
4625 case SAA7134_BOARD_PINNACLE_PCTV_310i: 5229 case SAA7134_BOARD_PINNACLE_PCTV_310i:
4626 case SAA7134_BOARD_KWORLD_DVBT_210: 5230 case SAA7134_BOARD_KWORLD_DVBT_210:
4627 case SAA7134_BOARD_TEVION_DVBT_220RF: 5231 case SAA7134_BOARD_TEVION_DVBT_220RF:
4628 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 5232 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
4629 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: 5233 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
4630 case SAA7134_BOARD_MEDION_MD8800_QUADRO: 5234 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
4631 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 5235 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
4632 /* this is a hybrid board, initialize to analog mode 5236 /* this is a hybrid board, initialize to analog mode
4633 * and configure firmware eeprom address 5237 * and configure firmware eeprom address
4634 */ 5238 */
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 4f0a9157ecb1..52baa4f7f7dd 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -294,7 +294,7 @@ void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf)
294 videobuf_waiton(&buf->vb,0,0); 294 videobuf_waiton(&buf->vb,0,0);
295 videobuf_dma_unmap(q, dma); 295 videobuf_dma_unmap(q, dma);
296 videobuf_dma_free(dma); 296 videobuf_dma_free(dma);
297 buf->vb.state = STATE_NEEDS_INIT; 297 buf->vb.state = VIDEOBUF_NEEDS_INIT;
298} 298}
299 299
300/* ------------------------------------------------------------------ */ 300/* ------------------------------------------------------------------ */
@@ -313,7 +313,7 @@ int saa7134_buffer_queue(struct saa7134_dev *dev,
313 buf->activate(dev,buf,NULL); 313 buf->activate(dev,buf,NULL);
314 } else if (list_empty(&q->queue)) { 314 } else if (list_empty(&q->queue)) {
315 list_add_tail(&buf->vb.queue,&q->queue); 315 list_add_tail(&buf->vb.queue,&q->queue);
316 buf->vb.state = STATE_QUEUED; 316 buf->vb.state = VIDEOBUF_QUEUED;
317 } else { 317 } else {
318 next = list_entry(q->queue.next,struct saa7134_buf, 318 next = list_entry(q->queue.next,struct saa7134_buf,
319 vb.queue); 319 vb.queue);
@@ -322,7 +322,7 @@ int saa7134_buffer_queue(struct saa7134_dev *dev,
322 } 322 }
323 } else { 323 } else {
324 list_add_tail(&buf->vb.queue,&q->queue); 324 list_add_tail(&buf->vb.queue,&q->queue);
325 buf->vb.state = STATE_QUEUED; 325 buf->vb.state = VIDEOBUF_QUEUED;
326 } 326 }
327 return 0; 327 return 0;
328} 328}
@@ -387,7 +387,7 @@ void saa7134_buffer_timeout(unsigned long data)
387 try to start over with the next one. */ 387 try to start over with the next one. */
388 if (q->curr) { 388 if (q->curr) {
389 dprintk("timeout on %p\n",q->curr); 389 dprintk("timeout on %p\n",q->curr);
390 saa7134_buffer_finish(dev,q,STATE_ERROR); 390 saa7134_buffer_finish(dev,q,VIDEOBUF_ERROR);
391 } 391 }
392 saa7134_buffer_next(dev,q); 392 saa7134_buffer_next(dev,q);
393 spin_unlock_irqrestore(&dev->slock,flags); 393 spin_unlock_irqrestore(&dev->slock,flags);
@@ -395,8 +395,8 @@ void saa7134_buffer_timeout(unsigned long data)
395 395
396/* resends a current buffer in queue after resume */ 396/* resends a current buffer in queue after resume */
397 397
398int saa7134_buffer_requeue(struct saa7134_dev *dev, 398static int saa7134_buffer_requeue(struct saa7134_dev *dev,
399 struct saa7134_dmaqueue *q) 399 struct saa7134_dmaqueue *q)
400{ 400{
401 struct saa7134_buf *buf, *next; 401 struct saa7134_buf *buf, *next;
402 402
@@ -834,6 +834,7 @@ static struct video_device *vdev_init(struct saa7134_dev *dev,
834 vfd->minor = -1; 834 vfd->minor = -1;
835 vfd->dev = &dev->pci->dev; 835 vfd->dev = &dev->pci->dev;
836 vfd->release = video_device_release; 836 vfd->release = video_device_release;
837 vfd->debug = video_debug;
837 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 838 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
838 dev->name, type, saa7134_boards[dev->board].name); 839 dev->name, type, saa7134_boards[dev->board].name);
839 return vfd; 840 return vfd;
@@ -1052,7 +1053,9 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1052 printk(KERN_INFO "%s: registered device video%d [v4l2]\n", 1053 printk(KERN_INFO "%s: registered device video%d [v4l2]\n",
1053 dev->name,dev->video_dev->minor & 0x1f); 1054 dev->name,dev->video_dev->minor & 0x1f);
1054 1055
1055 dev->vbi_dev = vdev_init(dev,&saa7134_vbi_template,"vbi"); 1056 dev->vbi_dev = vdev_init(dev, &saa7134_video_template, "vbi");
1057 dev->vbi_dev->type = VID_TYPE_TUNER | VID_TYPE_TELETEXT;
1058
1056 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, 1059 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
1057 vbi_nr[dev->nr]); 1060 vbi_nr[dev->nr]);
1058 if (err < 0) 1061 if (err < 0)
@@ -1181,8 +1184,13 @@ static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
1181 saa_writel(SAA7134_IRQ2, 0); 1184 saa_writel(SAA7134_IRQ2, 0);
1182 saa_writel(SAA7134_MAIN_CTRL, 0); 1185 saa_writel(SAA7134_MAIN_CTRL, 0);
1183 1186
1184 synchronize_irq(pci_dev->irq);
1185 dev->insuspend = 1; 1187 dev->insuspend = 1;
1188 synchronize_irq(pci_dev->irq);
1189
1190 /* ACK interrupts once more, just in case,
1191 since the IRQ handler won't ack them anymore*/
1192
1193 saa_writel(SAA7134_IRQ_REPORT, saa_readl(SAA7134_IRQ_REPORT));
1186 1194
1187 /* Disable timeout timers - if we have active buffers, we will 1195 /* Disable timeout timers - if we have active buffers, we will
1188 fill them on resume*/ 1196 fill them on resume*/
@@ -1194,10 +1202,10 @@ static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
1194 if (dev->remote) 1202 if (dev->remote)
1195 saa7134_ir_stop(dev); 1203 saa7134_ir_stop(dev);
1196 1204
1197 pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
1198 pci_save_state(pci_dev); 1205 pci_save_state(pci_dev);
1206 pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
1199 1207
1200 return 0; 1208 return 0;
1201} 1209}
1202 1210
1203static int saa7134_resume(struct pci_dev *pci_dev) 1211static int saa7134_resume(struct pci_dev *pci_dev)
@@ -1205,8 +1213,8 @@ static int saa7134_resume(struct pci_dev *pci_dev)
1205 struct saa7134_dev *dev = pci_get_drvdata(pci_dev); 1213 struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
1206 unsigned long flags; 1214 unsigned long flags;
1207 1215
1208 pci_restore_state(pci_dev);
1209 pci_set_power_state(pci_dev, PCI_D0); 1216 pci_set_power_state(pci_dev, PCI_D0);
1217 pci_restore_state(pci_dev);
1210 1218
1211 /* Do things that are done in saa7134_initdev , 1219 /* Do things that are done in saa7134_initdev ,
1212 except of initializing memory structures.*/ 1220 except of initializing memory structures.*/
@@ -1222,6 +1230,7 @@ static int saa7134_resume(struct pci_dev *pci_dev)
1222 saa7134_ir_start(dev, dev->remote); 1230 saa7134_ir_start(dev, dev->remote);
1223 saa7134_hw_enable1(dev); 1231 saa7134_hw_enable1(dev);
1224 1232
1233 msleep(100);
1225 1234
1226 saa7134_board_init2(dev); 1235 saa7134_board_init2(dev);
1227 1236
@@ -1229,10 +1238,13 @@ static int saa7134_resume(struct pci_dev *pci_dev)
1229 saa7134_set_tvnorm_hw(dev); 1238 saa7134_set_tvnorm_hw(dev);
1230 saa7134_tvaudio_setmute(dev); 1239 saa7134_tvaudio_setmute(dev);
1231 saa7134_tvaudio_setvolume(dev, dev->ctl_volume); 1240 saa7134_tvaudio_setvolume(dev, dev->ctl_volume);
1241 saa7134_tvaudio_init(dev);
1232 saa7134_tvaudio_do_scan(dev); 1242 saa7134_tvaudio_do_scan(dev);
1233 saa7134_enable_i2s(dev); 1243 saa7134_enable_i2s(dev);
1234 saa7134_hw_enable2(dev); 1244 saa7134_hw_enable2(dev);
1235 1245
1246 saa7134_irq_video_signalchange(dev);
1247
1236 /*resume unfinished buffer(s)*/ 1248 /*resume unfinished buffer(s)*/
1237 spin_lock_irqsave(&dev->slock, flags); 1249 spin_lock_irqsave(&dev->slock, flags);
1238 saa7134_buffer_requeue(dev, &dev->video_q); 1250 saa7134_buffer_requeue(dev, &dev->video_q);
@@ -1246,6 +1258,7 @@ static int saa7134_resume(struct pci_dev *pci_dev)
1246 1258
1247 /* start DMA now*/ 1259 /* start DMA now*/
1248 dev->insuspend = 0; 1260 dev->insuspend = 0;
1261 smp_wmb();
1249 saa7134_set_dmabits(dev); 1262 saa7134_set_dmabits(dev);
1250 spin_unlock_irqrestore(&dev->slock, flags); 1263 spin_unlock_irqrestore(&dev->slock, flags);
1251 1264
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index e1ab099ec4c6..a9ca5730826f 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -1073,14 +1073,21 @@ static int dvb_init(struct saa7134_dev *dev)
1073 1073
1074static int dvb_fini(struct saa7134_dev *dev) 1074static int dvb_fini(struct saa7134_dev *dev)
1075{ 1075{
1076 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE; 1076 /* FIXME: I suspect that this code is bogus, since the entry for
1077 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1078 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1079 */
1080 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1081 struct v4l2_priv_tun_config tda9887_cfg;
1082 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
1083
1084 tda9887_cfg.tuner = TUNER_TDA9887;
1085 tda9887_cfg.priv = &on;
1077 1086
1078 switch (dev->board) {
1079 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
1080 /* otherwise we don't detect the tuner on next insmod */ 1087 /* otherwise we don't detect the tuner on next insmod */
1081 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on); 1088 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
1082 break; 1089 }
1083 }; 1090
1084 videobuf_dvb_unregister(&dev->dvb); 1091 videobuf_dvb_unregister(&dev->dvb);
1085 return 0; 1092 return 0;
1086} 1093}
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index 9322f44865b8..b1b01fa86720 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -161,152 +161,176 @@ ts_mmap(struct file *file, struct vm_area_struct * vma)
161 * video_generic_ioctl (and maybe others). userspace 161 * video_generic_ioctl (and maybe others). userspace
162 * copying is done already, arg is a kernel pointer. 162 * copying is done already, arg is a kernel pointer.
163 */ 163 */
164static int ts_do_ioctl(struct inode *inode, struct file *file, 164
165 unsigned int cmd, void *arg) 165static int empress_querycap(struct file *file, void *priv,
166 struct v4l2_capability *cap)
166{ 167{
167 struct saa7134_dev *dev = file->private_data; 168 struct saa7134_fh *fh = priv;
168 struct v4l2_ext_controls *ctrls = arg; 169 struct saa7134_dev *dev = fh->dev;
169 170
170 if (debug > 1) 171 strcpy(cap->driver, "saa7134");
171 v4l_print_ioctl(dev->name,cmd); 172 strlcpy(cap->card, saa7134_boards[dev->board].name,
172 switch (cmd) { 173 sizeof(cap->card));
173 case VIDIOC_QUERYCAP: 174 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
174 { 175 cap->version = SAA7134_VERSION_CODE;
175 struct v4l2_capability *cap = arg; 176 cap->capabilities =
176 177 V4L2_CAP_VIDEO_CAPTURE |
177 memset(cap,0,sizeof(*cap)); 178 V4L2_CAP_READWRITE |
178 strcpy(cap->driver, "saa7134"); 179 V4L2_CAP_STREAMING;
179 strlcpy(cap->card, saa7134_boards[dev->board].name, 180 return 0;
180 sizeof(cap->card)); 181}
181 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
182 cap->version = SAA7134_VERSION_CODE;
183 cap->capabilities =
184 V4L2_CAP_VIDEO_CAPTURE |
185 V4L2_CAP_READWRITE |
186 V4L2_CAP_STREAMING;
187 return 0;
188 }
189 182
190 /* --- input switching --------------------------------------- */ 183static int empress_enum_input(struct file *file, void *priv,
191 case VIDIOC_ENUMINPUT: 184 struct v4l2_input *i)
192 { 185{
193 struct v4l2_input *i = arg; 186 if (i->index != 0)
187 return -EINVAL;
194 188
195 if (i->index != 0) 189 i->type = V4L2_INPUT_TYPE_CAMERA;
196 return -EINVAL; 190 strcpy(i->name, "CCIR656");
197 i->type = V4L2_INPUT_TYPE_CAMERA;
198 strcpy(i->name,"CCIR656");
199 return 0;
200 }
201 case VIDIOC_G_INPUT:
202 {
203 int *i = arg;
204 *i = 0;
205 return 0;
206 }
207 case VIDIOC_S_INPUT:
208 {
209 int *i = arg;
210 191
211 if (*i != 0) 192 return 0;
212 return -EINVAL; 193}
213 return 0;
214 }
215 /* --- capture ioctls ---------------------------------------- */
216
217 case VIDIOC_ENUM_FMT:
218 {
219 struct v4l2_fmtdesc *f = arg;
220 int index;
221
222 index = f->index;
223 if (index != 0)
224 return -EINVAL;
225
226 memset(f,0,sizeof(*f));
227 f->index = index;
228 strlcpy(f->description, "MPEG TS", sizeof(f->description));
229 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
230 f->pixelformat = V4L2_PIX_FMT_MPEG;
231 return 0;
232 }
233 194
234 case VIDIOC_G_FMT: 195static int empress_g_input(struct file *file, void *priv, unsigned int *i)
235 { 196{
236 struct v4l2_format *f = arg; 197 *i = 0;
198 return 0;
199}
237 200
238 memset(f,0,sizeof(*f)); 201static int empress_s_input(struct file *file, void *priv, unsigned int i)
239 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 202{
203 if (i != 0)
204 return -EINVAL;
240 205
241 saa7134_i2c_call_clients(dev, cmd, arg); 206 return 0;
242 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 207}
243 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
244 return 0;
245 }
246 208
247 case VIDIOC_S_FMT: 209static int empress_enum_fmt_cap(struct file *file, void *priv,
248 { 210 struct v4l2_fmtdesc *f)
249 struct v4l2_format *f = arg; 211{
212 if (f->index != 0)
213 return -EINVAL;
250 214
251 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 215 strlcpy(f->description, "MPEG TS", sizeof(f->description));
252 return -EINVAL; 216 f->pixelformat = V4L2_PIX_FMT_MPEG;
253 217
254 saa7134_i2c_call_clients(dev, cmd, arg); 218 return 0;
255 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 219}
256 f->fmt.pix.sizeimage = TS_PACKET_SIZE* dev->ts.nr_packets;
257 return 0;
258 }
259 220
260 case VIDIOC_REQBUFS: 221static int empress_g_fmt_cap(struct file *file, void *priv,
261 return videobuf_reqbufs(&dev->empress_tsq,arg); 222 struct v4l2_format *f)
223{
224 struct saa7134_fh *fh = priv;
225 struct saa7134_dev *dev = fh->dev;
262 226
263 case VIDIOC_QUERYBUF: 227 saa7134_i2c_call_clients(dev, VIDIOC_G_FMT, f);
264 return videobuf_querybuf(&dev->empress_tsq,arg);
265 228
266 case VIDIOC_QBUF: 229 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
267 return videobuf_qbuf(&dev->empress_tsq,arg); 230 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
268 231
269 case VIDIOC_DQBUF: 232 return 0;
270 return videobuf_dqbuf(&dev->empress_tsq,arg, 233}
271 file->f_flags & O_NONBLOCK);
272 234
273 case VIDIOC_STREAMON: 235static int empress_s_fmt_cap(struct file *file, void *priv,
274 return videobuf_streamon(&dev->empress_tsq); 236 struct v4l2_format *f)
237{
238 struct saa7134_fh *fh = priv;
239 struct saa7134_dev *dev = fh->dev;
275 240
276 case VIDIOC_STREAMOFF: 241 saa7134_i2c_call_clients(dev, VIDIOC_S_FMT, f);
277 return videobuf_streamoff(&dev->empress_tsq);
278 242
279 case VIDIOC_QUERYCTRL: 243 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
280 case VIDIOC_G_CTRL: 244 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
281 case VIDIOC_S_CTRL:
282 return saa7134_common_ioctl(dev, cmd, arg);
283 245
284 case VIDIOC_S_EXT_CTRLS: 246 return 0;
285 /* count == 0 is abused in saa6752hs.c, so that special 247}
286 case is handled here explicitly. */ 248
287 if (ctrls->count == 0) 249
288 return 0; 250static int empress_reqbufs(struct file *file, void *priv,
289 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) 251 struct v4l2_requestbuffers *p)
290 return -EINVAL; 252{
291 saa7134_i2c_call_clients(dev, VIDIOC_S_EXT_CTRLS, arg); 253 struct saa7134_fh *fh = priv;
292 ts_init_encoder(dev); 254 struct saa7134_dev *dev = fh->dev;
293 return 0; 255
294 case VIDIOC_G_EXT_CTRLS: 256 return videobuf_reqbufs(&dev->empress_tsq, p);
295 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) 257}
296 return -EINVAL; 258
297 saa7134_i2c_call_clients(dev, VIDIOC_G_EXT_CTRLS, arg); 259static int empress_querybuf(struct file *file, void *priv,
260 struct v4l2_buffer *b)
261{
262 struct saa7134_fh *fh = priv;
263 struct saa7134_dev *dev = fh->dev;
264
265 return videobuf_querybuf(&dev->empress_tsq, b);
266}
267
268static int empress_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
269{
270 struct saa7134_fh *fh = priv;
271 struct saa7134_dev *dev = fh->dev;
272
273 return videobuf_qbuf(&dev->empress_tsq, b);
274}
275
276static int empress_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
277{
278 struct saa7134_fh *fh = priv;
279 struct saa7134_dev *dev = fh->dev;
280
281 return videobuf_dqbuf(&dev->empress_tsq, b,
282 file->f_flags & O_NONBLOCK);
283}
284
285static int empress_streamon(struct file *file, void *priv,
286 enum v4l2_buf_type type)
287{
288 struct saa7134_fh *fh = priv;
289 struct saa7134_dev *dev = fh->dev;
290
291 return videobuf_streamon(&dev->empress_tsq);
292}
293
294static int empress_streamoff(struct file *file, void *priv,
295 enum v4l2_buf_type type)
296{
297 struct saa7134_fh *fh = priv;
298 struct saa7134_dev *dev = fh->dev;
299
300 return videobuf_streamoff(&dev->empress_tsq);
301}
302
303static int empress_s_ext_ctrls(struct file *file, void *priv,
304 struct v4l2_ext_controls *ctrls)
305{
306 struct saa7134_fh *fh = priv;
307 struct saa7134_dev *dev = fh->dev;
308
309 /* count == 0 is abused in saa6752hs.c, so that special
310 case is handled here explicitly. */
311 if (ctrls->count == 0)
298 return 0; 312 return 0;
299 313
300 default: 314 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
301 return -ENOIOCTLCMD; 315 return -EINVAL;
302 } 316
317 saa7134_i2c_call_clients(dev, VIDIOC_S_EXT_CTRLS, ctrls);
318 ts_init_encoder(dev);
319
303 return 0; 320 return 0;
304} 321}
305 322
306static int ts_ioctl(struct inode *inode, struct file *file, 323static int empress_g_ext_ctrls(struct file *file, void *priv,
307 unsigned int cmd, unsigned long arg) 324 struct v4l2_ext_controls *ctrls)
308{ 325{
309 return video_usercopy(inode, file, cmd, arg, ts_do_ioctl); 326 struct saa7134_fh *fh = priv;
327 struct saa7134_dev *dev = fh->dev;
328
329 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
330 return -EINVAL;
331 saa7134_i2c_call_clients(dev, VIDIOC_G_EXT_CTRLS, ctrls);
332
333 return 0;
310} 334}
311 335
312static const struct file_operations ts_fops = 336static const struct file_operations ts_fops =
@@ -317,7 +341,7 @@ static const struct file_operations ts_fops =
317 .read = ts_read, 341 .read = ts_read,
318 .poll = ts_poll, 342 .poll = ts_poll,
319 .mmap = ts_mmap, 343 .mmap = ts_mmap,
320 .ioctl = ts_ioctl, 344 .ioctl = video_ioctl2,
321 .llseek = no_llseek, 345 .llseek = no_llseek,
322}; 346};
323 347
@@ -330,6 +354,29 @@ static struct video_device saa7134_empress_template =
330 .type2 = 0 /* FIXME */, 354 .type2 = 0 /* FIXME */,
331 .fops = &ts_fops, 355 .fops = &ts_fops,
332 .minor = -1, 356 .minor = -1,
357
358 .vidioc_querycap = empress_querycap,
359 .vidioc_enum_fmt_cap = empress_enum_fmt_cap,
360 .vidioc_s_fmt_cap = empress_s_fmt_cap,
361 .vidioc_g_fmt_cap = empress_g_fmt_cap,
362 .vidioc_reqbufs = empress_reqbufs,
363 .vidioc_querybuf = empress_querybuf,
364 .vidioc_qbuf = empress_qbuf,
365 .vidioc_dqbuf = empress_dqbuf,
366 .vidioc_streamon = empress_streamon,
367 .vidioc_streamoff = empress_streamoff,
368 .vidioc_s_ext_ctrls = empress_s_ext_ctrls,
369 .vidioc_g_ext_ctrls = empress_g_ext_ctrls,
370 .vidioc_enum_input = empress_enum_input,
371 .vidioc_g_input = empress_g_input,
372 .vidioc_s_input = empress_s_input,
373
374 .vidioc_queryctrl = saa7134_queryctrl,
375 .vidioc_g_ctrl = saa7134_g_ctrl,
376 .vidioc_s_ctrl = saa7134_s_ctrl,
377
378 .tvnorms = SAA7134_NORMS,
379 .current_norm = V4L2_STD_PAL,
333}; 380};
334 381
335static void empress_signal_update(struct work_struct *work) 382static void empress_signal_update(struct work_struct *work)
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 6deaad1a5480..d3322c3018f2 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -323,7 +323,6 @@ static int attach_inform(struct i2c_client *client)
323{ 323{
324 struct saa7134_dev *dev = client->adapter->algo_data; 324 struct saa7134_dev *dev = client->adapter->algo_data;
325 int tuner = dev->tuner_type; 325 int tuner = dev->tuner_type;
326 int conf = dev->tda9887_conf;
327 struct tuner_setup tun_setup; 326 struct tuner_setup tun_setup;
328 327
329 d1printk( "%s i2c attach [addr=0x%x,client=%s]\n", 328 d1printk( "%s i2c attach [addr=0x%x,client=%s]\n",
@@ -335,6 +334,7 @@ static int attach_inform(struct i2c_client *client)
335 case 0x7a: 334 case 0x7a:
336 case 0x47: 335 case 0x47:
337 case 0x71: 336 case 0x71:
337 case 0x2d:
338 { 338 {
339 struct IR_i2c *ir = i2c_get_clientdata(client); 339 struct IR_i2c *ir = i2c_get_clientdata(client);
340 d1printk("%s i2c IR detected (%s).\n", 340 d1printk("%s i2c IR detected (%s).\n",
@@ -360,7 +360,6 @@ static int attach_inform(struct i2c_client *client)
360 } 360 }
361 361
362 if (tuner != UNSET) { 362 if (tuner != UNSET) {
363
364 tun_setup.type = tuner; 363 tun_setup.type = tuner;
365 tun_setup.addr = saa7134_boards[dev->board].tuner_addr; 364 tun_setup.addr = saa7134_boards[dev->board].tuner_addr;
366 tun_setup.config = saa7134_boards[dev->board].tuner_config; 365 tun_setup.config = saa7134_boards[dev->board].tuner_config;
@@ -372,9 +371,18 @@ static int attach_inform(struct i2c_client *client)
372 371
373 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_setup); 372 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_setup);
374 } 373 }
374
375 if (tuner == TUNER_TDA9887) {
376 struct v4l2_priv_tun_config tda9887_cfg;
377
378 tda9887_cfg.tuner = TUNER_TDA9887;
379 tda9887_cfg.priv = &dev->tda9887_conf;
380
381 client->driver->command(client, TUNER_SET_CONFIG,
382 &tda9887_cfg);
383 }
375 } 384 }
376 385
377 client->driver->command(client, TDA9887_SET_CONFIG, &conf);
378 386
379 return 0; 387 return 0;
380} 388}
@@ -432,6 +440,7 @@ static char *i2c_devs[128] = {
432 [ 0xa0 >> 1 ] = "eeprom", 440 [ 0xa0 >> 1 ] = "eeprom",
433 [ 0xc0 >> 1 ] = "tuner (analog)", 441 [ 0xc0 >> 1 ] = "tuner (analog)",
434 [ 0x86 >> 1 ] = "tda9887", 442 [ 0x86 >> 1 ] = "tda9887",
443 [ 0x5a >> 1 ] = "remote control",
435}; 444};
436 445
437static void do_i2c_scan(char *name, struct i2c_client *c) 446static void do_i2c_scan(char *name, struct i2c_client *c)
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 3abaa1b8ac9d..0db955c2d9b9 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -49,9 +49,14 @@ module_param(repeat_delay, int, 0644);
49MODULE_PARM_DESC(repeat_delay, "delay before key repeat started"); 49MODULE_PARM_DESC(repeat_delay, "delay before key repeat started");
50static int repeat_period = 33; 50static int repeat_period = 33;
51module_param(repeat_period, int, 0644); 51module_param(repeat_period, int, 0644);
52MODULE_PARM_DESC(repeat_period, "repeat period between" 52MODULE_PARM_DESC(repeat_period, "repeat period between "
53 "keypresses when key is down"); 53 "keypresses when key is down");
54 54
55static unsigned int disable_other_ir;
56module_param(disable_other_ir, int, 0644);
57MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
58 "alternative remotes from other manufacturers");
59
55#define dprintk(fmt, arg...) if (ir_debug) \ 60#define dprintk(fmt, arg...) if (ir_debug) \
56 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg) 61 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
57#define i2cdprintk(fmt, arg...) if (ir_debug) \ 62#define i2cdprintk(fmt, arg...) if (ir_debug) \
@@ -154,6 +159,45 @@ static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
154 return 1; 159 return 1;
155} 160}
156 161
162
163static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
164{
165 unsigned char data[12];
166 u32 gpio;
167
168 struct saa7134_dev *dev = ir->c.adapter->algo_data;
169
170 /* rising SAA7134_GPIO_GPRESCAN reads the status */
171 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
172 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
173
174 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
175
176 if (0x400000 & ~gpio)
177 return 0; /* No button press */
178
179 ir->c.addr = 0x5a >> 1;
180
181 if (12 != i2c_master_recv(&ir->c, data, 12)) {
182 i2cdprintk("read error\n");
183 return -EIO;
184 }
185 /* IR of this card normally decode signals NEC-standard from
186 * - Sven IHOO MT 5.1R remote. xxyye718
187 * - Sven DVD HD-10xx remote. xxyyf708
188 * - BBK ...
189 * - mayby others
190 * So, skip not our, if disable full codes mode.
191 */
192 if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
193 return 0;
194
195 *ir_key = data[9];
196 *ir_raw = data[9];
197
198 return 1;
199}
200
157void saa7134_input_irq(struct saa7134_dev *dev) 201void saa7134_input_irq(struct saa7134_dev *dev)
158{ 202{
159 struct card_ir *ir = dev->remote; 203 struct card_ir *ir = dev->remote;
@@ -260,6 +304,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
260 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 304 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
261 case SAA7134_BOARD_AVERMEDIA_STUDIO_507: 305 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
262 case SAA7134_BOARD_AVERMEDIA_GO_007_FM: 306 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
307 case SAA7134_BOARD_AVERMEDIA_M102:
263 ir_codes = ir_codes_avermedia; 308 ir_codes = ir_codes_avermedia;
264 mask_keycode = 0x0007C8; 309 mask_keycode = 0x0007C8;
265 mask_keydown = 0x000010; 310 mask_keydown = 0x000010;
@@ -287,6 +332,16 @@ int saa7134_input_init1(struct saa7134_dev *dev)
287 case SAA7134_BOARD_MANLI_MTV001: 332 case SAA7134_BOARD_MANLI_MTV001:
288 case SAA7134_BOARD_MANLI_MTV002: 333 case SAA7134_BOARD_MANLI_MTV002:
289 case SAA7134_BOARD_BEHOLD_409FM: 334 case SAA7134_BOARD_BEHOLD_409FM:
335 case SAA7134_BOARD_BEHOLD_401:
336 case SAA7134_BOARD_BEHOLD_403:
337 case SAA7134_BOARD_BEHOLD_403FM:
338 case SAA7134_BOARD_BEHOLD_405:
339 case SAA7134_BOARD_BEHOLD_405FM:
340 case SAA7134_BOARD_BEHOLD_407:
341 case SAA7134_BOARD_BEHOLD_407FM:
342 case SAA7134_BOARD_BEHOLD_409:
343 case SAA7134_BOARD_BEHOLD_505FM:
344 case SAA7134_BOARD_BEHOLD_507_9FM:
290 ir_codes = ir_codes_manli; 345 ir_codes = ir_codes_manli;
291 mask_keycode = 0x001f00; 346 mask_keycode = 0x001f00;
292 mask_keyup = 0x004000; 347 mask_keyup = 0x004000;
@@ -457,6 +512,12 @@ void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
457 ir->get_key = get_key_hvr1110; 512 ir->get_key = get_key_hvr1110;
458 ir->ir_codes = ir_codes_hauppauge_new; 513 ir->ir_codes = ir_codes_hauppauge_new;
459 break; 514 break;
515 case SAA7134_BOARD_BEHOLD_607_9FM:
516 case SAA7134_BOARD_BEHOLD_M6:
517 snprintf(ir->c.name, sizeof(ir->c.name), "BeholdTV");
518 ir->get_key = get_key_beholdm6xx;
519 ir->ir_codes = ir_codes_behold;
520 break;
460 default: 521 default:
461 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board); 522 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
462 break; 523 break;
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
deleted file mode 100644
index aedf04653e0e..000000000000
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ /dev/null
@@ -1,1046 +0,0 @@
1/*
2 *
3 * device driver for philips saa7134 based TV cards
4 * oss dsp interface
5 *
6 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 * 2005 conversion to standalone module:
8 * Ricardo Cerqueira <v4l@cerqueira.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#include <linux/init.h>
26#include <linux/list.h>
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/interrupt.h>
30#include <linux/slab.h>
31#include <linux/sound.h>
32#include <linux/soundcard.h>
33
34#include "saa7134-reg.h"
35#include "saa7134.h"
36
37/* ------------------------------------------------------------------ */
38
39static unsigned int debug = 0;
40module_param(debug, int, 0644);
41MODULE_PARM_DESC(debug,"enable debug messages [oss]");
42
43static unsigned int rate = 0;
44module_param(rate, int, 0444);
45MODULE_PARM_DESC(rate,"sample rate (valid are: 32000,48000)");
46
47static unsigned int dsp_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
48MODULE_PARM_DESC(dsp_nr, "device numbers for SAA7134 capture interface(s).");
49module_param_array(dsp_nr, int, NULL, 0444);
50
51static unsigned int mixer_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
52MODULE_PARM_DESC(mixer_nr, "mixer numbers for SAA7134 capture interface(s).");
53module_param_array(mixer_nr, int, NULL, 0444);
54
55#define dprintk(fmt, arg...) if (debug) \
56 printk(KERN_DEBUG "%s/oss: " fmt, dev->name , ## arg)
57
58
59/* ------------------------------------------------------------------ */
60
61static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks)
62{
63 if (blksize < 0x100)
64 blksize = 0x100;
65 if (blksize > 0x10000)
66 blksize = 0x10000;
67
68 if (blocks < 2)
69 blocks = 2;
70 if ((blksize * blocks) > 1024*1024)
71 blocks = 1024*1024 / blksize;
72
73 dev->dmasound.blocks = blocks;
74 dev->dmasound.blksize = blksize;
75 dev->dmasound.bufsize = blksize * blocks;
76
77 dprintk("buffer config: %d blocks / %d bytes, %d kB total\n",
78 blocks,blksize,blksize * blocks / 1024);
79 return 0;
80}
81
82static int dsp_buffer_init(struct saa7134_dev *dev)
83{
84 int err;
85
86 BUG_ON(!dev->dmasound.bufsize);
87 videobuf_dma_init(&dev->dmasound.dma);
88 err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE,
89 (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT);
90 if (0 != err)
91 return err;
92 return 0;
93}
94
95static int dsp_buffer_free(struct saa7134_dev *dev)
96{
97 BUG_ON(!dev->dmasound.blksize);
98 videobuf_dma_free(&dev->dmasound.dma);
99 dev->dmasound.blocks = 0;
100 dev->dmasound.blksize = 0;
101 dev->dmasound.bufsize = 0;
102 return 0;
103}
104
105static void dsp_dma_start(struct saa7134_dev *dev)
106{
107 dev->dmasound.dma_blk = 0;
108 dev->dmasound.dma_running = 1;
109 saa7134_set_dmabits(dev);
110}
111
112static void dsp_dma_stop(struct saa7134_dev *dev)
113{
114 dev->dmasound.dma_blk = -1;
115 dev->dmasound.dma_running = 0;
116 saa7134_set_dmabits(dev);
117}
118
119static int dsp_rec_start(struct saa7134_dev *dev)
120{
121 int err, bswap, sign;
122 u32 fmt, control;
123 unsigned long flags;
124
125 /* prepare buffer */
126 if (0 != (err = videobuf_pci_dma_map(dev->pci,&dev->dmasound.dma)))
127 return err;
128 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt)))
129 goto fail1;
130 if (0 != (err = saa7134_pgtable_build(dev->pci,&dev->dmasound.pt,
131 dev->dmasound.dma.sglist,
132 dev->dmasound.dma.sglen,
133 0)))
134 goto fail2;
135
136 /* sample format */
137 switch (dev->dmasound.afmt) {
138 case AFMT_U8:
139 case AFMT_S8: fmt = 0x00; break;
140 case AFMT_U16_LE:
141 case AFMT_U16_BE:
142 case AFMT_S16_LE:
143 case AFMT_S16_BE: fmt = 0x01; break;
144 default:
145 err = -EINVAL;
146 goto fail2;
147 }
148
149 switch (dev->dmasound.afmt) {
150 case AFMT_S8:
151 case AFMT_S16_LE:
152 case AFMT_S16_BE: sign = 1; break;
153 default: sign = 0; break;
154 }
155
156 switch (dev->dmasound.afmt) {
157 case AFMT_U16_BE:
158 case AFMT_S16_BE: bswap = 1; break;
159 default: bswap = 0; break;
160 }
161
162 switch (dev->pci->device) {
163 case PCI_DEVICE_ID_PHILIPS_SAA7134:
164 if (1 == dev->dmasound.channels)
165 fmt |= (1 << 3);
166 if (2 == dev->dmasound.channels)
167 fmt |= (3 << 3);
168 if (sign)
169 fmt |= 0x04;
170 fmt |= (TV == dev->dmasound.input) ? 0xc0 : 0x80;
171
172 saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->dmasound.blksize - 1) & 0x0000ff));
173 saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->dmasound.blksize - 1) & 0x00ff00) >> 8);
174 saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->dmasound.blksize - 1) & 0xff0000) >> 16);
175 saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt);
176
177 break;
178 case PCI_DEVICE_ID_PHILIPS_SAA7133:
179 case PCI_DEVICE_ID_PHILIPS_SAA7135:
180 if (1 == dev->dmasound.channels)
181 fmt |= (1 << 4);
182 if (2 == dev->dmasound.channels)
183 fmt |= (2 << 4);
184 if (!sign)
185 fmt |= 0x04;
186 saa_writel(SAA7133_NUM_SAMPLES, dev->dmasound.blksize -4);
187 saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24));
188 break;
189 }
190 dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n",
191 dev->dmasound.afmt, dev->dmasound.channels, fmt,
192 bswap ? 'b' : '-');
193
194 /* dma: setup channel 6 (= AUDIO) */
195 control = SAA7134_RS_CONTROL_BURST_16 |
196 SAA7134_RS_CONTROL_ME |
197 (dev->dmasound.pt.dma >> 12);
198 if (bswap)
199 control |= SAA7134_RS_CONTROL_BSWAP;
200 saa_writel(SAA7134_RS_BA1(6),0);
201 saa_writel(SAA7134_RS_BA2(6),dev->dmasound.blksize);
202 saa_writel(SAA7134_RS_PITCH(6),0);
203 saa_writel(SAA7134_RS_CONTROL(6),control);
204
205 /* start dma */
206 dev->dmasound.recording_on = 1;
207 spin_lock_irqsave(&dev->slock,flags);
208 dsp_dma_start(dev);
209 spin_unlock_irqrestore(&dev->slock,flags);
210 return 0;
211
212 fail2:
213 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
214 fail1:
215 videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
216 return err;
217}
218
219static int dsp_rec_stop(struct saa7134_dev *dev)
220{
221 unsigned long flags;
222
223 dprintk("rec_stop dma_blk=%d\n",dev->dmasound.dma_blk);
224
225 /* stop dma */
226 dev->dmasound.recording_on = 0;
227 spin_lock_irqsave(&dev->slock,flags);
228 dsp_dma_stop(dev);
229 spin_unlock_irqrestore(&dev->slock,flags);
230
231 /* unlock buffer */
232 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
233 videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
234 return 0;
235}
236
237/* ------------------------------------------------------------------ */
238
239static int dsp_open(struct inode *inode, struct file *file)
240{
241 int minor = iminor(inode);
242 struct saa7134_dev *dev;
243 int err;
244
245 list_for_each_entry(dev, &saa7134_devlist, devlist)
246 if (dev->dmasound.minor_dsp == minor)
247 goto found;
248 return -ENODEV;
249 found:
250
251 mutex_lock(&dev->dmasound.lock);
252 err = -EBUSY;
253 if (dev->dmasound.users_dsp)
254 goto fail1;
255 dev->dmasound.users_dsp++;
256 file->private_data = dev;
257
258 dev->dmasound.afmt = AFMT_U8;
259 dev->dmasound.channels = 1;
260 dev->dmasound.read_count = 0;
261 dev->dmasound.read_offset = 0;
262 dsp_buffer_conf(dev,PAGE_SIZE,64);
263 err = dsp_buffer_init(dev);
264 if (0 != err)
265 goto fail2;
266
267 mutex_unlock(&dev->dmasound.lock);
268 return 0;
269
270 fail2:
271 dev->dmasound.users_dsp--;
272 fail1:
273 mutex_unlock(&dev->dmasound.lock);
274 return err;
275}
276
277static int dsp_release(struct inode *inode, struct file *file)
278{
279 struct saa7134_dev *dev = file->private_data;
280
281 mutex_lock(&dev->dmasound.lock);
282 if (dev->dmasound.recording_on)
283 dsp_rec_stop(dev);
284 dsp_buffer_free(dev);
285 dev->dmasound.users_dsp--;
286 file->private_data = NULL;
287 mutex_unlock(&dev->dmasound.lock);
288 return 0;
289}
290
291static ssize_t dsp_read(struct file *file, char __user *buffer,
292 size_t count, loff_t *ppos)
293{
294 struct saa7134_dev *dev = file->private_data;
295 DECLARE_WAITQUEUE(wait, current);
296 unsigned int bytes;
297 unsigned long flags;
298 int err,ret = 0;
299
300 add_wait_queue(&dev->dmasound.wq, &wait);
301 mutex_lock(&dev->dmasound.lock);
302 while (count > 0) {
303 /* wait for data if needed */
304 if (0 == dev->dmasound.read_count) {
305 if (!dev->dmasound.recording_on) {
306 err = dsp_rec_start(dev);
307 if (err < 0) {
308 if (0 == ret)
309 ret = err;
310 break;
311 }
312 }
313 if (dev->dmasound.recording_on &&
314 !dev->dmasound.dma_running) {
315 /* recover from overruns */
316 spin_lock_irqsave(&dev->slock,flags);
317 dsp_dma_start(dev);
318 spin_unlock_irqrestore(&dev->slock,flags);
319 }
320 if (file->f_flags & O_NONBLOCK) {
321 if (0 == ret)
322 ret = -EAGAIN;
323 break;
324 }
325 mutex_unlock(&dev->dmasound.lock);
326 set_current_state(TASK_INTERRUPTIBLE);
327 if (0 == dev->dmasound.read_count)
328 schedule();
329 set_current_state(TASK_RUNNING);
330 mutex_lock(&dev->dmasound.lock);
331 if (signal_pending(current)) {
332 if (0 == ret)
333 ret = -EINTR;
334 break;
335 }
336 }
337
338 /* copy data to userspace */
339 bytes = count;
340 if (bytes > dev->dmasound.read_count)
341 bytes = dev->dmasound.read_count;
342 if (bytes > dev->dmasound.bufsize - dev->dmasound.read_offset)
343 bytes = dev->dmasound.bufsize - dev->dmasound.read_offset;
344 if (copy_to_user(buffer + ret,
345 dev->dmasound.dma.vmalloc + dev->dmasound.read_offset,
346 bytes)) {
347 if (0 == ret)
348 ret = -EFAULT;
349 break;
350 }
351
352 ret += bytes;
353 count -= bytes;
354 dev->dmasound.read_count -= bytes;
355 dev->dmasound.read_offset += bytes;
356 if (dev->dmasound.read_offset == dev->dmasound.bufsize)
357 dev->dmasound.read_offset = 0;
358 }
359 mutex_unlock(&dev->dmasound.lock);
360 remove_wait_queue(&dev->dmasound.wq, &wait);
361 return ret;
362}
363
364static ssize_t dsp_write(struct file *file, const char __user *buffer,
365 size_t count, loff_t *ppos)
366{
367 return -EINVAL;
368}
369
370static const char *osspcm_ioctls[] = {
371 "RESET", "SYNC", "SPEED", "STEREO", "GETBLKSIZE", "SETFMT",
372 "CHANNELS", "?", "POST", "SUBDIVIDE", "SETFRAGMENT", "GETFMTS",
373 "GETOSPACE", "GETISPACE", "NONBLOCK", "GETCAPS", "GET/SETTRIGGER",
374 "GETIPTR", "GETOPTR", "MAPINBUF", "MAPOUTBUF", "SETSYNCRO",
375 "SETDUPLEX", "GETODELAY"
376};
377#define OSSPCM_IOCTLS ARRAY_SIZE(osspcm_ioctls)
378
379static void saa7134_oss_print_ioctl(char *name, unsigned int cmd)
380{
381 char *dir;
382
383 switch (_IOC_DIR(cmd)) {
384 case _IOC_NONE: dir = "--"; break;
385 case _IOC_READ: dir = "r-"; break;
386 case _IOC_WRITE: dir = "-w"; break;
387 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
388 default: dir = "??"; break;
389 }
390 switch (_IOC_TYPE(cmd)) {
391 case 'P':
392 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss dsp, %s, SNDCTL_DSP_%s)\n",
393 name, cmd, dir, (_IOC_NR(cmd) < OSSPCM_IOCTLS) ?
394 osspcm_ioctls[_IOC_NR(cmd)] : "???");
395 break;
396 case 'M':
397 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss mixer, %s, #%d)\n",
398 name, cmd, dir, _IOC_NR(cmd));
399 break;
400 default:
401 printk(KERN_DEBUG "%s: ioctl 0x%08x (???, %s, #%d)\n",
402 name, cmd, dir, _IOC_NR(cmd));
403 }
404}
405
406static int dsp_ioctl(struct inode *inode, struct file *file,
407 unsigned int cmd, unsigned long arg)
408{
409 struct saa7134_dev *dev = file->private_data;
410 void __user *argp = (void __user *) arg;
411 int __user *p = argp;
412 int val = 0;
413
414 if (debug > 1)
415 saa7134_oss_print_ioctl(dev->name,cmd);
416 switch (cmd) {
417 case OSS_GETVERSION:
418 return put_user(SOUND_VERSION, p);
419 case SNDCTL_DSP_GETCAPS:
420 return 0;
421
422 case SNDCTL_DSP_SPEED:
423 if (get_user(val, p))
424 return -EFAULT;
425 /* fall through */
426 case SOUND_PCM_READ_RATE:
427 return put_user(dev->dmasound.rate, p);
428
429 case SNDCTL_DSP_STEREO:
430 if (get_user(val, p))
431 return -EFAULT;
432 mutex_lock(&dev->dmasound.lock);
433 dev->dmasound.channels = val ? 2 : 1;
434 if (dev->dmasound.recording_on) {
435 dsp_rec_stop(dev);
436 dsp_rec_start(dev);
437 }
438 mutex_unlock(&dev->dmasound.lock);
439 return put_user(dev->dmasound.channels-1, p);
440
441 case SNDCTL_DSP_CHANNELS:
442 if (get_user(val, p))
443 return -EFAULT;
444 if (val != 1 && val != 2)
445 return -EINVAL;
446 mutex_lock(&dev->dmasound.lock);
447 dev->dmasound.channels = val;
448 if (dev->dmasound.recording_on) {
449 dsp_rec_stop(dev);
450 dsp_rec_start(dev);
451 }
452 mutex_unlock(&dev->dmasound.lock);
453 /* fall through */
454 case SOUND_PCM_READ_CHANNELS:
455 return put_user(dev->dmasound.channels, p);
456
457 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
458 return put_user(AFMT_U8 | AFMT_S8 |
459 AFMT_U16_LE | AFMT_U16_BE |
460 AFMT_S16_LE | AFMT_S16_BE, p);
461
462 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */
463 if (get_user(val, p))
464 return -EFAULT;
465 switch (val) {
466 case AFMT_QUERY:
467 /* nothing to do */
468 break;
469 case AFMT_U8:
470 case AFMT_S8:
471 case AFMT_U16_LE:
472 case AFMT_U16_BE:
473 case AFMT_S16_LE:
474 case AFMT_S16_BE:
475 mutex_lock(&dev->dmasound.lock);
476 dev->dmasound.afmt = val;
477 if (dev->dmasound.recording_on) {
478 dsp_rec_stop(dev);
479 dsp_rec_start(dev);
480 }
481 mutex_unlock(&dev->dmasound.lock);
482 return put_user(dev->dmasound.afmt, p);
483 default:
484 return -EINVAL;
485 }
486
487 case SOUND_PCM_READ_BITS:
488 switch (dev->dmasound.afmt) {
489 case AFMT_U8:
490 case AFMT_S8:
491 return put_user(8, p);
492 case AFMT_U16_LE:
493 case AFMT_U16_BE:
494 case AFMT_S16_LE:
495 case AFMT_S16_BE:
496 return put_user(16, p);
497 default:
498 return -EINVAL;
499 }
500
501 case SNDCTL_DSP_NONBLOCK:
502 file->f_flags |= O_NONBLOCK;
503 return 0;
504
505 case SNDCTL_DSP_RESET:
506 mutex_lock(&dev->dmasound.lock);
507 if (dev->dmasound.recording_on)
508 dsp_rec_stop(dev);
509 mutex_unlock(&dev->dmasound.lock);
510 return 0;
511 case SNDCTL_DSP_GETBLKSIZE:
512 return put_user(dev->dmasound.blksize, p);
513
514 case SNDCTL_DSP_SETFRAGMENT:
515 if (get_user(val, p))
516 return -EFAULT;
517 if (dev->dmasound.recording_on)
518 return -EBUSY;
519 dsp_buffer_free(dev);
520 /* used to be arg >> 16 instead of val >> 16; fixed */
521 dsp_buffer_conf(dev,1 << (val & 0xffff), (val >> 16) & 0xffff);
522 dsp_buffer_init(dev);
523 return 0;
524
525 case SNDCTL_DSP_SYNC:
526 /* NOP */
527 return 0;
528
529 case SNDCTL_DSP_GETISPACE:
530 {
531 audio_buf_info info;
532 info.fragsize = dev->dmasound.blksize;
533 info.fragstotal = dev->dmasound.blocks;
534 info.bytes = dev->dmasound.read_count;
535 info.fragments = info.bytes / info.fragsize;
536 if (copy_to_user(argp, &info, sizeof(info)))
537 return -EFAULT;
538 return 0;
539 }
540 default:
541 return -EINVAL;
542 }
543}
544
545static unsigned int dsp_poll(struct file *file, struct poll_table_struct *wait)
546{
547 struct saa7134_dev *dev = file->private_data;
548 unsigned int mask = 0;
549
550 poll_wait(file, &dev->dmasound.wq, wait);
551
552 if (0 == dev->dmasound.read_count) {
553 mutex_lock(&dev->dmasound.lock);
554 if (!dev->dmasound.recording_on)
555 dsp_rec_start(dev);
556 mutex_unlock(&dev->dmasound.lock);
557 } else
558 mask |= (POLLIN | POLLRDNORM);
559 return mask;
560}
561
562const struct file_operations saa7134_dsp_fops = {
563 .owner = THIS_MODULE,
564 .open = dsp_open,
565 .release = dsp_release,
566 .read = dsp_read,
567 .write = dsp_write,
568 .ioctl = dsp_ioctl,
569 .poll = dsp_poll,
570 .llseek = no_llseek,
571};
572
573/* ------------------------------------------------------------------ */
574
575static int
576mixer_recsrc_7134(struct saa7134_dev *dev)
577{
578 int analog_io,rate;
579
580 switch (dev->dmasound.input) {
581 case TV:
582 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0xc0);
583 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00);
584 break;
585 case LINE1:
586 case LINE2:
587 case LINE2_LEFT:
588 analog_io = (LINE1 == dev->dmasound.input) ? 0x00 : 0x08;
589 rate = (32000 == dev->dmasound.rate) ? 0x01 : 0x03;
590 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, analog_io);
591 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0x80);
592 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, rate);
593 break;
594 }
595 return 0;
596}
597
598static int
599mixer_recsrc_7133(struct saa7134_dev *dev)
600{
601 u32 anabar, xbarin;
602
603 xbarin = 0x03; // adc
604 anabar = 0;
605 switch (dev->dmasound.input) {
606 case TV:
607 xbarin = 0; // Demodulator
608 anabar = 2; // DACs
609 break;
610 case LINE1:
611 anabar = 0; // aux1, aux1
612 break;
613 case LINE2:
614 case LINE2_LEFT:
615 anabar = 9; // aux2, aux2
616 break;
617 }
618 /* output xbar always main channel */
619 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbb10);
620 saa_dsp_writel(dev, 0x464 >> 2, xbarin);
621 saa_writel(0x594 >> 2, anabar);
622
623 return 0;
624}
625
626static int
627mixer_recsrc(struct saa7134_dev *dev, enum saa7134_audio_in src)
628{
629 static const char *iname[] = { "Oops", "TV", "LINE1", "LINE2" };
630
631 dev->dmasound.count++;
632 dev->dmasound.input = src;
633 dprintk("mixer input = %s\n",iname[dev->dmasound.input]);
634
635 switch (dev->pci->device) {
636 case PCI_DEVICE_ID_PHILIPS_SAA7134:
637 mixer_recsrc_7134(dev);
638 break;
639 case PCI_DEVICE_ID_PHILIPS_SAA7133:
640 case PCI_DEVICE_ID_PHILIPS_SAA7135:
641 mixer_recsrc_7133(dev);
642 break;
643 }
644 return 0;
645}
646
647static int
648mixer_level(struct saa7134_dev *dev, enum saa7134_audio_in src, int level)
649{
650 switch (dev->pci->device) {
651 case PCI_DEVICE_ID_PHILIPS_SAA7134:
652 switch (src) {
653 case TV:
654 /* nothing */
655 break;
656 case LINE1:
657 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x10,
658 (100 == level) ? 0x00 : 0x10);
659 break;
660 case LINE2:
661 case LINE2_LEFT:
662 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x20,
663 (100 == level) ? 0x00 : 0x20);
664 break;
665 }
666 break;
667 case PCI_DEVICE_ID_PHILIPS_SAA7133:
668 case PCI_DEVICE_ID_PHILIPS_SAA7135:
669 /* nothing */
670 break;
671 }
672 return 0;
673}
674
675/* ------------------------------------------------------------------ */
676
677static int mixer_open(struct inode *inode, struct file *file)
678{
679 int minor = iminor(inode);
680 struct saa7134_dev *dev;
681
682 list_for_each_entry(dev, &saa7134_devlist, devlist)
683 if (dev->dmasound.minor_mixer == minor) {
684 file->private_data = dev;
685 return 0;
686 }
687 return -ENODEV;
688}
689
690static int mixer_release(struct inode *inode, struct file *file)
691{
692 file->private_data = NULL;
693 return 0;
694}
695
696static int mixer_ioctl(struct inode *inode, struct file *file,
697 unsigned int cmd, unsigned long arg)
698{
699 struct saa7134_dev *dev = file->private_data;
700 enum saa7134_audio_in input;
701 int val,ret;
702 void __user *argp = (void __user *) arg;
703 int __user *p = argp;
704
705 if (debug > 1)
706 saa7134_oss_print_ioctl(dev->name,cmd);
707 switch (cmd) {
708 case OSS_GETVERSION:
709 return put_user(SOUND_VERSION, p);
710 case SOUND_MIXER_INFO:
711 {
712 mixer_info info;
713 memset(&info,0,sizeof(info));
714 strlcpy(info.id, "TV audio", sizeof(info.id));
715 strlcpy(info.name, dev->name, sizeof(info.name));
716 info.modify_counter = dev->dmasound.count;
717 if (copy_to_user(argp, &info, sizeof(info)))
718 return -EFAULT;
719 return 0;
720 }
721 case SOUND_OLD_MIXER_INFO:
722 {
723 _old_mixer_info info;
724 memset(&info,0,sizeof(info));
725 strlcpy(info.id, "TV audio", sizeof(info.id));
726 strlcpy(info.name, dev->name, sizeof(info.name));
727 if (copy_to_user(argp, &info, sizeof(info)))
728 return -EFAULT;
729 return 0;
730 }
731 case MIXER_READ(SOUND_MIXER_CAPS):
732 return put_user(SOUND_CAP_EXCL_INPUT, p);
733 case MIXER_READ(SOUND_MIXER_STEREODEVS):
734 return put_user(0, p);
735 case MIXER_READ(SOUND_MIXER_RECMASK):
736 case MIXER_READ(SOUND_MIXER_DEVMASK):
737 val = SOUND_MASK_LINE1 | SOUND_MASK_LINE2;
738 if (32000 == dev->dmasound.rate)
739 val |= SOUND_MASK_VIDEO;
740 return put_user(val, p);
741
742 case MIXER_WRITE(SOUND_MIXER_RECSRC):
743 if (get_user(val, p))
744 return -EFAULT;
745 input = dev->dmasound.input;
746 if (32000 == dev->dmasound.rate &&
747 val & SOUND_MASK_VIDEO && dev->dmasound.input != TV)
748 input = TV;
749 if (val & SOUND_MASK_LINE1 && dev->dmasound.input != LINE1)
750 input = LINE1;
751 if (val & SOUND_MASK_LINE2 && dev->dmasound.input != LINE2)
752 input = LINE2;
753 if (input != dev->dmasound.input)
754 mixer_recsrc(dev,input);
755 /* fall throuth */
756 case MIXER_READ(SOUND_MIXER_RECSRC):
757 switch (dev->dmasound.input) {
758 case TV: ret = SOUND_MASK_VIDEO; break;
759 case LINE1: ret = SOUND_MASK_LINE1; break;
760 case LINE2: ret = SOUND_MASK_LINE2; break;
761 default: ret = 0;
762 }
763 return put_user(ret, p);
764
765 case MIXER_WRITE(SOUND_MIXER_VIDEO):
766 case MIXER_READ(SOUND_MIXER_VIDEO):
767 if (32000 != dev->dmasound.rate)
768 return -EINVAL;
769 return put_user(100 | 100 << 8, p);
770
771 case MIXER_WRITE(SOUND_MIXER_LINE1):
772 if (get_user(val, p))
773 return -EFAULT;
774 val &= 0xff;
775 val = (val <= 50) ? 50 : 100;
776 dev->dmasound.line1 = val;
777 mixer_level(dev,LINE1,dev->dmasound.line1);
778 /* fall throuth */
779 case MIXER_READ(SOUND_MIXER_LINE1):
780 return put_user(dev->dmasound.line1 | dev->dmasound.line1 << 8, p);
781
782 case MIXER_WRITE(SOUND_MIXER_LINE2):
783 if (get_user(val, p))
784 return -EFAULT;
785 val &= 0xff;
786 val = (val <= 50) ? 50 : 100;
787 dev->dmasound.line2 = val;
788 mixer_level(dev,LINE2,dev->dmasound.line2);
789 /* fall throuth */
790 case MIXER_READ(SOUND_MIXER_LINE2):
791 return put_user(dev->dmasound.line2 | dev->dmasound.line2 << 8, p);
792
793 default:
794 return -EINVAL;
795 }
796}
797
798const struct file_operations saa7134_mixer_fops = {
799 .owner = THIS_MODULE,
800 .open = mixer_open,
801 .release = mixer_release,
802 .ioctl = mixer_ioctl,
803 .llseek = no_llseek,
804};
805
806/* ------------------------------------------------------------------ */
807
808static irqreturn_t saa7134_oss_irq(int irq, void *dev_id)
809{
810 struct saa7134_dmasound *dmasound = dev_id;
811 struct saa7134_dev *dev = dmasound->priv_data;
812 unsigned long report, status;
813 int loop, handled = 0;
814
815 for (loop = 0; loop < 10; loop++) {
816 report = saa_readl(SAA7134_IRQ_REPORT);
817 status = saa_readl(SAA7134_IRQ_STATUS);
818
819 if (report & SAA7134_IRQ_REPORT_DONE_RA3) {
820 handled = 1;
821 saa_writel(SAA7134_IRQ_REPORT,report);
822 saa7134_irq_oss_done(dev, status);
823 } else {
824 goto out;
825 }
826 }
827
828 if (loop == 10) {
829 dprintk("error! looping IRQ!");
830 }
831out:
832 return IRQ_RETVAL(handled);
833}
834
835int saa7134_oss_init1(struct saa7134_dev *dev)
836{
837
838 if ((request_irq(dev->pci->irq, saa7134_oss_irq,
839 IRQF_SHARED | IRQF_DISABLED, dev->name,
840 (void*) &dev->dmasound)) < 0)
841 return -1;
842
843 /* general */
844 mutex_init(&dev->dmasound.lock);
845 init_waitqueue_head(&dev->dmasound.wq);
846
847 switch (dev->pci->device) {
848 case PCI_DEVICE_ID_PHILIPS_SAA7133:
849 case PCI_DEVICE_ID_PHILIPS_SAA7135:
850 saa_writel(0x588 >> 2, 0x00000fff);
851 saa_writel(0x58c >> 2, 0x00543210);
852 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbbbb);
853 break;
854 }
855
856 /* dsp */
857 dev->dmasound.rate = 32000;
858 if (rate)
859 dev->dmasound.rate = rate;
860 dev->dmasound.rate = (dev->dmasound.rate > 40000) ? 48000 : 32000;
861
862 /* mixer */
863 dev->dmasound.line1 = 50;
864 dev->dmasound.line2 = 50;
865 mixer_level(dev,LINE1,dev->dmasound.line1);
866 mixer_level(dev,LINE2,dev->dmasound.line2);
867 mixer_recsrc(dev, (dev->dmasound.rate == 32000) ? TV : LINE2);
868
869 return 0;
870}
871
872int saa7134_oss_fini(struct saa7134_dev *dev)
873{
874 /* nothing */
875 return 0;
876}
877
878void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status)
879{
880 int next_blk, reg = 0;
881
882 spin_lock(&dev->slock);
883 if (UNSET == dev->dmasound.dma_blk) {
884 dprintk("irq: recording stopped\n");
885 goto done;
886 }
887 if (0 != (status & 0x0f000000))
888 dprintk("irq: lost %ld\n", (status >> 24) & 0x0f);
889 if (0 == (status & 0x10000000)) {
890 /* odd */
891 if (0 == (dev->dmasound.dma_blk & 0x01))
892 reg = SAA7134_RS_BA1(6);
893 } else {
894 /* even */
895 if (1 == (dev->dmasound.dma_blk & 0x01))
896 reg = SAA7134_RS_BA2(6);
897 }
898 if (0 == reg) {
899 dprintk("irq: field oops [%s]\n",
900 (status & 0x10000000) ? "even" : "odd");
901 goto done;
902 }
903 if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) {
904 dprintk("irq: overrun [full=%d/%d]\n",dev->dmasound.read_count,
905 dev->dmasound.bufsize);
906 dsp_dma_stop(dev);
907 goto done;
908 }
909
910 /* next block addr */
911 next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks;
912 saa_writel(reg,next_blk * dev->dmasound.blksize);
913 if (debug > 2)
914 dprintk("irq: ok, %s, next_blk=%d, addr=%x\n",
915 (status & 0x10000000) ? "even" : "odd ", next_blk,
916 next_blk * dev->dmasound.blksize);
917
918 /* update status & wake waiting readers */
919 dev->dmasound.dma_blk = (dev->dmasound.dma_blk + 1) % dev->dmasound.blocks;
920 dev->dmasound.read_count += dev->dmasound.blksize;
921 wake_up(&dev->dmasound.wq);
922
923 done:
924 spin_unlock(&dev->slock);
925}
926
927static int saa7134_dsp_create(struct saa7134_dev *dev)
928{
929 int err;
930
931 err = dev->dmasound.minor_dsp =
932 register_sound_dsp(&saa7134_dsp_fops,
933 dsp_nr[dev->nr]);
934 if (err < 0) {
935 goto fail;
936 }
937 printk(KERN_INFO "%s: registered device dsp%d\n",
938 dev->name,dev->dmasound.minor_dsp >> 4);
939
940 err = dev->dmasound.minor_mixer =
941 register_sound_mixer(&saa7134_mixer_fops,
942 mixer_nr[dev->nr]);
943 if (err < 0)
944 goto fail;
945 printk(KERN_INFO "%s: registered device mixer%d\n",
946 dev->name,dev->dmasound.minor_mixer >> 4);
947
948 return 0;
949
950fail:
951 unregister_sound_dsp(dev->dmasound.minor_dsp);
952 return 0;
953
954
955}
956
957static int oss_device_init(struct saa7134_dev *dev)
958{
959 dev->dmasound.priv_data = dev;
960 saa7134_oss_init1(dev);
961 saa7134_dsp_create(dev);
962 return 1;
963}
964
965static int oss_device_exit(struct saa7134_dev *dev)
966{
967
968 unregister_sound_mixer(dev->dmasound.minor_mixer);
969 unregister_sound_dsp(dev->dmasound.minor_dsp);
970
971 saa7134_oss_fini(dev);
972
973 if (dev->pci->irq > 0) {
974 synchronize_irq(dev->pci->irq);
975 free_irq(dev->pci->irq,&dev->dmasound);
976 }
977
978 dev->dmasound.priv_data = NULL;
979 return 1;
980}
981
982static int saa7134_oss_init(void)
983{
984 struct saa7134_dev *dev = NULL;
985 struct list_head *list;
986
987 if (!saa7134_dmasound_init && !saa7134_dmasound_exit) {
988 saa7134_dmasound_init = oss_device_init;
989 saa7134_dmasound_exit = oss_device_exit;
990 } else {
991 printk(KERN_WARNING "saa7134 OSS: can't load, DMA sound handler already assigned (probably to ALSA)\n");
992 return -EBUSY;
993 }
994
995 printk(KERN_INFO "saa7134 OSS driver for DMA sound loaded\n");
996
997
998 list_for_each(list,&saa7134_devlist) {
999 dev = list_entry(list, struct saa7134_dev, devlist);
1000 if (dev->dmasound.priv_data == NULL) {
1001 oss_device_init(dev);
1002 } else {
1003 printk(KERN_ERR "saa7134 OSS: DMA sound is being handled by ALSA, ignoring %s\n",dev->name);
1004 return -EBUSY;
1005 }
1006 }
1007
1008 if (dev == NULL)
1009 printk(KERN_INFO "saa7134 OSS: no saa7134 cards found\n");
1010
1011 return 0;
1012
1013}
1014
1015static void saa7134_oss_exit(void)
1016{
1017 struct saa7134_dev *dev;
1018
1019 list_for_each_entry(dev, &saa7134_devlist, devlist) {
1020 /* Device isn't registered by OSS, probably ALSA's */
1021 if (!dev->dmasound.minor_dsp)
1022 continue;
1023
1024 oss_device_exit(dev);
1025 }
1026
1027 saa7134_dmasound_init = NULL;
1028 saa7134_dmasound_exit = NULL;
1029
1030 printk(KERN_INFO "saa7134 OSS driver for DMA sound unloaded\n");
1031
1032 return;
1033}
1034
1035/* We initialize this late, to make sure the sound system is up and running */
1036late_initcall(saa7134_oss_init);
1037module_exit(saa7134_oss_exit);
1038MODULE_LICENSE("GPL");
1039MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
1040
1041/* ----------------------------------------------------------- */
1042/*
1043 * Local variables:
1044 * c-basic-offset: 8
1045 * End:
1046 */
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index 4b63ad3e8466..f1b8fcaeb43a 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -47,7 +47,7 @@ static int buffer_activate(struct saa7134_dev *dev,
47{ 47{
48 48
49 dprintk("buffer_activate [%p]",buf); 49 dprintk("buffer_activate [%p]",buf);
50 buf->vb.state = STATE_ACTIVE; 50 buf->vb.state = VIDEOBUF_ACTIVE;
51 buf->top_seen = 0; 51 buf->top_seen = 0;
52 52
53 if (NULL == next) 53 if (NULL == next)
@@ -91,7 +91,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
91 saa7134_dma_free(q,buf); 91 saa7134_dma_free(q,buf);
92 } 92 }
93 93
94 if (STATE_NEEDS_INIT == buf->vb.state) { 94 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
95 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); 95 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
96 96
97 buf->vb.width = llength; 97 buf->vb.width = llength;
@@ -121,7 +121,7 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
121 saa_writel(SAA7134_RS_PITCH(5),TS_PACKET_SIZE); 121 saa_writel(SAA7134_RS_PITCH(5),TS_PACKET_SIZE);
122 saa_writel(SAA7134_RS_CONTROL(5),control); 122 saa_writel(SAA7134_RS_CONTROL(5),control);
123 123
124 buf->vb.state = STATE_PREPARED; 124 buf->vb.state = VIDEOBUF_PREPARED;
125 buf->activate = buffer_activate; 125 buf->activate = buffer_activate;
126 buf->vb.field = field; 126 buf->vb.field = field;
127 return 0; 127 return 0;
@@ -242,7 +242,7 @@ void saa7134_irq_ts_done(struct saa7134_dev *dev, unsigned long status)
242 if ((status & 0x100000) != 0x100000) 242 if ((status & 0x100000) != 0x100000)
243 goto done; 243 goto done;
244 } 244 }
245 saa7134_buffer_finish(dev,&dev->ts_q,STATE_DONE); 245 saa7134_buffer_finish(dev,&dev->ts_q,VIDEOBUF_DONE);
246 } 246 }
247 saa7134_buffer_next(dev,&dev->ts_q); 247 saa7134_buffer_next(dev,&dev->ts_q);
248 248
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index f8e304c76232..4e9810469ae3 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -163,32 +163,6 @@ static struct saa7134_tvaudio tvaudio[] = {
163 163
164/* ------------------------------------------------------------------ */ 164/* ------------------------------------------------------------------ */
165 165
166static void tvaudio_init(struct saa7134_dev *dev)
167{
168 int clock = saa7134_boards[dev->board].audio_clock;
169
170 if (UNSET != audio_clock_override)
171 clock = audio_clock_override;
172
173 /* init all audio registers */
174 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x00);
175 if (need_resched())
176 schedule();
177 else
178 udelay(10);
179
180 saa_writeb(SAA7134_AUDIO_CLOCK0, clock & 0xff);
181 saa_writeb(SAA7134_AUDIO_CLOCK1, (clock >> 8) & 0xff);
182 saa_writeb(SAA7134_AUDIO_CLOCK2, (clock >> 16) & 0xff);
183 /* frame locked audio is mandatory for NICAM */
184 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x01);
185
186 saa_writeb(SAA7134_NICAM_ERROR_LOW, 0x14);
187 saa_writeb(SAA7134_NICAM_ERROR_HIGH, 0x50);
188 saa_writeb(SAA7134_MONITOR_SELECT, 0xa0);
189 saa_writeb(SAA7134_FM_DEMATRIX, 0x80);
190}
191
192static u32 tvaudio_carr2reg(u32 carrier) 166static u32 tvaudio_carr2reg(u32 carrier)
193{ 167{
194 u64 a = carrier; 168 u64 a = carrier;
@@ -517,9 +491,13 @@ static int tvaudio_thread(void *data)
517 dev->thread.scan1 = dev->thread.scan2; 491 dev->thread.scan1 = dev->thread.scan2;
518 dprintk("tvaudio thread scan start [%d]\n",dev->thread.scan1); 492 dprintk("tvaudio thread scan start [%d]\n",dev->thread.scan1);
519 dev->tvaudio = NULL; 493 dev->tvaudio = NULL;
520 tvaudio_init(dev); 494
495 saa_writeb(SAA7134_MONITOR_SELECT, 0xa0);
496 saa_writeb(SAA7134_FM_DEMATRIX, 0x80);
497
521 if (dev->ctl_automute) 498 if (dev->ctl_automute)
522 dev->automute = 1; 499 dev->automute = 1;
500
523 mute_input_7134(dev); 501 mute_input_7134(dev);
524 502
525 /* give the tuner some time */ 503 /* give the tuner some time */
@@ -784,27 +762,15 @@ static int mute_input_7133(struct saa7134_dev *dev)
784static int tvaudio_thread_ddep(void *data) 762static int tvaudio_thread_ddep(void *data)
785{ 763{
786 struct saa7134_dev *dev = data; 764 struct saa7134_dev *dev = data;
787 u32 value, norms, clock; 765 u32 value, norms;
788 766
789 767
790 set_freezable(); 768 set_freezable();
791
792 clock = saa7134_boards[dev->board].audio_clock;
793 if (UNSET != audio_clock_override)
794 clock = audio_clock_override;
795 saa_writel(0x598 >> 2, clock);
796
797 /* unmute */
798 saa_dsp_writel(dev, 0x474 >> 2, 0x00);
799 saa_dsp_writel(dev, 0x450 >> 2, 0x00);
800
801 for (;;) { 769 for (;;) {
802 tvaudio_sleep(dev,-1); 770 tvaudio_sleep(dev,-1);
803 if (kthread_should_stop()) 771 if (kthread_should_stop())
804 goto done; 772 goto done;
805
806 restart: 773 restart:
807
808 try_to_freeze(); 774 try_to_freeze();
809 775
810 dev->thread.scan1 = dev->thread.scan2; 776 dev->thread.scan1 = dev->thread.scan2;
@@ -978,6 +944,38 @@ int saa7134_tvaudio_getstereo(struct saa7134_dev *dev)
978 return retval; 944 return retval;
979} 945}
980 946
947void saa7134_tvaudio_init(struct saa7134_dev *dev)
948{
949 int clock = saa7134_boards[dev->board].audio_clock;
950
951 if (UNSET != audio_clock_override)
952 clock = audio_clock_override;
953
954 switch (dev->pci->device) {
955 case PCI_DEVICE_ID_PHILIPS_SAA7134:
956 /* init all audio registers */
957 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x00);
958 if (need_resched())
959 schedule();
960 else
961 udelay(10);
962
963 saa_writeb(SAA7134_AUDIO_CLOCK0, clock & 0xff);
964 saa_writeb(SAA7134_AUDIO_CLOCK1, (clock >> 8) & 0xff);
965 saa_writeb(SAA7134_AUDIO_CLOCK2, (clock >> 16) & 0xff);
966 /* frame locked audio is mandatory for NICAM */
967 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x01);
968 saa_writeb(SAA7134_NICAM_ERROR_LOW, 0x14);
969 saa_writeb(SAA7134_NICAM_ERROR_HIGH, 0x50);
970 break;
971 case PCI_DEVICE_ID_PHILIPS_SAA7133:
972 case PCI_DEVICE_ID_PHILIPS_SAA7135:
973 saa_writel(0x598 >> 2, clock);
974 saa_dsp_writel(dev, 0x474 >> 2, 0x00);
975 saa_dsp_writel(dev, 0x450 >> 2, 0x00);
976 }
977}
978
981int saa7134_tvaudio_init2(struct saa7134_dev *dev) 979int saa7134_tvaudio_init2(struct saa7134_dev *dev)
982{ 980{
983 int (*my_thread)(void *data) = NULL; 981 int (*my_thread)(void *data) = NULL;
@@ -994,6 +992,7 @@ int saa7134_tvaudio_init2(struct saa7134_dev *dev)
994 992
995 dev->thread.thread = NULL; 993 dev->thread.thread = NULL;
996 if (my_thread) { 994 if (my_thread) {
995 saa7134_tvaudio_init(dev);
997 /* start tvaudio thread */ 996 /* start tvaudio thread */
998 dev->thread.thread = kthread_run(my_thread, dev, "%s", dev->name); 997 dev->thread.thread = kthread_run(my_thread, dev, "%s", dev->name);
999 if (IS_ERR(dev->thread.thread)) { 998 if (IS_ERR(dev->thread.thread)) {
diff --git a/drivers/media/video/saa7134/saa7134-vbi.c b/drivers/media/video/saa7134/saa7134-vbi.c
index 81a2aedeff5c..f0d5ed9c2b06 100644
--- a/drivers/media/video/saa7134/saa7134-vbi.c
+++ b/drivers/media/video/saa7134/saa7134-vbi.c
@@ -85,7 +85,7 @@ static int buffer_activate(struct saa7134_dev *dev,
85 unsigned long control,base; 85 unsigned long control,base;
86 86
87 dprintk("buffer_activate [%p]\n",buf); 87 dprintk("buffer_activate [%p]\n",buf);
88 buf->vb.state = STATE_ACTIVE; 88 buf->vb.state = VIDEOBUF_ACTIVE;
89 buf->top_seen = 0; 89 buf->top_seen = 0;
90 90
91 task_init(dev,buf,TASK_A); 91 task_init(dev,buf,TASK_A);
@@ -136,7 +136,7 @@ static int buffer_prepare(struct videobuf_queue *q,
136 if (buf->vb.size != size) 136 if (buf->vb.size != size)
137 saa7134_dma_free(q,buf); 137 saa7134_dma_free(q,buf);
138 138
139 if (STATE_NEEDS_INIT == buf->vb.state) { 139 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
140 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); 140 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
141 141
142 buf->vb.width = llength; 142 buf->vb.width = llength;
@@ -154,7 +154,7 @@ static int buffer_prepare(struct videobuf_queue *q,
154 if (err) 154 if (err)
155 goto oops; 155 goto oops;
156 } 156 }
157 buf->vb.state = STATE_PREPARED; 157 buf->vb.state = VIDEOBUF_PREPARED;
158 buf->activate = buffer_activate; 158 buf->activate = buffer_activate;
159 buf->vb.field = field; 159 buf->vb.field = field;
160 return 0; 160 return 0;
@@ -240,7 +240,7 @@ void saa7134_irq_vbi_done(struct saa7134_dev *dev, unsigned long status)
240 goto done; 240 goto done;
241 241
242 dev->vbi_q.curr->vb.field_count = dev->vbi_fieldcount; 242 dev->vbi_q.curr->vb.field_count = dev->vbi_fieldcount;
243 saa7134_buffer_finish(dev,&dev->vbi_q,STATE_DONE); 243 saa7134_buffer_finish(dev,&dev->vbi_q,VIDEOBUF_DONE);
244 } 244 }
245 saa7134_buffer_next(dev,&dev->vbi_q); 245 saa7134_buffer_next(dev,&dev->vbi_q);
246 246
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 6396d9b5c063..1184d359e848 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -38,7 +38,7 @@
38 38
39/* ------------------------------------------------------------------ */ 39/* ------------------------------------------------------------------ */
40 40
41static unsigned int video_debug = 0; 41unsigned int video_debug;
42static unsigned int gbuffers = 8; 42static unsigned int gbuffers = 8;
43static unsigned int noninterlaced = 0; 43static unsigned int noninterlaced = 0;
44static unsigned int gbufsize = 720*576*4; 44static unsigned int gbufsize = 720*576*4;
@@ -54,7 +54,7 @@ module_param_string(secam, secam, sizeof(secam), 0644);
54MODULE_PARM_DESC(secam, "force SECAM variant, either DK,L or Lc"); 54MODULE_PARM_DESC(secam, "force SECAM variant, either DK,L or Lc");
55 55
56 56
57#define dprintk(fmt, arg...) if (video_debug) \ 57#define dprintk(fmt, arg...) if (video_debug&0x04) \
58 printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg) 58 printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg)
59 59
60/* ------------------------------------------------------------------ */ 60/* ------------------------------------------------------------------ */
@@ -540,9 +540,8 @@ void res_free(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bits)
540 540
541/* ------------------------------------------------------------------ */ 541/* ------------------------------------------------------------------ */
542 542
543void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm) 543static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
544{ 544{
545
546 dprintk("set tv norm = %s\n",norm->name); 545 dprintk("set tv norm = %s\n",norm->name);
547 dev->tvnorm = norm; 546 dev->tvnorm = norm;
548 547
@@ -561,7 +560,6 @@ void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
561 dev->crop_current = dev->crop_defrect; 560 dev->crop_current = dev->crop_defrect;
562 561
563 saa7134_set_tvnorm_hw(dev); 562 saa7134_set_tvnorm_hw(dev);
564
565} 563}
566 564
567static void video_mux(struct saa7134_dev *dev, int input) 565static void video_mux(struct saa7134_dev *dev, int input)
@@ -945,7 +943,7 @@ static int buffer_activate(struct saa7134_dev *dev,
945 unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */ 943 unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
946 944
947 dprintk("buffer_activate buf=%p\n",buf); 945 dprintk("buffer_activate buf=%p\n",buf);
948 buf->vb.state = STATE_ACTIVE; 946 buf->vb.state = VIDEOBUF_ACTIVE;
949 buf->top_seen = 0; 947 buf->top_seen = 0;
950 948
951 set_size(dev,TASK_A,buf->vb.width,buf->vb.height, 949 set_size(dev,TASK_A,buf->vb.width,buf->vb.height,
@@ -1054,7 +1052,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1054 saa7134_dma_free(q,buf); 1052 saa7134_dma_free(q,buf);
1055 } 1053 }
1056 1054
1057 if (STATE_NEEDS_INIT == buf->vb.state) { 1055 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
1058 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); 1056 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
1059 1057
1060 buf->vb.width = fh->width; 1058 buf->vb.width = fh->width;
@@ -1074,7 +1072,7 @@ static int buffer_prepare(struct videobuf_queue *q,
1074 if (err) 1072 if (err)
1075 goto oops; 1073 goto oops;
1076 } 1074 }
1077 buf->vb.state = STATE_PREPARED; 1075 buf->vb.state = VIDEOBUF_PREPARED;
1078 buf->activate = buffer_activate; 1076 buf->activate = buffer_activate;
1079 return 0; 1077 return 0;
1080 1078
@@ -1119,8 +1117,10 @@ static struct videobuf_queue_ops video_qops = {
1119 1117
1120/* ------------------------------------------------------------------ */ 1118/* ------------------------------------------------------------------ */
1121 1119
1122static int get_control(struct saa7134_dev *dev, struct v4l2_control *c) 1120int saa7134_g_ctrl(struct file *file, void *priv, struct v4l2_control *c)
1123{ 1121{
1122 struct saa7134_fh *fh = priv;
1123 struct saa7134_dev *dev = fh->dev;
1124 const struct v4l2_queryctrl* ctrl; 1124 const struct v4l2_queryctrl* ctrl;
1125 1125
1126 ctrl = ctrl_by_id(c->id); 1126 ctrl = ctrl_by_id(c->id);
@@ -1165,17 +1165,27 @@ static int get_control(struct saa7134_dev *dev, struct v4l2_control *c)
1165 } 1165 }
1166 return 0; 1166 return 0;
1167} 1167}
1168EXPORT_SYMBOL_GPL(saa7134_g_ctrl);
1168 1169
1169static int set_control(struct saa7134_dev *dev, struct saa7134_fh *fh, 1170int saa7134_s_ctrl(struct file *file, void *f, struct v4l2_control *c)
1170 struct v4l2_control *c)
1171{ 1171{
1172 const struct v4l2_queryctrl* ctrl; 1172 const struct v4l2_queryctrl* ctrl;
1173 struct saa7134_fh *fh = f;
1174 struct saa7134_dev *dev = fh->dev;
1173 unsigned long flags; 1175 unsigned long flags;
1174 int restart_overlay = 0; 1176 int restart_overlay = 0;
1177 int err = -EINVAL;
1178
1179 err = v4l2_prio_check(&dev->prio, &fh->prio);
1180 if (0 != err)
1181 return err;
1182
1183 mutex_lock(&dev->lock);
1175 1184
1176 ctrl = ctrl_by_id(c->id); 1185 ctrl = ctrl_by_id(c->id);
1177 if (NULL == ctrl) 1186 if (NULL == ctrl)
1178 return -EINVAL; 1187 goto error;
1188
1179 dprintk("set_control name=%s val=%d\n",ctrl->name,c->value); 1189 dprintk("set_control name=%s val=%d\n",ctrl->name,c->value);
1180 switch (ctrl->type) { 1190 switch (ctrl->type) {
1181 case V4L2_CTRL_TYPE_BOOLEAN: 1191 case V4L2_CTRL_TYPE_BOOLEAN:
@@ -1236,18 +1246,26 @@ static int set_control(struct saa7134_dev *dev, struct saa7134_fh *fh,
1236 restart_overlay = 1; 1246 restart_overlay = 1;
1237 break; 1247 break;
1238 case V4L2_CID_PRIVATE_AUTOMUTE: 1248 case V4L2_CID_PRIVATE_AUTOMUTE:
1249 {
1250 struct v4l2_priv_tun_config tda9887_cfg;
1251
1252 tda9887_cfg.tuner = TUNER_TDA9887;
1253 tda9887_cfg.priv = &dev->tda9887_conf;
1254
1239 dev->ctl_automute = c->value; 1255 dev->ctl_automute = c->value;
1240 if (dev->tda9887_conf) { 1256 if (dev->tda9887_conf) {
1241 if (dev->ctl_automute) 1257 if (dev->ctl_automute)
1242 dev->tda9887_conf |= TDA9887_AUTOMUTE; 1258 dev->tda9887_conf |= TDA9887_AUTOMUTE;
1243 else 1259 else
1244 dev->tda9887_conf &= ~TDA9887_AUTOMUTE; 1260 dev->tda9887_conf &= ~TDA9887_AUTOMUTE;
1245 saa7134_i2c_call_clients(dev, TDA9887_SET_CONFIG, 1261
1246 &dev->tda9887_conf); 1262 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG,
1263 &tda9887_cfg);
1247 } 1264 }
1248 break; 1265 break;
1266 }
1249 default: 1267 default:
1250 return -EINVAL; 1268 goto error;
1251 } 1269 }
1252 if (restart_overlay && fh && res_check(fh, RESOURCE_OVERLAY)) { 1270 if (restart_overlay && fh && res_check(fh, RESOURCE_OVERLAY)) {
1253 spin_lock_irqsave(&dev->slock,flags); 1271 spin_lock_irqsave(&dev->slock,flags);
@@ -1255,8 +1273,13 @@ static int set_control(struct saa7134_dev *dev, struct saa7134_fh *fh,
1255 start_preview(dev,fh); 1273 start_preview(dev,fh);
1256 spin_unlock_irqrestore(&dev->slock,flags); 1274 spin_unlock_irqrestore(&dev->slock,flags);
1257 } 1275 }
1258 return 0; 1276 err = 0;
1277
1278error:
1279 mutex_unlock(&dev->lock);
1280 return err;
1259} 1281}
1282EXPORT_SYMBOL_GPL(saa7134_s_ctrl);
1260 1283
1261/* ------------------------------------------------------------------ */ 1284/* ------------------------------------------------------------------ */
1262 1285
@@ -1413,8 +1436,8 @@ video_poll(struct file *file, struct poll_table_struct *wait)
1413 return POLLERR; 1436 return POLLERR;
1414 1437
1415 poll_wait(file, &buf->done, wait); 1438 poll_wait(file, &buf->done, wait);
1416 if (buf->state == STATE_DONE || 1439 if (buf->state == VIDEOBUF_DONE ||
1417 buf->state == STATE_ERROR) 1440 buf->state == VIDEOBUF_ERROR)
1418 return POLLIN|POLLRDNORM; 1441 return POLLIN|POLLRDNORM;
1419 return 0; 1442 return 0;
1420} 1443}
@@ -1478,8 +1501,11 @@ static int video_mmap(struct file *file, struct vm_area_struct * vma)
1478 1501
1479/* ------------------------------------------------------------------ */ 1502/* ------------------------------------------------------------------ */
1480 1503
1481static void saa7134_vbi_fmt(struct saa7134_dev *dev, struct v4l2_format *f) 1504static int saa7134_try_get_set_fmt_vbi(struct file *file, void *priv,
1505 struct v4l2_format *f)
1482{ 1506{
1507 struct saa7134_fh *fh = priv;
1508 struct saa7134_dev *dev = fh->dev;
1483 struct saa7134_tvnorm *norm = dev->tvnorm; 1509 struct saa7134_tvnorm *norm = dev->tvnorm;
1484 1510
1485 f->fmt.vbi.sampling_rate = 6750000 * 4; 1511 f->fmt.vbi.sampling_rate = 6750000 * 4;
@@ -1492,837 +1518,805 @@ static void saa7134_vbi_fmt(struct saa7134_dev *dev, struct v4l2_format *f)
1492 f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; 1518 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1493 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */ 1519 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */
1494 1520
1521 return 0;
1495} 1522}
1496 1523
1497static int saa7134_g_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh, 1524static int saa7134_g_fmt_cap(struct file *file, void *priv,
1498 struct v4l2_format *f) 1525 struct v4l2_format *f)
1499{ 1526{
1500 switch (f->type) { 1527 struct saa7134_fh *fh = priv;
1501 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1528
1502 memset(&f->fmt.pix,0,sizeof(f->fmt.pix)); 1529 f->fmt.pix.width = fh->width;
1503 f->fmt.pix.width = fh->width; 1530 f->fmt.pix.height = fh->height;
1504 f->fmt.pix.height = fh->height; 1531 f->fmt.pix.field = fh->cap.field;
1505 f->fmt.pix.field = fh->cap.field; 1532 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1506 f->fmt.pix.pixelformat = fh->fmt->fourcc; 1533 f->fmt.pix.bytesperline =
1507 f->fmt.pix.bytesperline = 1534 (f->fmt.pix.width * fh->fmt->depth) >> 3;
1508 (f->fmt.pix.width * fh->fmt->depth) >> 3; 1535 f->fmt.pix.sizeimage =
1509 f->fmt.pix.sizeimage = 1536 f->fmt.pix.height * f->fmt.pix.bytesperline;
1510 f->fmt.pix.height * f->fmt.pix.bytesperline; 1537 return 0;
1511 return 0;
1512 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1513 if (saa7134_no_overlay > 0) {
1514 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1515 return -EINVAL;
1516 }
1517 f->fmt.win = fh->win;
1518 return 0;
1519 case V4L2_BUF_TYPE_VBI_CAPTURE:
1520 saa7134_vbi_fmt(dev,f);
1521 return 0;
1522 default:
1523 return -EINVAL;
1524 }
1525} 1538}
1526 1539
1527static int saa7134_try_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh, 1540static int saa7134_g_fmt_overlay(struct file *file, void *priv,
1528 struct v4l2_format *f) 1541 struct v4l2_format *f)
1529{ 1542{
1530 int err; 1543 struct saa7134_fh *fh = priv;
1531 1544
1532 switch (f->type) { 1545 if (saa7134_no_overlay > 0) {
1533 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1546 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1534 { 1547 return -EINVAL;
1535 struct saa7134_format *fmt; 1548 }
1536 enum v4l2_field field; 1549 f->fmt.win = fh->win;
1537 unsigned int maxw, maxh;
1538 1550
1539 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 1551 return 0;
1540 if (NULL == fmt) 1552}
1541 return -EINVAL;
1542 1553
1543 field = f->fmt.pix.field; 1554static int saa7134_try_fmt_cap(struct file *file, void *priv,
1544 maxw = min(dev->crop_current.width*4, dev->crop_bounds.width); 1555 struct v4l2_format *f)
1545 maxh = min(dev->crop_current.height*4, dev->crop_bounds.height); 1556{
1557 struct saa7134_fh *fh = priv;
1558 struct saa7134_dev *dev = fh->dev;
1559 struct saa7134_format *fmt;
1560 enum v4l2_field field;
1561 unsigned int maxw, maxh;
1546 1562
1547 if (V4L2_FIELD_ANY == field) { 1563 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1548 field = (f->fmt.pix.height > maxh/2) 1564 if (NULL == fmt)
1549 ? V4L2_FIELD_INTERLACED 1565 return -EINVAL;
1550 : V4L2_FIELD_BOTTOM;
1551 }
1552 switch (field) {
1553 case V4L2_FIELD_TOP:
1554 case V4L2_FIELD_BOTTOM:
1555 maxh = maxh / 2;
1556 break;
1557 case V4L2_FIELD_INTERLACED:
1558 break;
1559 default:
1560 return -EINVAL;
1561 }
1562 1566
1563 f->fmt.pix.field = field; 1567 field = f->fmt.pix.field;
1564 if (f->fmt.pix.width < 48) 1568 maxw = min(dev->crop_current.width*4, dev->crop_bounds.width);
1565 f->fmt.pix.width = 48; 1569 maxh = min(dev->crop_current.height*4, dev->crop_bounds.height);
1566 if (f->fmt.pix.height < 32)
1567 f->fmt.pix.height = 32;
1568 if (f->fmt.pix.width > maxw)
1569 f->fmt.pix.width = maxw;
1570 if (f->fmt.pix.height > maxh)
1571 f->fmt.pix.height = maxh;
1572 f->fmt.pix.width &= ~0x03;
1573 f->fmt.pix.bytesperline =
1574 (f->fmt.pix.width * fmt->depth) >> 3;
1575 f->fmt.pix.sizeimage =
1576 f->fmt.pix.height * f->fmt.pix.bytesperline;
1577 1570
1578 return 0; 1571 if (V4L2_FIELD_ANY == field) {
1572 field = (f->fmt.pix.height > maxh/2)
1573 ? V4L2_FIELD_INTERLACED
1574 : V4L2_FIELD_BOTTOM;
1579 } 1575 }
1580 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1576 switch (field) {
1581 if (saa7134_no_overlay > 0) { 1577 case V4L2_FIELD_TOP:
1582 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); 1578 case V4L2_FIELD_BOTTOM:
1583 return -EINVAL; 1579 maxh = maxh / 2;
1584 } 1580 break;
1585 err = verify_preview(dev,&f->fmt.win); 1581 case V4L2_FIELD_INTERLACED:
1586 if (0 != err) 1582 break;
1587 return err;
1588 return 0;
1589 case V4L2_BUF_TYPE_VBI_CAPTURE:
1590 saa7134_vbi_fmt(dev,f);
1591 return 0;
1592 default: 1583 default:
1593 return -EINVAL; 1584 return -EINVAL;
1594 } 1585 }
1586
1587 f->fmt.pix.field = field;
1588 if (f->fmt.pix.width < 48)
1589 f->fmt.pix.width = 48;
1590 if (f->fmt.pix.height < 32)
1591 f->fmt.pix.height = 32;
1592 if (f->fmt.pix.width > maxw)
1593 f->fmt.pix.width = maxw;
1594 if (f->fmt.pix.height > maxh)
1595 f->fmt.pix.height = maxh;
1596 f->fmt.pix.width &= ~0x03;
1597 f->fmt.pix.bytesperline =
1598 (f->fmt.pix.width * fmt->depth) >> 3;
1599 f->fmt.pix.sizeimage =
1600 f->fmt.pix.height * f->fmt.pix.bytesperline;
1601
1602 return 0;
1595} 1603}
1596 1604
1597static int saa7134_s_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh, 1605static int saa7134_try_fmt_overlay(struct file *file, void *priv,
1598 struct v4l2_format *f) 1606 struct v4l2_format *f)
1599{ 1607{
1600 unsigned long flags; 1608 struct saa7134_fh *fh = priv;
1601 int err; 1609 struct saa7134_dev *dev = fh->dev;
1602
1603 switch (f->type) {
1604 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1605 err = saa7134_try_fmt(dev,fh,f);
1606 if (0 != err)
1607 return err;
1608
1609 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1610 fh->width = f->fmt.pix.width;
1611 fh->height = f->fmt.pix.height;
1612 fh->cap.field = f->fmt.pix.field;
1613 return 0;
1614 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1615 if (saa7134_no_overlay > 0) {
1616 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1617 return -EINVAL;
1618 }
1619 err = verify_preview(dev,&f->fmt.win);
1620 if (0 != err)
1621 return err;
1622
1623 mutex_lock(&dev->lock);
1624 fh->win = f->fmt.win;
1625 fh->nclips = f->fmt.win.clipcount;
1626 if (fh->nclips > 8)
1627 fh->nclips = 8;
1628 if (copy_from_user(fh->clips,f->fmt.win.clips,
1629 sizeof(struct v4l2_clip)*fh->nclips)) {
1630 mutex_unlock(&dev->lock);
1631 return -EFAULT;
1632 }
1633 1610
1634 if (res_check(fh, RESOURCE_OVERLAY)) { 1611 if (saa7134_no_overlay > 0) {
1635 spin_lock_irqsave(&dev->slock,flags); 1612 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1636 stop_preview(dev,fh);
1637 start_preview(dev,fh);
1638 spin_unlock_irqrestore(&dev->slock,flags);
1639 }
1640 mutex_unlock(&dev->lock);
1641 return 0;
1642 case V4L2_BUF_TYPE_VBI_CAPTURE:
1643 saa7134_vbi_fmt(dev,f);
1644 return 0;
1645 default:
1646 return -EINVAL; 1613 return -EINVAL;
1647 } 1614 }
1615
1616 return verify_preview(dev, &f->fmt.win);
1648} 1617}
1649 1618
1650int saa7134_common_ioctl(struct saa7134_dev *dev, 1619static int saa7134_s_fmt_cap(struct file *file, void *priv,
1651 unsigned int cmd, void *arg) 1620 struct v4l2_format *f)
1652{ 1621{
1622 struct saa7134_fh *fh = priv;
1653 int err; 1623 int err;
1654 1624
1655 switch (cmd) { 1625 err = saa7134_try_fmt_cap(file, priv, f);
1656 case VIDIOC_QUERYCTRL: 1626 if (0 != err)
1657 { 1627 return err;
1658 const struct v4l2_queryctrl *ctrl;
1659 struct v4l2_queryctrl *c = arg;
1660 1628
1661 if ((c->id < V4L2_CID_BASE || 1629 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1662 c->id >= V4L2_CID_LASTP1) && 1630 fh->width = f->fmt.pix.width;
1663 (c->id < V4L2_CID_PRIVATE_BASE || 1631 fh->height = f->fmt.pix.height;
1664 c->id >= V4L2_CID_PRIVATE_LASTP1)) 1632 fh->cap.field = f->fmt.pix.field;
1665 return -EINVAL; 1633 return 0;
1666 ctrl = ctrl_by_id(c->id); 1634}
1667 *c = (NULL != ctrl) ? *ctrl : no_ctrl; 1635
1668 return 0; 1636static int saa7134_s_fmt_overlay(struct file *file, void *priv,
1637 struct v4l2_format *f)
1638{
1639 struct saa7134_fh *fh = priv;
1640 struct saa7134_dev *dev = fh->dev;
1641 int err;
1642 unsigned int flags;
1643
1644 if (saa7134_no_overlay > 0) {
1645 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1646 return -EINVAL;
1669 } 1647 }
1670 case VIDIOC_G_CTRL: 1648 err = verify_preview(dev, &f->fmt.win);
1671 return get_control(dev,arg); 1649 if (0 != err)
1672 case VIDIOC_S_CTRL:
1673 {
1674 mutex_lock(&dev->lock);
1675 err = set_control(dev,NULL,arg);
1676 mutex_unlock(&dev->lock);
1677 return err; 1650 return err;
1678 }
1679 /* --- input switching --------------------------------------- */
1680 case VIDIOC_ENUMINPUT:
1681 {
1682 struct v4l2_input *i = arg;
1683 unsigned int n;
1684 1651
1685 n = i->index; 1652 mutex_lock(&dev->lock);
1686 if (n >= SAA7134_INPUT_MAX)
1687 return -EINVAL;
1688 if (NULL == card_in(dev,i->index).name)
1689 return -EINVAL;
1690 memset(i,0,sizeof(*i));
1691 i->index = n;
1692 i->type = V4L2_INPUT_TYPE_CAMERA;
1693 strcpy(i->name,card_in(dev,n).name);
1694 if (card_in(dev,n).tv)
1695 i->type = V4L2_INPUT_TYPE_TUNER;
1696 i->audioset = 1;
1697 if (n == dev->ctl_input) {
1698 int v1 = saa_readb(SAA7134_STATUS_VIDEO1);
1699 int v2 = saa_readb(SAA7134_STATUS_VIDEO2);
1700
1701 if (0 != (v1 & 0x40))
1702 i->status |= V4L2_IN_ST_NO_H_LOCK;
1703 if (0 != (v2 & 0x40))
1704 i->status |= V4L2_IN_ST_NO_SYNC;
1705 if (0 != (v2 & 0x0e))
1706 i->status |= V4L2_IN_ST_MACROVISION;
1707 }
1708 for (n = 0; n < TVNORMS; n++)
1709 i->std |= tvnorms[n].id;
1710 return 0;
1711 }
1712 case VIDIOC_G_INPUT:
1713 {
1714 int *i = arg;
1715 *i = dev->ctl_input;
1716 return 0;
1717 }
1718 case VIDIOC_S_INPUT:
1719 {
1720 int *i = arg;
1721 1653
1722 if (*i < 0 || *i >= SAA7134_INPUT_MAX) 1654 fh->win = f->fmt.win;
1723 return -EINVAL; 1655 fh->nclips = f->fmt.win.clipcount;
1724 if (NULL == card_in(dev,*i).name) 1656
1725 return -EINVAL; 1657 if (fh->nclips > 8)
1726 mutex_lock(&dev->lock); 1658 fh->nclips = 8;
1727 video_mux(dev,*i); 1659
1660 if (copy_from_user(fh->clips, f->fmt.win.clips,
1661 sizeof(struct v4l2_clip)*fh->nclips)) {
1728 mutex_unlock(&dev->lock); 1662 mutex_unlock(&dev->lock);
1729 return 0; 1663 return -EFAULT;
1730 } 1664 }
1731 1665
1666 if (res_check(fh, RESOURCE_OVERLAY)) {
1667 spin_lock_irqsave(&dev->slock, flags);
1668 stop_preview(dev, fh);
1669 start_preview(dev, fh);
1670 spin_unlock_irqrestore(&dev->slock, flags);
1732 } 1671 }
1672
1673 mutex_unlock(&dev->lock);
1733 return 0; 1674 return 0;
1734} 1675}
1735EXPORT_SYMBOL(saa7134_common_ioctl);
1736 1676
1737/* 1677int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c)
1738 * This function is _not_ called directly, but from
1739 * video_generic_ioctl (and maybe others). userspace
1740 * copying is done already, arg is a kernel pointer.
1741 */
1742static int video_do_ioctl(struct inode *inode, struct file *file,
1743 unsigned int cmd, void *arg)
1744{ 1678{
1745 struct saa7134_fh *fh = file->private_data; 1679 const struct v4l2_queryctrl *ctrl;
1680
1681 if ((c->id < V4L2_CID_BASE ||
1682 c->id >= V4L2_CID_LASTP1) &&
1683 (c->id < V4L2_CID_PRIVATE_BASE ||
1684 c->id >= V4L2_CID_PRIVATE_LASTP1))
1685 return -EINVAL;
1686 ctrl = ctrl_by_id(c->id);
1687 *c = (NULL != ctrl) ? *ctrl : no_ctrl;
1688 return 0;
1689}
1690EXPORT_SYMBOL_GPL(saa7134_queryctrl);
1691
1692static int saa7134_enum_input(struct file *file, void *priv,
1693 struct v4l2_input *i)
1694{
1695 struct saa7134_fh *fh = priv;
1696 struct saa7134_dev *dev = fh->dev;
1697 unsigned int n;
1698
1699 n = i->index;
1700 if (n >= SAA7134_INPUT_MAX)
1701 return -EINVAL;
1702 if (NULL == card_in(dev, i->index).name)
1703 return -EINVAL;
1704 memset(i, 0, sizeof(*i));
1705 i->index = n;
1706 i->type = V4L2_INPUT_TYPE_CAMERA;
1707 strcpy(i->name, card_in(dev, n).name);
1708 if (card_in(dev, n).tv)
1709 i->type = V4L2_INPUT_TYPE_TUNER;
1710 i->audioset = 1;
1711 if (n == dev->ctl_input) {
1712 int v1 = saa_readb(SAA7134_STATUS_VIDEO1);
1713 int v2 = saa_readb(SAA7134_STATUS_VIDEO2);
1714
1715 if (0 != (v1 & 0x40))
1716 i->status |= V4L2_IN_ST_NO_H_LOCK;
1717 if (0 != (v2 & 0x40))
1718 i->status |= V4L2_IN_ST_NO_SYNC;
1719 if (0 != (v2 & 0x0e))
1720 i->status |= V4L2_IN_ST_MACROVISION;
1721 }
1722 i->std = SAA7134_NORMS;
1723 return 0;
1724}
1725
1726static int saa7134_g_input(struct file *file, void *priv, unsigned int *i)
1727{
1728 struct saa7134_fh *fh = priv;
1729 struct saa7134_dev *dev = fh->dev;
1730
1731 *i = dev->ctl_input;
1732 return 0;
1733}
1734
1735static int saa7134_s_input(struct file *file, void *priv, unsigned int i)
1736{
1737 struct saa7134_fh *fh = priv;
1746 struct saa7134_dev *dev = fh->dev; 1738 struct saa7134_dev *dev = fh->dev;
1747 unsigned long flags;
1748 int err; 1739 int err;
1749 1740
1750 if (video_debug > 1) 1741 err = v4l2_prio_check(&dev->prio, &fh->prio);
1751 v4l_print_ioctl(dev->name,cmd); 1742 if (0 != err)
1752 1743 return err;
1753 switch (cmd) {
1754 case VIDIOC_S_CTRL:
1755 case VIDIOC_S_STD:
1756 case VIDIOC_S_INPUT:
1757 case VIDIOC_S_TUNER:
1758 case VIDIOC_S_FREQUENCY:
1759 err = v4l2_prio_check(&dev->prio,&fh->prio);
1760 if (0 != err)
1761 return err;
1762 }
1763 1744
1764 switch (cmd) { 1745 if (i < 0 || i >= SAA7134_INPUT_MAX)
1765 case VIDIOC_QUERYCAP: 1746 return -EINVAL;
1766 { 1747 if (NULL == card_in(dev, i).name)
1767 struct v4l2_capability *cap = arg; 1748 return -EINVAL;
1768 unsigned int tuner_type = dev->tuner_type; 1749 mutex_lock(&dev->lock);
1769 1750 video_mux(dev, i);
1770 memset(cap,0,sizeof(*cap)); 1751 mutex_unlock(&dev->lock);
1771 strcpy(cap->driver, "saa7134"); 1752 return 0;
1772 strlcpy(cap->card, saa7134_boards[dev->board].name, 1753}
1773 sizeof(cap->card));
1774 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1775 cap->version = SAA7134_VERSION_CODE;
1776 cap->capabilities =
1777 V4L2_CAP_VIDEO_CAPTURE |
1778 V4L2_CAP_VBI_CAPTURE |
1779 V4L2_CAP_READWRITE |
1780 V4L2_CAP_STREAMING |
1781 V4L2_CAP_TUNER;
1782 if (saa7134_no_overlay <= 0) {
1783 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
1784 }
1785 1754
1786 if ((tuner_type == TUNER_ABSENT) || (tuner_type == UNSET)) 1755static int saa7134_querycap(struct file *file, void *priv,
1787 cap->capabilities &= ~V4L2_CAP_TUNER; 1756 struct v4l2_capability *cap)
1757{
1758 struct saa7134_fh *fh = priv;
1759 struct saa7134_dev *dev = fh->dev;
1788 1760
1761 unsigned int tuner_type = dev->tuner_type;
1762
1763 strcpy(cap->driver, "saa7134");
1764 strlcpy(cap->card, saa7134_boards[dev->board].name,
1765 sizeof(cap->card));
1766 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
1767 cap->version = SAA7134_VERSION_CODE;
1768 cap->capabilities =
1769 V4L2_CAP_VIDEO_CAPTURE |
1770 V4L2_CAP_VBI_CAPTURE |
1771 V4L2_CAP_READWRITE |
1772 V4L2_CAP_STREAMING |
1773 V4L2_CAP_TUNER;
1774 if (saa7134_no_overlay <= 0)
1775 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
1776
1777 if ((tuner_type == TUNER_ABSENT) || (tuner_type == UNSET))
1778 cap->capabilities &= ~V4L2_CAP_TUNER;
1789 return 0; 1779 return 0;
1790 } 1780}
1791 1781
1792 /* --- tv standards ------------------------------------------ */ 1782static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
1793 case VIDIOC_ENUMSTD: 1783{
1794 { 1784 struct saa7134_fh *fh = priv;
1795 struct v4l2_standard *e = arg; 1785 struct saa7134_dev *dev = fh->dev;
1796 unsigned int i; 1786 unsigned long flags;
1787 unsigned int i;
1788 v4l2_std_id fixup;
1789 int err;
1797 1790
1798 i = e->index; 1791 err = v4l2_prio_check(&dev->prio, &fh->prio);
1799 if (i >= TVNORMS) 1792 if (0 != err)
1800 return -EINVAL; 1793 return err;
1801 err = v4l2_video_std_construct(e, tvnorms[e->index].id,
1802 tvnorms[e->index].name);
1803 e->index = i;
1804 if (err < 0)
1805 return err;
1806 return 0;
1807 }
1808 case VIDIOC_G_STD:
1809 {
1810 v4l2_std_id *id = arg;
1811 1794
1812 *id = dev->tvnorm->id; 1795 for (i = 0; i < TVNORMS; i++)
1813 return 0; 1796 if (*id == tvnorms[i].id)
1814 } 1797 break;
1815 case VIDIOC_S_STD:
1816 {
1817 v4l2_std_id *id = arg;
1818 unsigned int i;
1819 v4l2_std_id fixup;
1820 1798
1799 if (i == TVNORMS)
1821 for (i = 0; i < TVNORMS; i++) 1800 for (i = 0; i < TVNORMS; i++)
1822 if (*id == tvnorms[i].id) 1801 if (*id & tvnorms[i].id)
1823 break; 1802 break;
1824 if (i == TVNORMS) 1803 if (i == TVNORMS)
1825 for (i = 0; i < TVNORMS; i++) 1804 return -EINVAL;
1826 if (*id & tvnorms[i].id) 1805
1827 break; 1806 if ((*id & V4L2_STD_SECAM) && (secam[0] != '-')) {
1828 if (i == TVNORMS) 1807 if (secam[0] == 'L' || secam[0] == 'l') {
1829 return -EINVAL; 1808 if (secam[1] == 'C' || secam[1] == 'c')
1830 if ((*id & V4L2_STD_SECAM) && (secam[0] != '-')) { 1809 fixup = V4L2_STD_SECAM_LC;
1831 if (secam[0] == 'L' || secam[0] == 'l') { 1810 else
1832 if (secam[1] == 'C' || secam[1] == 'c') 1811 fixup = V4L2_STD_SECAM_L;
1833 fixup = V4L2_STD_SECAM_LC; 1812 } else {
1834 else 1813 if (secam[0] == 'D' || secam[0] == 'd')
1835 fixup = V4L2_STD_SECAM_L; 1814 fixup = V4L2_STD_SECAM_DK;
1836 } else { 1815 else
1837 if (secam[0] == 'D' || secam[0] == 'd') 1816 fixup = V4L2_STD_SECAM;
1838 fixup = V4L2_STD_SECAM_DK;
1839 else
1840 fixup = V4L2_STD_SECAM;
1841 }
1842 for (i = 0; i < TVNORMS; i++)
1843 if (fixup == tvnorms[i].id)
1844 break;
1845 } 1817 }
1846 mutex_lock(&dev->lock); 1818 for (i = 0; i < TVNORMS; i++)
1847 if (res_check(fh, RESOURCE_OVERLAY)) { 1819 if (fixup == tvnorms[i].id)
1848 spin_lock_irqsave(&dev->slock,flags); 1820 break;
1849 stop_preview(dev,fh);
1850 spin_unlock_irqrestore(&dev->slock, flags);
1851
1852 set_tvnorm(dev,&tvnorms[i]);
1853
1854 spin_lock_irqsave(&dev->slock, flags);
1855 start_preview(dev,fh);
1856 spin_unlock_irqrestore(&dev->slock,flags);
1857 } else
1858 set_tvnorm(dev,&tvnorms[i]);
1859 saa7134_tvaudio_do_scan(dev);
1860 mutex_unlock(&dev->lock);
1861 return 0;
1862 } 1821 }
1863 1822
1864 case VIDIOC_CROPCAP: 1823 *id = tvnorms[i].id;
1865 {
1866 struct v4l2_cropcap *cap = arg;
1867 1824
1868 if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && 1825 mutex_lock(&dev->lock);
1869 cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) 1826 if (res_check(fh, RESOURCE_OVERLAY)) {
1870 return -EINVAL; 1827 spin_lock_irqsave(&dev->slock, flags);
1871 cap->bounds = dev->crop_bounds; 1828 stop_preview(dev, fh);
1872 cap->defrect = dev->crop_defrect; 1829 spin_unlock_irqrestore(&dev->slock, flags);
1873 cap->pixelaspect.numerator = 1;
1874 cap->pixelaspect.denominator = 1;
1875 if (dev->tvnorm->id & V4L2_STD_525_60) {
1876 cap->pixelaspect.numerator = 11;
1877 cap->pixelaspect.denominator = 10;
1878 }
1879 if (dev->tvnorm->id & V4L2_STD_625_50) {
1880 cap->pixelaspect.numerator = 54;
1881 cap->pixelaspect.denominator = 59;
1882 }
1883 return 0;
1884 }
1885 1830
1886 case VIDIOC_G_CROP: 1831 set_tvnorm(dev, &tvnorms[i]);
1887 {
1888 struct v4l2_crop * crop = arg;
1889 1832
1890 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && 1833 spin_lock_irqsave(&dev->slock, flags);
1891 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) 1834 start_preview(dev, fh);
1892 return -EINVAL; 1835 spin_unlock_irqrestore(&dev->slock, flags);
1893 crop->c = dev->crop_current; 1836 } else
1894 return 0; 1837 set_tvnorm(dev, &tvnorms[i]);
1895 }
1896 case VIDIOC_S_CROP:
1897 {
1898 struct v4l2_crop *crop = arg;
1899 struct v4l2_rect *b = &dev->crop_bounds;
1900 1838
1901 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && 1839 saa7134_tvaudio_do_scan(dev);
1902 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) 1840 mutex_unlock(&dev->lock);
1903 return -EINVAL; 1841 return 0;
1904 if (crop->c.height < 0) 1842}
1905 return -EINVAL;
1906 if (crop->c.width < 0)
1907 return -EINVAL;
1908 1843
1909 if (res_locked(fh->dev,RESOURCE_OVERLAY)) 1844static int saa7134_cropcap(struct file *file, void *priv,
1910 return -EBUSY; 1845 struct v4l2_cropcap *cap)
1911 if (res_locked(fh->dev,RESOURCE_VIDEO)) 1846{
1912 return -EBUSY; 1847 struct saa7134_fh *fh = priv;
1848 struct saa7134_dev *dev = fh->dev;
1913 1849
1914 if (crop->c.top < b->top) 1850 if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1915 crop->c.top = b->top; 1851 cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1916 if (crop->c.top > b->top + b->height) 1852 return -EINVAL;
1917 crop->c.top = b->top + b->height; 1853 cap->bounds = dev->crop_bounds;
1918 if (crop->c.height > b->top - crop->c.top + b->height) 1854 cap->defrect = dev->crop_defrect;
1919 crop->c.height = b->top - crop->c.top + b->height; 1855 cap->pixelaspect.numerator = 1;
1920 1856 cap->pixelaspect.denominator = 1;
1921 if (crop->c.left < b->left) 1857 if (dev->tvnorm->id & V4L2_STD_525_60) {
1922 crop->c.left = b->left; 1858 cap->pixelaspect.numerator = 11;
1923 if (crop->c.left > b->left + b->width) 1859 cap->pixelaspect.denominator = 10;
1924 crop->c.left = b->left + b->width; 1860 }
1925 if (crop->c.width > b->left - crop->c.left + b->width) 1861 if (dev->tvnorm->id & V4L2_STD_625_50) {
1926 crop->c.width = b->left - crop->c.left + b->width; 1862 cap->pixelaspect.numerator = 54;
1927 1863 cap->pixelaspect.denominator = 59;
1928 dev->crop_current = crop->c;
1929 return 0;
1930 } 1864 }
1865 return 0;
1866}
1931 1867
1932 /* --- tuner ioctls ------------------------------------------ */ 1868static int saa7134_g_crop(struct file *file, void *f, struct v4l2_crop *crop)
1933 case VIDIOC_G_TUNER: 1869{
1934 { 1870 struct saa7134_fh *fh = f;
1935 struct v4l2_tuner *t = arg; 1871 struct saa7134_dev *dev = fh->dev;
1936 int n;
1937 1872
1938 if (0 != t->index) 1873 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1939 return -EINVAL; 1874 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1940 memset(t,0,sizeof(*t)); 1875 return -EINVAL;
1941 for (n = 0; n < SAA7134_INPUT_MAX; n++) 1876 crop->c = dev->crop_current;
1942 if (card_in(dev,n).tv) 1877 return 0;
1943 break; 1878}
1944 if (NULL != card_in(dev,n).name) {
1945 strcpy(t->name, "Television");
1946 t->type = V4L2_TUNER_ANALOG_TV;
1947 t->capability = V4L2_TUNER_CAP_NORM |
1948 V4L2_TUNER_CAP_STEREO |
1949 V4L2_TUNER_CAP_LANG1 |
1950 V4L2_TUNER_CAP_LANG2;
1951 t->rangehigh = 0xffffffffUL;
1952 t->rxsubchans = saa7134_tvaudio_getstereo(dev);
1953 t->audmode = saa7134_tvaudio_rx2mode(t->rxsubchans);
1954 }
1955 if (0 != (saa_readb(SAA7134_STATUS_VIDEO1) & 0x03))
1956 t->signal = 0xffff;
1957 return 0;
1958 }
1959 case VIDIOC_S_TUNER:
1960 {
1961 struct v4l2_tuner *t = arg;
1962 int rx,mode;
1963 1879
1964 mode = dev->thread.mode; 1880static int saa7134_s_crop(struct file *file, void *f, struct v4l2_crop *crop)
1965 if (UNSET == mode) { 1881{
1966 rx = saa7134_tvaudio_getstereo(dev); 1882 struct saa7134_fh *fh = f;
1967 mode = saa7134_tvaudio_rx2mode(t->rxsubchans); 1883 struct saa7134_dev *dev = fh->dev;
1968 } 1884 struct v4l2_rect *b = &dev->crop_bounds;
1969 if (mode != t->audmode) {
1970 dev->thread.mode = t->audmode;
1971 }
1972 return 0;
1973 }
1974 case VIDIOC_G_FREQUENCY:
1975 {
1976 struct v4l2_frequency *f = arg;
1977 1885
1978 memset(f,0,sizeof(*f)); 1886 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1979 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1887 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1980 f->frequency = dev->ctl_freq; 1888 return -EINVAL;
1981 return 0; 1889 if (crop->c.height < 0)
1982 } 1890 return -EINVAL;
1983 case VIDIOC_S_FREQUENCY: 1891 if (crop->c.width < 0)
1984 { 1892 return -EINVAL;
1985 struct v4l2_frequency *f = arg;
1986 1893
1987 if (0 != f->tuner) 1894 if (res_locked(fh->dev, RESOURCE_OVERLAY))
1988 return -EINVAL; 1895 return -EBUSY;
1989 if (0 == fh->radio && V4L2_TUNER_ANALOG_TV != f->type) 1896 if (res_locked(fh->dev, RESOURCE_VIDEO))
1990 return -EINVAL; 1897 return -EBUSY;
1991 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type) 1898
1992 return -EINVAL; 1899 if (crop->c.top < b->top)
1993 mutex_lock(&dev->lock); 1900 crop->c.top = b->top;
1994 dev->ctl_freq = f->frequency; 1901 if (crop->c.top > b->top + b->height)
1902 crop->c.top = b->top + b->height;
1903 if (crop->c.height > b->top - crop->c.top + b->height)
1904 crop->c.height = b->top - crop->c.top + b->height;
1905
1906 if (crop->c.left < b->left)
1907 crop->c.left = b->left;
1908 if (crop->c.left > b->left + b->width)
1909 crop->c.left = b->left + b->width;
1910 if (crop->c.width > b->left - crop->c.left + b->width)
1911 crop->c.width = b->left - crop->c.left + b->width;
1912
1913 dev->crop_current = crop->c;
1914 return 0;
1915}
1995 1916
1996 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,f); 1917static int saa7134_g_tuner(struct file *file, void *priv,
1918 struct v4l2_tuner *t)
1919{
1920 struct saa7134_fh *fh = priv;
1921 struct saa7134_dev *dev = fh->dev;
1922 int n;
1997 1923
1998 saa7134_tvaudio_do_scan(dev); 1924 if (0 != t->index)
1999 mutex_unlock(&dev->lock); 1925 return -EINVAL;
2000 return 0; 1926 memset(t, 0, sizeof(*t));
2001 } 1927 for (n = 0; n < SAA7134_INPUT_MAX; n++)
1928 if (card_in(dev, n).tv)
1929 break;
1930 if (NULL != card_in(dev, n).name) {
1931 strcpy(t->name, "Television");
1932 t->type = V4L2_TUNER_ANALOG_TV;
1933 t->capability = V4L2_TUNER_CAP_NORM |
1934 V4L2_TUNER_CAP_STEREO |
1935 V4L2_TUNER_CAP_LANG1 |
1936 V4L2_TUNER_CAP_LANG2;
1937 t->rangehigh = 0xffffffffUL;
1938 t->rxsubchans = saa7134_tvaudio_getstereo(dev);
1939 t->audmode = saa7134_tvaudio_rx2mode(t->rxsubchans);
1940 }
1941 if (0 != (saa_readb(SAA7134_STATUS_VIDEO1) & 0x03))
1942 t->signal = 0xffff;
1943 return 0;
1944}
2002 1945
2003 /* --- control ioctls ---------------------------------------- */ 1946static int saa7134_s_tuner(struct file *file, void *priv,
2004 case VIDIOC_ENUMINPUT: 1947 struct v4l2_tuner *t)
2005 case VIDIOC_G_INPUT: 1948{
2006 case VIDIOC_S_INPUT: 1949 struct saa7134_fh *fh = priv;
2007 case VIDIOC_QUERYCTRL: 1950 struct saa7134_dev *dev = fh->dev;
2008 case VIDIOC_G_CTRL: 1951 int rx, mode, err;
2009 case VIDIOC_S_CTRL:
2010 return saa7134_common_ioctl(dev, cmd, arg);
2011 1952
2012 case VIDIOC_G_AUDIO: 1953 err = v4l2_prio_check(&dev->prio, &fh->prio);
2013 { 1954 if (0 != err)
2014 struct v4l2_audio *a = arg; 1955 return err;
2015 1956
2016 memset(a,0,sizeof(*a)); 1957 mode = dev->thread.mode;
2017 strcpy(a->name,"audio"); 1958 if (UNSET == mode) {
2018 return 0; 1959 rx = saa7134_tvaudio_getstereo(dev);
2019 } 1960 mode = saa7134_tvaudio_rx2mode(t->rxsubchans);
2020 case VIDIOC_S_AUDIO:
2021 return 0;
2022 case VIDIOC_G_PARM:
2023 {
2024 struct v4l2_captureparm *parm = arg;
2025 memset(parm,0,sizeof(*parm));
2026 return 0;
2027 } 1961 }
1962 if (mode != t->audmode)
1963 dev->thread.mode = t->audmode;
2028 1964
2029 case VIDIOC_G_PRIORITY: 1965 return 0;
2030 { 1966}
2031 enum v4l2_priority *p = arg;
2032 1967
2033 *p = v4l2_prio_max(&dev->prio); 1968static int saa7134_g_frequency(struct file *file, void *priv,
2034 return 0; 1969 struct v4l2_frequency *f)
2035 } 1970{
2036 case VIDIOC_S_PRIORITY: 1971 struct saa7134_fh *fh = priv;
2037 { 1972 struct saa7134_dev *dev = fh->dev;
2038 enum v4l2_priority *prio = arg;
2039 1973
2040 return v4l2_prio_change(&dev->prio, &fh->prio, *prio); 1974 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
2041 } 1975 f->frequency = dev->ctl_freq;
2042 1976
2043 /* --- preview ioctls ---------------------------------------- */ 1977 return 0;
2044 case VIDIOC_ENUM_FMT: 1978}
2045 {
2046 struct v4l2_fmtdesc *f = arg;
2047 enum v4l2_buf_type type;
2048 unsigned int index;
2049
2050 index = f->index;
2051 type = f->type;
2052 switch (type) {
2053 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2054 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2055 if (saa7134_no_overlay > 0) {
2056 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
2057 return -EINVAL;
2058 }
2059 if (index >= FORMATS)
2060 return -EINVAL;
2061 if (f->type == V4L2_BUF_TYPE_VIDEO_OVERLAY &&
2062 formats[index].planar)
2063 return -EINVAL;
2064 memset(f,0,sizeof(*f));
2065 f->index = index;
2066 f->type = type;
2067 strlcpy(f->description,formats[index].name,sizeof(f->description));
2068 f->pixelformat = formats[index].fourcc;
2069 break;
2070 case V4L2_BUF_TYPE_VBI_CAPTURE:
2071 if (0 != index)
2072 return -EINVAL;
2073 memset(f,0,sizeof(*f));
2074 f->index = index;
2075 f->type = type;
2076 f->pixelformat = V4L2_PIX_FMT_GREY;
2077 strcpy(f->description,"vbi data");
2078 break;
2079 default:
2080 return -EINVAL;
2081 }
2082 return 0;
2083 }
2084 case VIDIOC_G_FBUF:
2085 {
2086 struct v4l2_framebuffer *fb = arg;
2087 1979
2088 *fb = dev->ovbuf; 1980static int saa7134_s_frequency(struct file *file, void *priv,
2089 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; 1981 struct v4l2_frequency *f)
2090 return 0; 1982{
2091 } 1983 struct saa7134_fh *fh = priv;
2092 case VIDIOC_S_FBUF: 1984 struct saa7134_dev *dev = fh->dev;
2093 { 1985 int err;
2094 struct v4l2_framebuffer *fb = arg;
2095 struct saa7134_format *fmt;
2096 1986
2097 if(!capable(CAP_SYS_ADMIN) && 1987 err = v4l2_prio_check(&dev->prio, &fh->prio);
2098 !capable(CAP_SYS_RAWIO)) 1988 if (0 != err)
2099 return -EPERM; 1989 return err;
2100 1990
2101 /* check args */ 1991 if (0 != f->tuner)
2102 fmt = format_by_fourcc(fb->fmt.pixelformat); 1992 return -EINVAL;
2103 if (NULL == fmt) 1993 if (0 == fh->radio && V4L2_TUNER_ANALOG_TV != f->type)
2104 return -EINVAL; 1994 return -EINVAL;
1995 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type)
1996 return -EINVAL;
1997 mutex_lock(&dev->lock);
1998 dev->ctl_freq = f->frequency;
2105 1999
2106 /* ok, accept it */ 2000 saa7134_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
2107 dev->ovbuf = *fb; 2001
2108 dev->ovfmt = fmt; 2002 saa7134_tvaudio_do_scan(dev);
2109 if (0 == dev->ovbuf.fmt.bytesperline) 2003 mutex_unlock(&dev->lock);
2110 dev->ovbuf.fmt.bytesperline = 2004 return 0;
2111 dev->ovbuf.fmt.width*fmt->depth/8; 2005}
2112 return 0; 2006
2007static int saa7134_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
2008{
2009 strcpy(a->name, "audio");
2010 return 0;
2011}
2012
2013static int saa7134_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
2014{
2015 return 0;
2016}
2017
2018static int saa7134_g_priority(struct file *file, void *f, enum v4l2_priority *p)
2019{
2020 struct saa7134_fh *fh = f;
2021 struct saa7134_dev *dev = fh->dev;
2022
2023 *p = v4l2_prio_max(&dev->prio);
2024 return 0;
2025}
2026
2027static int saa7134_s_priority(struct file *file, void *f,
2028 enum v4l2_priority prio)
2029{
2030 struct saa7134_fh *fh = f;
2031 struct saa7134_dev *dev = fh->dev;
2032
2033 return v4l2_prio_change(&dev->prio, &fh->prio, prio);
2034}
2035
2036static int saa7134_enum_fmt_cap(struct file *file, void *priv,
2037 struct v4l2_fmtdesc *f)
2038{
2039 if (f->index >= FORMATS)
2040 return -EINVAL;
2041
2042 strlcpy(f->description, formats[f->index].name,
2043 sizeof(f->description));
2044
2045 f->pixelformat = formats[f->index].fourcc;
2046
2047 return 0;
2048}
2049
2050static int saa7134_enum_fmt_overlay(struct file *file, void *priv,
2051 struct v4l2_fmtdesc *f)
2052{
2053 if (saa7134_no_overlay > 0) {
2054 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
2055 return -EINVAL;
2113 } 2056 }
2114 case VIDIOC_OVERLAY:
2115 {
2116 int *on = arg;
2117 2057
2118 if (*on) { 2058 if ((f->index >= FORMATS) || formats[f->index].planar)
2119 if (saa7134_no_overlay > 0) { 2059 return -EINVAL;
2120 printk ("no_overlay\n");
2121 return -EINVAL;
2122 }
2123 2060
2124 if (!res_get(dev,fh,RESOURCE_OVERLAY)) 2061 strlcpy(f->description, formats[f->index].name,
2125 return -EBUSY; 2062 sizeof(f->description));
2126 spin_lock_irqsave(&dev->slock,flags); 2063
2127 start_preview(dev,fh); 2064 f->pixelformat = formats[f->index].fourcc;
2128 spin_unlock_irqrestore(&dev->slock,flags); 2065
2129 } 2066 return 0;
2130 if (!*on) { 2067}
2131 if (!res_check(fh, RESOURCE_OVERLAY)) 2068
2132 return -EINVAL; 2069static int saa7134_enum_fmt_vbi(struct file *file, void *priv,
2133 spin_lock_irqsave(&dev->slock,flags); 2070 struct v4l2_fmtdesc *f)
2134 stop_preview(dev,fh); 2071{
2135 spin_unlock_irqrestore(&dev->slock,flags); 2072 if (0 != f->index)
2136 res_free(dev,fh,RESOURCE_OVERLAY); 2073 return -EINVAL;
2074
2075 f->pixelformat = V4L2_PIX_FMT_GREY;
2076 strcpy(f->description, "vbi data");
2077
2078 return 0;
2079}
2080
2081static int saa7134_g_fbuf(struct file *file, void *f,
2082 struct v4l2_framebuffer *fb)
2083{
2084 struct saa7134_fh *fh = f;
2085 struct saa7134_dev *dev = fh->dev;
2086
2087 *fb = dev->ovbuf;
2088 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
2089
2090 return 0;
2091}
2092
2093static int saa7134_s_fbuf(struct file *file, void *f,
2094 struct v4l2_framebuffer *fb)
2095{
2096 struct saa7134_fh *fh = f;
2097 struct saa7134_dev *dev = fh->dev;
2098 struct saa7134_format *fmt;
2099
2100 if (!capable(CAP_SYS_ADMIN) &&
2101 !capable(CAP_SYS_RAWIO))
2102 return -EPERM;
2103
2104 /* check args */
2105 fmt = format_by_fourcc(fb->fmt.pixelformat);
2106 if (NULL == fmt)
2107 return -EINVAL;
2108
2109 /* ok, accept it */
2110 dev->ovbuf = *fb;
2111 dev->ovfmt = fmt;
2112 if (0 == dev->ovbuf.fmt.bytesperline)
2113 dev->ovbuf.fmt.bytesperline =
2114 dev->ovbuf.fmt.width*fmt->depth/8;
2115 return 0;
2116}
2117
2118static int saa7134_overlay(struct file *file, void *f, unsigned int on)
2119{
2120 struct saa7134_fh *fh = f;
2121 struct saa7134_dev *dev = fh->dev;
2122 unsigned long flags;
2123
2124 if (on) {
2125 if (saa7134_no_overlay > 0) {
2126 dprintk("no_overlay\n");
2127 return -EINVAL;
2137 } 2128 }
2138 return 0;
2139 }
2140 2129
2141 /* --- capture ioctls ---------------------------------------- */ 2130 if (!res_get(dev, fh, RESOURCE_OVERLAY))
2142 case VIDIOC_G_FMT: 2131 return -EBUSY;
2143 { 2132 spin_lock_irqsave(&dev->slock, flags);
2144 struct v4l2_format *f = arg; 2133 start_preview(dev, fh);
2145 return saa7134_g_fmt(dev,fh,f); 2134 spin_unlock_irqrestore(&dev->slock, flags);
2146 }
2147 case VIDIOC_S_FMT:
2148 {
2149 struct v4l2_format *f = arg;
2150 return saa7134_s_fmt(dev,fh,f);
2151 } 2135 }
2152 case VIDIOC_TRY_FMT: 2136 if (!on) {
2153 { 2137 if (!res_check(fh, RESOURCE_OVERLAY))
2154 struct v4l2_format *f = arg; 2138 return -EINVAL;
2155 return saa7134_try_fmt(dev,fh,f); 2139 spin_lock_irqsave(&dev->slock, flags);
2140 stop_preview(dev, fh);
2141 spin_unlock_irqrestore(&dev->slock, flags);
2142 res_free(dev, fh, RESOURCE_OVERLAY);
2156 } 2143 }
2144 return 0;
2145}
2146
2157#ifdef CONFIG_VIDEO_V4L1_COMPAT 2147#ifdef CONFIG_VIDEO_V4L1_COMPAT
2158 case VIDIOCGMBUF: 2148static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
2159 return videobuf_cgmbuf(saa7134_queue(fh), arg, gbuffers); 2149{
2150 struct saa7134_fh *fh = file->private_data;
2151 return videobuf_cgmbuf(saa7134_queue(fh), mbuf, 8);
2152}
2160#endif 2153#endif
2161 case VIDIOC_REQBUFS:
2162 return videobuf_reqbufs(saa7134_queue(fh),arg);
2163 2154
2164 case VIDIOC_QUERYBUF: 2155static int saa7134_reqbufs(struct file *file, void *priv,
2165 return videobuf_querybuf(saa7134_queue(fh),arg); 2156 struct v4l2_requestbuffers *p)
2157{
2158 struct saa7134_fh *fh = priv;
2159 return videobuf_reqbufs(saa7134_queue(fh), p);
2160}
2166 2161
2167 case VIDIOC_QBUF: 2162static int saa7134_querybuf(struct file *file, void *priv,
2168 return videobuf_qbuf(saa7134_queue(fh),arg); 2163 struct v4l2_buffer *b)
2164{
2165 struct saa7134_fh *fh = priv;
2166 return videobuf_querybuf(saa7134_queue(fh), b);
2167}
2169 2168
2170 case VIDIOC_DQBUF: 2169static int saa7134_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2171 return videobuf_dqbuf(saa7134_queue(fh),arg, 2170{
2172 file->f_flags & O_NONBLOCK); 2171 struct saa7134_fh *fh = priv;
2172 return videobuf_qbuf(saa7134_queue(fh), b);
2173}
2173 2174
2174 case VIDIOC_STREAMON: 2175static int saa7134_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2175 { 2176{
2176 int res = saa7134_resource(fh); 2177 struct saa7134_fh *fh = priv;
2178 return videobuf_dqbuf(saa7134_queue(fh), b,
2179 file->f_flags & O_NONBLOCK);
2180}
2177 2181
2178 if (!res_get(dev,fh,res)) 2182static int saa7134_streamon(struct file *file, void *priv,
2179 return -EBUSY; 2183 enum v4l2_buf_type type)
2180 return videobuf_streamon(saa7134_queue(fh)); 2184{
2181 } 2185 struct saa7134_fh *fh = priv;
2182 case VIDIOC_STREAMOFF: 2186 struct saa7134_dev *dev = fh->dev;
2183 { 2187 int res = saa7134_resource(fh);
2184 int res = saa7134_resource(fh);
2185 2188
2186 err = videobuf_streamoff(saa7134_queue(fh)); 2189 if (!res_get(dev, fh, res))
2187 if (err < 0) 2190 return -EBUSY;
2188 return err;
2189 res_free(dev,fh,res);
2190 return 0;
2191 }
2192 2191
2193 default: 2192 return videobuf_streamon(saa7134_queue(fh));
2194 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 2193}
2195 video_do_ioctl); 2194
2196 } 2195static int saa7134_streamoff(struct file *file, void *priv,
2196 enum v4l2_buf_type type)
2197{
2198 int err;
2199 struct saa7134_fh *fh = priv;
2200 struct saa7134_dev *dev = fh->dev;
2201 int res = saa7134_resource(fh);
2202
2203 err = videobuf_streamoff(saa7134_queue(fh));
2204 if (err < 0)
2205 return err;
2206 res_free(dev, fh, res);
2197 return 0; 2207 return 0;
2198} 2208}
2199 2209
2200static int video_ioctl(struct inode *inode, struct file *file, 2210static int saa7134_g_parm(struct file *file, void *fh,
2201 unsigned int cmd, unsigned long arg) 2211 struct v4l2_streamparm *parm)
2202{ 2212{
2203 return video_usercopy(inode, file, cmd, arg, video_do_ioctl); 2213 return 0;
2204} 2214}
2205 2215
2206static int radio_do_ioctl(struct inode *inode, struct file *file, 2216static int radio_querycap(struct file *file, void *priv,
2207 unsigned int cmd, void *arg) 2217 struct v4l2_capability *cap)
2208{ 2218{
2209 struct saa7134_fh *fh = file->private_data; 2219 struct saa7134_fh *fh = file->private_data;
2210 struct saa7134_dev *dev = fh->dev; 2220 struct saa7134_dev *dev = fh->dev;
2211 2221
2212 if (video_debug > 1) 2222 strcpy(cap->driver, "saa7134");
2213 v4l_print_ioctl(dev->name,cmd); 2223 strlcpy(cap->card, saa7134_boards[dev->board].name, sizeof(cap->card));
2214 switch (cmd) { 2224 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
2215 case VIDIOC_QUERYCAP: 2225 cap->version = SAA7134_VERSION_CODE;
2216 { 2226 cap->capabilities = V4L2_CAP_TUNER;
2217 struct v4l2_capability *cap = arg; 2227 return 0;
2218 2228}
2219 memset(cap,0,sizeof(*cap));
2220 strcpy(cap->driver, "saa7134");
2221 strlcpy(cap->card, saa7134_boards[dev->board].name,
2222 sizeof(cap->card));
2223 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
2224 cap->version = SAA7134_VERSION_CODE;
2225 cap->capabilities = V4L2_CAP_TUNER;
2226 return 0;
2227 }
2228 case VIDIOC_G_TUNER:
2229 {
2230 struct v4l2_tuner *t = arg;
2231 2229
2232 if (0 != t->index) 2230static int radio_g_tuner(struct file *file, void *priv,
2233 return -EINVAL; 2231 struct v4l2_tuner *t)
2232{
2233 struct saa7134_fh *fh = file->private_data;
2234 struct saa7134_dev *dev = fh->dev;
2234 2235
2235 memset(t,0,sizeof(*t)); 2236 if (0 != t->index)
2236 strcpy(t->name, "Radio"); 2237 return -EINVAL;
2237 t->type = V4L2_TUNER_RADIO;
2238 2238
2239 saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t); 2239 memset(t, 0, sizeof(*t));
2240 if (dev->input->amux == TV) { 2240 strcpy(t->name, "Radio");
2241 t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11); 2241 t->type = V4L2_TUNER_RADIO;
2242 t->rxsubchans = (saa_readb(0x529) & 0x08) ? 2242
2243 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO; 2243 saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
2244 } 2244 if (dev->input->amux == TV) {
2245 return 0; 2245 t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11);
2246 t->rxsubchans = (saa_readb(0x529) & 0x08) ?
2247 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
2246 } 2248 }
2247 case VIDIOC_S_TUNER: 2249 return 0;
2248 { 2250}
2249 struct v4l2_tuner *t = arg; 2251static int radio_s_tuner(struct file *file, void *priv,
2252 struct v4l2_tuner *t)
2253{
2254 struct saa7134_fh *fh = file->private_data;
2255 struct saa7134_dev *dev = fh->dev;
2250 2256
2251 if (0 != t->index) 2257 if (0 != t->index)
2252 return -EINVAL; 2258 return -EINVAL;
2253 2259
2254 saa7134_i2c_call_clients(dev,VIDIOC_S_TUNER,t); 2260 saa7134_i2c_call_clients(dev, VIDIOC_S_TUNER, t);
2261 return 0;
2262}
2255 2263
2256 return 0; 2264static int radio_enum_input(struct file *file, void *priv,
2257 } 2265 struct v4l2_input *i)
2258 case VIDIOC_ENUMINPUT: 2266{
2259 { 2267 if (i->index != 0)
2260 struct v4l2_input *i = arg; 2268 return -EINVAL;
2261 2269
2262 if (i->index != 0) 2270 strcpy(i->name, "Radio");
2263 return -EINVAL; 2271 i->type = V4L2_INPUT_TYPE_TUNER;
2264 strcpy(i->name,"Radio");
2265 i->type = V4L2_INPUT_TYPE_TUNER;
2266 return 0;
2267 }
2268 case VIDIOC_G_INPUT:
2269 {
2270 int *i = arg;
2271 *i = 0;
2272 return 0;
2273 }
2274 case VIDIOC_G_AUDIO:
2275 {
2276 struct v4l2_audio *a = arg;
2277 2272
2278 memset(a,0,sizeof(*a)); 2273 return 0;
2279 strcpy(a->name,"Radio"); 2274}
2280 return 0;
2281 }
2282 case VIDIOC_G_STD:
2283 {
2284 v4l2_std_id *id = arg;
2285 *id = 0;
2286 return 0;
2287 }
2288 case VIDIOC_S_AUDIO:
2289 case VIDIOC_S_INPUT:
2290 case VIDIOC_S_STD:
2291 return 0;
2292 2275
2293 case VIDIOC_QUERYCTRL: 2276static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
2294 { 2277{
2295 const struct v4l2_queryctrl *ctrl; 2278 *i = 0;
2296 struct v4l2_queryctrl *c = arg; 2279 return 0;
2280}
2297 2281
2298 if (c->id < V4L2_CID_BASE || 2282static int radio_g_audio(struct file *file, void *priv,
2299 c->id >= V4L2_CID_LASTP1) 2283 struct v4l2_audio *a)
2300 return -EINVAL; 2284{
2301 if (c->id == V4L2_CID_AUDIO_MUTE) { 2285 memset(a, 0, sizeof(*a));
2302 ctrl = ctrl_by_id(c->id); 2286 strcpy(a->name, "Radio");
2303 *c = *ctrl; 2287 return 0;
2304 } else 2288}
2305 *c = no_ctrl;
2306 return 0;
2307 }
2308 2289
2309 case VIDIOC_G_CTRL: 2290static int radio_s_audio(struct file *file, void *priv,
2310 case VIDIOC_S_CTRL: 2291 struct v4l2_audio *a)
2311 case VIDIOC_G_FREQUENCY: 2292{
2312 case VIDIOC_S_FREQUENCY: 2293 return 0;
2313 return video_do_ioctl(inode,file,cmd,arg); 2294}
2314 2295
2315 default: 2296static int radio_s_input(struct file *filp, void *priv, unsigned int i)
2316 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 2297{
2317 radio_do_ioctl);
2318 }
2319 return 0; 2298 return 0;
2320} 2299}
2321 2300
2322static int radio_ioctl(struct inode *inode, struct file *file, 2301static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm)
2323 unsigned int cmd, unsigned long arg)
2324{ 2302{
2325 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl); 2303 return 0;
2304}
2305
2306static int radio_queryctrl(struct file *file, void *priv,
2307 struct v4l2_queryctrl *c)
2308{
2309 const struct v4l2_queryctrl *ctrl;
2310
2311 if (c->id < V4L2_CID_BASE ||
2312 c->id >= V4L2_CID_LASTP1)
2313 return -EINVAL;
2314 if (c->id == V4L2_CID_AUDIO_MUTE) {
2315 ctrl = ctrl_by_id(c->id);
2316 *c = *ctrl;
2317 } else
2318 *c = no_ctrl;
2319 return 0;
2326} 2320}
2327 2321
2328static const struct file_operations video_fops = 2322static const struct file_operations video_fops =
@@ -2333,7 +2327,7 @@ static const struct file_operations video_fops =
2333 .read = video_read, 2327 .read = video_read,
2334 .poll = video_poll, 2328 .poll = video_poll,
2335 .mmap = video_mmap, 2329 .mmap = video_mmap,
2336 .ioctl = video_ioctl, 2330 .ioctl = video_ioctl2,
2337 .compat_ioctl = v4l_compat_ioctl32, 2331 .compat_ioctl = v4l_compat_ioctl32,
2338 .llseek = no_llseek, 2332 .llseek = no_llseek,
2339}; 2333};
@@ -2343,7 +2337,7 @@ static const struct file_operations radio_fops =
2343 .owner = THIS_MODULE, 2337 .owner = THIS_MODULE,
2344 .open = video_open, 2338 .open = video_open,
2345 .release = video_release, 2339 .release = video_release,
2346 .ioctl = radio_ioctl, 2340 .ioctl = video_ioctl2,
2347 .compat_ioctl = v4l_compat_ioctl32, 2341 .compat_ioctl = v4l_compat_ioctl32,
2348 .llseek = no_llseek, 2342 .llseek = no_llseek,
2349}; 2343};
@@ -2353,27 +2347,79 @@ static const struct file_operations radio_fops =
2353 2347
2354struct video_device saa7134_video_template = 2348struct video_device saa7134_video_template =
2355{ 2349{
2356 .name = "saa7134-video", 2350 .name = "saa7134-video",
2357 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER| 2351 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER |
2358 VID_TYPE_CLIPPING|VID_TYPE_SCALES, 2352 VID_TYPE_CLIPPING|VID_TYPE_SCALES,
2359 .fops = &video_fops, 2353 .fops = &video_fops,
2360 .minor = -1, 2354 .minor = -1,
2361}; 2355 .vidioc_querycap = saa7134_querycap,
2362 2356 .vidioc_enum_fmt_cap = saa7134_enum_fmt_cap,
2363struct video_device saa7134_vbi_template = 2357 .vidioc_g_fmt_cap = saa7134_g_fmt_cap,
2364{ 2358 .vidioc_try_fmt_cap = saa7134_try_fmt_cap,
2365 .name = "saa7134-vbi", 2359 .vidioc_s_fmt_cap = saa7134_s_fmt_cap,
2366 .type = VID_TYPE_TUNER|VID_TYPE_TELETEXT, 2360 .vidioc_enum_fmt_overlay = saa7134_enum_fmt_overlay,
2367 .fops = &video_fops, 2361 .vidioc_g_fmt_overlay = saa7134_g_fmt_overlay,
2368 .minor = -1, 2362 .vidioc_try_fmt_overlay = saa7134_try_fmt_overlay,
2363 .vidioc_s_fmt_overlay = saa7134_s_fmt_overlay,
2364 .vidioc_enum_fmt_vbi = saa7134_enum_fmt_vbi,
2365 .vidioc_g_fmt_vbi = saa7134_try_get_set_fmt_vbi,
2366 .vidioc_try_fmt_vbi = saa7134_try_get_set_fmt_vbi,
2367 .vidioc_s_fmt_vbi = saa7134_try_get_set_fmt_vbi,
2368 .vidioc_g_audio = saa7134_g_audio,
2369 .vidioc_s_audio = saa7134_s_audio,
2370 .vidioc_cropcap = saa7134_cropcap,
2371 .vidioc_reqbufs = saa7134_reqbufs,
2372 .vidioc_querybuf = saa7134_querybuf,
2373 .vidioc_qbuf = saa7134_qbuf,
2374 .vidioc_dqbuf = saa7134_dqbuf,
2375 .vidioc_s_std = saa7134_s_std,
2376 .vidioc_enum_input = saa7134_enum_input,
2377 .vidioc_g_input = saa7134_g_input,
2378 .vidioc_s_input = saa7134_s_input,
2379 .vidioc_queryctrl = saa7134_queryctrl,
2380 .vidioc_g_ctrl = saa7134_g_ctrl,
2381 .vidioc_s_ctrl = saa7134_s_ctrl,
2382 .vidioc_streamon = saa7134_streamon,
2383 .vidioc_streamoff = saa7134_streamoff,
2384 .vidioc_g_tuner = saa7134_g_tuner,
2385 .vidioc_s_tuner = saa7134_s_tuner,
2386#ifdef CONFIG_VIDEO_V4L1_COMPAT
2387 .vidiocgmbuf = vidiocgmbuf,
2388#endif
2389 .vidioc_g_crop = saa7134_g_crop,
2390 .vidioc_s_crop = saa7134_s_crop,
2391 .vidioc_g_fbuf = saa7134_g_fbuf,
2392 .vidioc_s_fbuf = saa7134_s_fbuf,
2393 .vidioc_overlay = saa7134_overlay,
2394 .vidioc_g_priority = saa7134_g_priority,
2395 .vidioc_s_priority = saa7134_s_priority,
2396 .vidioc_g_parm = saa7134_g_parm,
2397 .vidioc_g_frequency = saa7134_g_frequency,
2398 .vidioc_s_frequency = saa7134_s_frequency,
2399 .tvnorms = SAA7134_NORMS,
2400 .current_norm = V4L2_STD_PAL,
2369}; 2401};
2370 2402
2371struct video_device saa7134_radio_template = 2403struct video_device saa7134_radio_template =
2372{ 2404{
2373 .name = "saa7134-radio", 2405 .name = "saa7134-radio",
2374 .type = VID_TYPE_TUNER, 2406 .type = VID_TYPE_TUNER,
2375 .fops = &radio_fops, 2407 .fops = &radio_fops,
2376 .minor = -1, 2408 .minor = -1,
2409 .vidioc_querycap = radio_querycap,
2410 .vidioc_g_tuner = radio_g_tuner,
2411 .vidioc_enum_input = radio_enum_input,
2412 .vidioc_g_audio = radio_g_audio,
2413 .vidioc_s_tuner = radio_s_tuner,
2414 .vidioc_s_audio = radio_s_audio,
2415 .vidioc_s_input = radio_s_input,
2416 .vidioc_s_std = radio_s_std,
2417 .vidioc_queryctrl = radio_queryctrl,
2418 .vidioc_g_input = radio_g_input,
2419 .vidioc_g_ctrl = saa7134_g_ctrl,
2420 .vidioc_s_ctrl = saa7134_s_ctrl,
2421 .vidioc_g_frequency = saa7134_g_frequency,
2422 .vidioc_s_frequency = saa7134_s_frequency,
2377}; 2423};
2378 2424
2379int saa7134_video_init1(struct saa7134_dev *dev) 2425int saa7134_video_init1(struct saa7134_dev *dev)
@@ -2511,7 +2557,7 @@ void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status)
2511 goto done; 2557 goto done;
2512 } 2558 }
2513 dev->video_q.curr->vb.field_count = dev->video_fieldcount; 2559 dev->video_q.curr->vb.field_count = dev->video_fieldcount;
2514 saa7134_buffer_finish(dev,&dev->video_q,STATE_DONE); 2560 saa7134_buffer_finish(dev,&dev->video_q,VIDEOBUF_DONE);
2515 } 2561 }
2516 saa7134_buffer_next(dev,&dev->video_q); 2562 saa7134_buffer_next(dev,&dev->video_q);
2517 2563
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 66a390c321a7..ce450304fb53 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -240,6 +240,19 @@ struct saa7134_format {
240#define SAA7134_BOARD_SABRENT_TV_PCB05 115 240#define SAA7134_BOARD_SABRENT_TV_PCB05 115
241#define SAA7134_BOARD_10MOONSTVMASTER3 116 241#define SAA7134_BOARD_10MOONSTVMASTER3 116
242#define SAA7134_BOARD_AVERMEDIA_SUPER_007 117 242#define SAA7134_BOARD_AVERMEDIA_SUPER_007 117
243#define SAA7134_BOARD_BEHOLD_401 118
244#define SAA7134_BOARD_BEHOLD_403 119
245#define SAA7134_BOARD_BEHOLD_403FM 120
246#define SAA7134_BOARD_BEHOLD_405 121
247#define SAA7134_BOARD_BEHOLD_405FM 122
248#define SAA7134_BOARD_BEHOLD_407 123
249#define SAA7134_BOARD_BEHOLD_407FM 124
250#define SAA7134_BOARD_BEHOLD_409 125
251#define SAA7134_BOARD_BEHOLD_505FM 126
252#define SAA7134_BOARD_BEHOLD_507_9FM 127
253#define SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM 128
254#define SAA7134_BOARD_BEHOLD_607_9FM 129
255#define SAA7134_BOARD_BEHOLD_M6 130
243 256
244#define SAA7134_MAXBOARDS 8 257#define SAA7134_MAXBOARDS 8
245#define SAA7134_INPUT_MAX 8 258#define SAA7134_INPUT_MAX 8
@@ -481,7 +494,7 @@ struct saa7134_dev {
481 /* i2c i/o */ 494 /* i2c i/o */
482 struct i2c_adapter i2c_adap; 495 struct i2c_adapter i2c_adap;
483 struct i2c_client i2c_client; 496 struct i2c_client i2c_client;
484 unsigned char eedata[128]; 497 unsigned char eedata[256];
485 498
486 /* video overlay */ 499 /* video overlay */
487 struct v4l2_framebuffer ovbuf; 500 struct v4l2_framebuffer ovbuf;
@@ -566,6 +579,12 @@ struct saa7134_dev {
566 579
567#define saa_wait(us) { udelay(us); } 580#define saa_wait(us) { udelay(us); }
568 581
582#define SAA7134_NORMS (\
583 V4L2_STD_PAL | V4L2_STD_PAL_N | \
584 V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
585 V4L2_STD_NTSC | V4L2_STD_PAL_M | \
586 V4L2_STD_PAL_60)
587
569/* ----------------------------------------------------------- */ 588/* ----------------------------------------------------------- */
570/* saa7134-core.c */ 589/* saa7134-core.c */
571 590
@@ -596,9 +615,6 @@ void saa7134_buffer_next(struct saa7134_dev *dev, struct saa7134_dmaqueue *q);
596void saa7134_buffer_timeout(unsigned long data); 615void saa7134_buffer_timeout(unsigned long data);
597void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf); 616void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf);
598 617
599int saa7134_buffer_requeue(struct saa7134_dev *dev,
600 struct saa7134_dmaqueue *q);
601
602int saa7134_set_dmabits(struct saa7134_dev *dev); 618int saa7134_set_dmabits(struct saa7134_dev *dev);
603 619
604extern int (*saa7134_dmasound_init)(struct saa7134_dev *dev); 620extern int (*saa7134_dmasound_init)(struct saa7134_dev *dev);
@@ -628,16 +644,17 @@ void saa7134_i2c_call_clients(struct saa7134_dev *dev,
628/* ----------------------------------------------------------- */ 644/* ----------------------------------------------------------- */
629/* saa7134-video.c */ 645/* saa7134-video.c */
630 646
647extern unsigned int video_debug;
631extern struct video_device saa7134_video_template; 648extern struct video_device saa7134_video_template;
632extern struct video_device saa7134_radio_template; 649extern struct video_device saa7134_radio_template;
633 650
634void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm); 651int saa7134_g_ctrl(struct file *file, void *priv, struct v4l2_control *c);
652int saa7134_s_ctrl(struct file *file, void *f, struct v4l2_control *c);
653int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c);
654
635int saa7134_videoport_init(struct saa7134_dev *dev); 655int saa7134_videoport_init(struct saa7134_dev *dev);
636void saa7134_set_tvnorm_hw(struct saa7134_dev *dev); 656void saa7134_set_tvnorm_hw(struct saa7134_dev *dev);
637 657
638int saa7134_common_ioctl(struct saa7134_dev *dev,
639 unsigned int cmd, void *arg);
640
641int saa7134_video_init1(struct saa7134_dev *dev); 658int saa7134_video_init1(struct saa7134_dev *dev);
642int saa7134_video_init2(struct saa7134_dev *dev); 659int saa7134_video_init2(struct saa7134_dev *dev);
643void saa7134_irq_video_signalchange(struct saa7134_dev *dev); 660void saa7134_irq_video_signalchange(struct saa7134_dev *dev);
@@ -682,6 +699,7 @@ void saa7134_tvaudio_setinput(struct saa7134_dev *dev,
682void saa7134_tvaudio_setvolume(struct saa7134_dev *dev, int level); 699void saa7134_tvaudio_setvolume(struct saa7134_dev *dev, int level);
683int saa7134_tvaudio_getstereo(struct saa7134_dev *dev); 700int saa7134_tvaudio_getstereo(struct saa7134_dev *dev);
684 701
702void saa7134_tvaudio_init(struct saa7134_dev *dev);
685int saa7134_tvaudio_init2(struct saa7134_dev *dev); 703int saa7134_tvaudio_init2(struct saa7134_dev *dev);
686int saa7134_tvaudio_fini(struct saa7134_dev *dev); 704int saa7134_tvaudio_fini(struct saa7134_dev *dev);
687int saa7134_tvaudio_do_scan(struct saa7134_dev *dev); 705int saa7134_tvaudio_do_scan(struct saa7134_dev *dev);
diff --git a/drivers/media/video/sn9c102/Makefile b/drivers/media/video/sn9c102/Makefile
index a56d16f69c71..7ecd5a90c7c9 100644
--- a/drivers/media/video/sn9c102/Makefile
+++ b/drivers/media/video/sn9c102/Makefile
@@ -3,6 +3,7 @@ sn9c102-objs := sn9c102_core.o \
3 sn9c102_hv7131r.o \ 3 sn9c102_hv7131r.o \
4 sn9c102_mi0343.o \ 4 sn9c102_mi0343.o \
5 sn9c102_mi0360.o \ 5 sn9c102_mi0360.o \
6 sn9c102_mt9v111.o \
6 sn9c102_ov7630.o \ 7 sn9c102_ov7630.o \
7 sn9c102_ov7660.o \ 8 sn9c102_ov7660.o \
8 sn9c102_pas106b.o \ 9 sn9c102_pas106b.o \
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 511847912c48..c40ba3adab21 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -47,7 +47,7 @@
47#define SN9C102_MODULE_AUTHOR "(C) 2004-2007 Luca Risolia" 47#define SN9C102_MODULE_AUTHOR "(C) 2004-2007 Luca Risolia"
48#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 48#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
49#define SN9C102_MODULE_LICENSE "GPL" 49#define SN9C102_MODULE_LICENSE "GPL"
50#define SN9C102_MODULE_VERSION "1:1.47" 50#define SN9C102_MODULE_VERSION "1:1.47pre49"
51#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 47) 51#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 47)
52 52
53/*****************************************************************************/ 53/*****************************************************************************/
@@ -3322,7 +3322,6 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3322 cam->v4ldev->fops = &sn9c102_fops; 3322 cam->v4ldev->fops = &sn9c102_fops;
3323 cam->v4ldev->minor = video_nr[dev_nr]; 3323 cam->v4ldev->minor = video_nr[dev_nr];
3324 cam->v4ldev->release = video_device_release; 3324 cam->v4ldev->release = video_device_release;
3325 video_set_drvdata(cam->v4ldev, cam);
3326 3325
3327 init_completion(&cam->probe); 3326 init_completion(&cam->probe);
3328 3327
@@ -3340,6 +3339,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3340 3339
3341 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor); 3340 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor);
3342 3341
3342 video_set_drvdata(cam->v4ldev, cam);
3343 cam->module_param.force_munmap = force_munmap[dev_nr]; 3343 cam->module_param.force_munmap = force_munmap[dev_nr];
3344 cam->module_param.frame_timeout = frame_timeout[dev_nr]; 3344 cam->module_param.frame_timeout = frame_timeout[dev_nr];
3345 3345
diff --git a/drivers/media/video/sn9c102/sn9c102_devtable.h b/drivers/media/video/sn9c102/sn9c102_devtable.h
index 916054faf9be..35223e0d7e49 100644
--- a/drivers/media/video/sn9c102/sn9c102_devtable.h
+++ b/drivers/media/video/sn9c102/sn9c102_devtable.h
@@ -126,6 +126,7 @@ extern int sn9c102_probe_hv7131d(struct sn9c102_device* cam);
126extern int sn9c102_probe_hv7131r(struct sn9c102_device* cam); 126extern int sn9c102_probe_hv7131r(struct sn9c102_device* cam);
127extern int sn9c102_probe_mi0343(struct sn9c102_device* cam); 127extern int sn9c102_probe_mi0343(struct sn9c102_device* cam);
128extern int sn9c102_probe_mi0360(struct sn9c102_device* cam); 128extern int sn9c102_probe_mi0360(struct sn9c102_device* cam);
129extern int sn9c102_probe_mt9v111(struct sn9c102_device *cam);
129extern int sn9c102_probe_ov7630(struct sn9c102_device* cam); 130extern int sn9c102_probe_ov7630(struct sn9c102_device* cam);
130extern int sn9c102_probe_ov7660(struct sn9c102_device* cam); 131extern int sn9c102_probe_ov7660(struct sn9c102_device* cam);
131extern int sn9c102_probe_pas106b(struct sn9c102_device* cam); 132extern int sn9c102_probe_pas106b(struct sn9c102_device* cam);
@@ -144,6 +145,7 @@ static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = {
144 &sn9c102_probe_hv7131r, /* strong detection based on SENSOR ids */ 145 &sn9c102_probe_hv7131r, /* strong detection based on SENSOR ids */
145 &sn9c102_probe_mi0343, /* strong detection based on SENSOR ids */ 146 &sn9c102_probe_mi0343, /* strong detection based on SENSOR ids */
146 &sn9c102_probe_mi0360, /* strong detection based on SENSOR ids */ 147 &sn9c102_probe_mi0360, /* strong detection based on SENSOR ids */
148 &sn9c102_probe_mt9v111, /* strong detection based on SENSOR ids */
147 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */ 149 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */
148 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */ 150 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */
149 &sn9c102_probe_ov7630, /* strong detection based on SENSOR ids */ 151 &sn9c102_probe_ov7630, /* strong detection based on SENSOR ids */
diff --git a/drivers/media/video/sn9c102/sn9c102_mt9v111.c b/drivers/media/video/sn9c102/sn9c102_mt9v111.c
new file mode 100644
index 000000000000..3b98ac3bbc38
--- /dev/null
+++ b/drivers/media/video/sn9c102/sn9c102_mt9v111.c
@@ -0,0 +1,259 @@
1/***************************************************************************
2 * Plug-in for MT9V111 image sensor connected to the SN9C1xx PC Camera *
3 * Controllers *
4 * *
5 * Copyright (C) 2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
21
22#include "sn9c102_sensor.h"
23
24
25static int mt9v111_init(struct sn9c102_device *cam)
26{
27 struct sn9c102_sensor *s = sn9c102_get_sensor(cam);
28 int err = 0;
29
30 err = sn9c102_write_const_regs(cam, {0x44, 0x01}, {0x40, 0x02},
31 {0x00, 0x03}, {0x1a, 0x04},
32 {0x1f, 0x05}, {0x20, 0x06},
33 {0x1f, 0x07}, {0x81, 0x08},
34 {0x5c, 0x09}, {0x00, 0x0a},
35 {0x00, 0x0b}, {0x00, 0x0c},
36 {0x00, 0x0d}, {0x00, 0x0e},
37 {0x00, 0x0f}, {0x03, 0x10},
38 {0x00, 0x11}, {0x00, 0x12},
39 {0x02, 0x13}, {0x14, 0x14},
40 {0x28, 0x15}, {0x1e, 0x16},
41 {0xe2, 0x17}, {0x06, 0x18},
42 {0x00, 0x19}, {0x00, 0x1a},
43 {0x00, 0x1b}, {0x08, 0x20},
44 {0x39, 0x21}, {0x51, 0x22},
45 {0x63, 0x23}, {0x73, 0x24},
46 {0x82, 0x25}, {0x8f, 0x26},
47 {0x9b, 0x27}, {0xa7, 0x28},
48 {0xb1, 0x29}, {0xbc, 0x2a},
49 {0xc6, 0x2b}, {0xcf, 0x2c},
50 {0xd8, 0x2d}, {0xe1, 0x2e},
51 {0xea, 0x2f}, {0xf2, 0x30},
52 {0x13, 0x84}, {0x00, 0x85},
53 {0x25, 0x86}, {0x00, 0x87},
54 {0x07, 0x88}, {0x00, 0x89},
55 {0xee, 0x8a}, {0x0f, 0x8b},
56 {0xe5, 0x8c}, {0x0f, 0x8d},
57 {0x2e, 0x8e}, {0x00, 0x8f},
58 {0x30, 0x90}, {0x00, 0x91},
59 {0xd4, 0x92}, {0x0f, 0x93},
60 {0xfc, 0x94}, {0x0f, 0x95},
61 {0x14, 0x96}, {0x00, 0x97},
62 {0x00, 0x98}, {0x60, 0x99},
63 {0x07, 0x9a}, {0x40, 0x9b},
64 {0x20, 0x9c}, {0x00, 0x9d},
65 {0x00, 0x9e}, {0x00, 0x9f},
66 {0x2d, 0xc0}, {0x2d, 0xc1},
67 {0x3a, 0xc2}, {0x05, 0xc3},
68 {0x04, 0xc4}, {0x3f, 0xc5},
69 {0x00, 0xc6}, {0x00, 0xc7},
70 {0x50, 0xc8}, {0x3c, 0xc9},
71 {0x28, 0xca}, {0xd8, 0xcb},
72 {0x14, 0xcc}, {0xec, 0xcd},
73 {0x32, 0xce}, {0xdd, 0xcf},
74 {0x2d, 0xd0}, {0xdd, 0xd1},
75 {0x6a, 0xd2}, {0x50, 0xd3},
76 {0x60, 0xd4}, {0x00, 0xd5},
77 {0x00, 0xd6});
78
79 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x01,
80 0x00, 0x01, 0, 0);
81 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x0d,
82 0x00, 0x01, 0, 0);
83 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x0d,
84 0x00, 0x00, 0, 0);
85 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x08,
86 0x04, 0x80, 0, 0);
87 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x01,
88 0x00, 0x04, 0, 0);
89 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x08,
90 0x00, 0x08, 0, 0);
91 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x02,
92 0x00, 0x16, 0, 0);
93 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x03,
94 0x01, 0xe7, 0, 0);
95 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x04,
96 0x02, 0x87, 0, 0);
97 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x06,
98 0x00, 0x40, 0, 0);
99 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x05,
100 0x00, 0x09, 0, 0);
101 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x07,
102 0x30, 0x02, 0, 0);
103 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x0c,
104 0x00, 0x00, 0, 0);
105 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x12,
106 0x00, 0xb0, 0, 0);
107 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x13,
108 0x00, 0x7c, 0, 0);
109 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x1e,
110 0x00, 0x00, 0, 0);
111 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x20,
112 0x00, 0x00, 0, 0);
113 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x20,
114 0x00, 0x00, 0, 0);
115 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x01,
116 0x00, 0x04, 0, 0);
117
118 return err;
119}
120
121static int mt9v111_get_ctrl(struct sn9c102_device *cam,
122 struct v4l2_control *ctrl)
123{
124 struct sn9c102_sensor *s = sn9c102_get_sensor(cam);
125 u8 data[2];
126 int err = 0;
127
128 switch (ctrl->id) {
129 case V4L2_CID_VFLIP:
130 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
131 data) < 0)
132 return -EIO;
133 ctrl->value = data[1] & 0x80 ? 1 : 0;
134 return 0;
135 default:
136 return -EINVAL;
137 }
138
139 return err ? -EIO : 0;
140}
141
142static int mt9v111_set_ctrl(struct sn9c102_device *cam,
143 const struct v4l2_control *ctrl)
144{
145 struct sn9c102_sensor *s = sn9c102_get_sensor(cam);
146 int err = 0;
147
148 switch (ctrl->id) {
149 case V4L2_CID_VFLIP:
150 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id,
151 0x20,
152 ctrl->value ? 0x80 : 0x00,
153 ctrl->value ? 0x80 : 0x00, 0,
154 0);
155 break;
156 default:
157 return -EINVAL;
158 }
159
160 return err ? -EIO : 0;
161}
162
163static int mt9v111_set_crop(struct sn9c102_device *cam,
164 const struct v4l2_rect *rect)
165{
166 struct sn9c102_sensor *s = sn9c102_get_sensor(cam);
167 int err = 0;
168 u8 v_start = (u8) (rect->top - s->cropcap.bounds.top) + 2;
169
170 err += sn9c102_write_reg(cam, v_start, 0x13);
171
172 return err;
173}
174
175static int mt9v111_set_pix_format(struct sn9c102_device *cam,
176 const struct v4l2_pix_format *pix)
177{
178 int err = 0;
179
180 if (pix->pixelformat == V4L2_PIX_FMT_SBGGR8) {
181 err += sn9c102_write_reg(cam, 0xb4, 0x17);
182 } else {
183 err += sn9c102_write_reg(cam, 0xe2, 0x17);
184 }
185
186 return err;
187}
188
189
190static const struct sn9c102_sensor mt9v111 = {
191 .name = "MT9V111",
192 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
193 .supported_bridge = BRIDGE_SN9C105 | BRIDGE_SN9C120,
194 .frequency = SN9C102_I2C_100KHZ,
195 .interface = SN9C102_I2C_2WIRES,
196 .i2c_slave_id = 0x5c,
197 .init = &mt9v111_init,
198 .qctrl = {
199 {
200 .id = V4L2_CID_VFLIP,
201 .type = V4L2_CTRL_TYPE_BOOLEAN,
202 .name = "vertical mirror",
203 .minimum = 0,
204 .maximum = 1,
205 .step = 1,
206 .default_value = 0,
207 .flags = 0,
208 },
209 },
210 .get_ctrl = &mt9v111_get_ctrl,
211 .set_ctrl = &mt9v111_set_ctrl,
212 .cropcap = {
213 .bounds = {
214 .left = 0,
215 .top = 0,
216 .width = 640,
217 .height = 480,
218 },
219 .defrect = {
220 .left = 0,
221 .top = 0,
222 .width = 640,
223 .height = 480,
224 },
225 },
226 .set_crop = &mt9v111_set_crop,
227 .pix_format = {
228 .width = 640,
229 .height = 480,
230 .pixelformat = V4L2_PIX_FMT_SBGGR8,
231 .priv = 8,
232 },
233 .set_pix_format = &mt9v111_set_pix_format
234};
235
236
237int sn9c102_probe_mt9v111(struct sn9c102_device *cam)
238{
239 u8 data[2];
240 int err = 0;
241
242 err += sn9c102_write_const_regs(cam, {0x01, 0xf1}, {0x00, 0xf1},
243 {0x29, 0x01}, {0x42, 0x17},
244 {0x62, 0x17}, {0x08, 0x01});
245 err += sn9c102_i2c_try_raw_write(cam, &mt9v111, 4,
246 mt9v111.i2c_slave_id, 0x01, 0x00,
247 0x04, 0, 0);
248 if (err || sn9c102_i2c_try_raw_read(cam, &mt9v111,
249 mt9v111.i2c_slave_id, 0x36, 2,
250 data) < 0)
251 return -EIO;
252
253 if (data[0] != 0x82 || data[1] != 0x3a)
254 return -ENODEV;
255
256 sn9c102_attach_sensor(cam, &mt9v111);
257
258 return 0;
259}
diff --git a/drivers/media/video/stk-sensor.c b/drivers/media/video/stk-sensor.c
new file mode 100644
index 000000000000..4a9a0b62efa3
--- /dev/null
+++ b/drivers/media/video/stk-sensor.c
@@ -0,0 +1,578 @@
1/* stk-sensor.c: Driver for ov96xx sensor (used in some Syntek webcams)
2 *
3 * Copyright 2007-2008 Jaime Velasco Juan <jsagarribay@gmail.com>
4 *
5 * Some parts derived from ov7670.c:
6 * Copyright 2006 One Laptop Per Child Association, Inc. Written
7 * by Jonathan Corbet with substantial inspiration from Mark
8 * McClelland's ovcamchip code.
9 *
10 * Copyright 2006-7 Jonathan Corbet <corbet@lwn.net>
11 *
12 * This file may be distributed under the terms of the GNU General
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28/* Controlling the sensor via the STK1125 vendor specific control interface:
29 * The camera uses an OmniVision sensor and the stk1125 provides an
30 * SCCB(i2c)-USB bridge which let us program the sensor.
31 * In my case the sensor id is 0x9652, it can be read from sensor's register
32 * 0x0A and 0x0B as follows:
33 * - read register #R:
34 * output #R to index 0x0208
35 * output 0x0070 to index 0x0200
36 * input 1 byte from index 0x0201 (some kind of status register)
37 * until its value is 0x01
38 * input 1 byte from index 0x0209. This is the value of #R
39 * - write value V to register #R
40 * output #R to index 0x0204
41 * output V to index 0x0205
42 * output 0x0005 to index 0x0200
43 * input 1 byte from index 0x0201 until its value becomes 0x04
44 */
45
46/* It seems the i2c bus is controlled with these registers */
47
48#include "stk-webcam.h"
49
50#define STK_IIC_BASE (0x0200)
51# define STK_IIC_OP (STK_IIC_BASE)
52# define STK_IIC_OP_TX (0x05)
53# define STK_IIC_OP_RX (0x70)
54# define STK_IIC_STAT (STK_IIC_BASE+1)
55# define STK_IIC_STAT_TX_OK (0x04)
56# define STK_IIC_STAT_RX_OK (0x01)
57/* I don't know what does this register.
58 * when it is 0x00 or 0x01, we cannot talk to the sensor,
59 * other values work */
60# define STK_IIC_ENABLE (STK_IIC_BASE+2)
61# define STK_IIC_ENABLE_NO (0x00)
62/* This is what the driver writes in windows */
63# define STK_IIC_ENABLE_YES (0x1e)
64/*
65 * Address of the slave. Seems like the binary driver look for the
66 * sensor in multiple places, attempting a reset sequence.
67 * We only know about the ov9650
68 */
69# define STK_IIC_ADDR (STK_IIC_BASE+3)
70# define STK_IIC_TX_INDEX (STK_IIC_BASE+4)
71# define STK_IIC_TX_VALUE (STK_IIC_BASE+5)
72# define STK_IIC_RX_INDEX (STK_IIC_BASE+8)
73# define STK_IIC_RX_VALUE (STK_IIC_BASE+9)
74
75#define MAX_RETRIES (50)
76
77#define SENSOR_ADDRESS (0x60)
78
79/* From ov7670.c (These registers aren't fully accurate) */
80
81/* Registers */
82#define REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
83#define REG_BLUE 0x01 /* blue gain */
84#define REG_RED 0x02 /* red gain */
85#define REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
86#define REG_COM1 0x04 /* Control 1 */
87#define COM1_CCIR656 0x40 /* CCIR656 enable */
88#define COM1_QFMT 0x20 /* QVGA/QCIF format */
89#define COM1_SKIP_0 0x00 /* Do not skip any row */
90#define COM1_SKIP_2 0x04 /* Skip 2 rows of 4 */
91#define COM1_SKIP_3 0x08 /* Skip 3 rows of 4 */
92#define REG_BAVE 0x05 /* U/B Average level */
93#define REG_GbAVE 0x06 /* Y/Gb Average level */
94#define REG_AECHH 0x07 /* AEC MS 5 bits */
95#define REG_RAVE 0x08 /* V/R Average level */
96#define REG_COM2 0x09 /* Control 2 */
97#define COM2_SSLEEP 0x10 /* Soft sleep mode */
98#define REG_PID 0x0a /* Product ID MSB */
99#define REG_VER 0x0b /* Product ID LSB */
100#define REG_COM3 0x0c /* Control 3 */
101#define COM3_SWAP 0x40 /* Byte swap */
102#define COM3_SCALEEN 0x08 /* Enable scaling */
103#define COM3_DCWEN 0x04 /* Enable downsamp/crop/window */
104#define REG_COM4 0x0d /* Control 4 */
105#define REG_COM5 0x0e /* All "reserved" */
106#define REG_COM6 0x0f /* Control 6 */
107#define REG_AECH 0x10 /* More bits of AEC value */
108#define REG_CLKRC 0x11 /* Clock control */
109#define CLK_PLL 0x80 /* Enable internal PLL */
110#define CLK_EXT 0x40 /* Use external clock directly */
111#define CLK_SCALE 0x3f /* Mask for internal clock scale */
112#define REG_COM7 0x12 /* Control 7 */
113#define COM7_RESET 0x80 /* Register reset */
114#define COM7_FMT_MASK 0x38
115#define COM7_FMT_SXGA 0x00
116#define COM7_FMT_VGA 0x40
117#define COM7_FMT_CIF 0x20 /* CIF format */
118#define COM7_FMT_QVGA 0x10 /* QVGA format */
119#define COM7_FMT_QCIF 0x08 /* QCIF format */
120#define COM7_RGB 0x04 /* bits 0 and 2 - RGB format */
121#define COM7_YUV 0x00 /* YUV */
122#define COM7_BAYER 0x01 /* Bayer format */
123#define COM7_PBAYER 0x05 /* "Processed bayer" */
124#define REG_COM8 0x13 /* Control 8 */
125#define COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
126#define COM8_AECSTEP 0x40 /* Unlimited AEC step size */
127#define COM8_BFILT 0x20 /* Band filter enable */
128#define COM8_AGC 0x04 /* Auto gain enable */
129#define COM8_AWB 0x02 /* White balance enable */
130#define COM8_AEC 0x01 /* Auto exposure enable */
131#define REG_COM9 0x14 /* Control 9 - gain ceiling */
132#define REG_COM10 0x15 /* Control 10 */
133#define COM10_HSYNC 0x40 /* HSYNC instead of HREF */
134#define COM10_PCLK_HB 0x20 /* Suppress PCLK on horiz blank */
135#define COM10_HREF_REV 0x08 /* Reverse HREF */
136#define COM10_VS_LEAD 0x04 /* VSYNC on clock leading edge */
137#define COM10_VS_NEG 0x02 /* VSYNC negative */
138#define COM10_HS_NEG 0x01 /* HSYNC negative */
139#define REG_HSTART 0x17 /* Horiz start high bits */
140#define REG_HSTOP 0x18 /* Horiz stop high bits */
141#define REG_VSTART 0x19 /* Vert start high bits */
142#define REG_VSTOP 0x1a /* Vert stop high bits */
143#define REG_PSHFT 0x1b /* Pixel delay after HREF */
144#define REG_MIDH 0x1c /* Manuf. ID high */
145#define REG_MIDL 0x1d /* Manuf. ID low */
146#define REG_MVFP 0x1e /* Mirror / vflip */
147#define MVFP_MIRROR 0x20 /* Mirror image */
148#define MVFP_FLIP 0x10 /* Vertical flip */
149
150#define REG_AEW 0x24 /* AGC upper limit */
151#define REG_AEB 0x25 /* AGC lower limit */
152#define REG_VPT 0x26 /* AGC/AEC fast mode op region */
153#define REG_ADVFL 0x2d /* Insert dummy lines (LSB) */
154#define REG_ADVFH 0x2e /* Insert dummy lines (MSB) */
155#define REG_HSYST 0x30 /* HSYNC rising edge delay */
156#define REG_HSYEN 0x31 /* HSYNC falling edge delay */
157#define REG_HREF 0x32 /* HREF pieces */
158#define REG_TSLB 0x3a /* lots of stuff */
159#define TSLB_YLAST 0x04 /* UYVY or VYUY - see com13 */
160#define TSLB_BYTEORD 0x08 /* swap bytes in 16bit mode? */
161#define REG_COM11 0x3b /* Control 11 */
162#define COM11_NIGHT 0x80 /* NIght mode enable */
163#define COM11_NMFR 0x60 /* Two bit NM frame rate */
164#define COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
165#define COM11_50HZ 0x08 /* Manual 50Hz select */
166#define COM11_EXP 0x02
167#define REG_COM12 0x3c /* Control 12 */
168#define COM12_HREF 0x80 /* HREF always */
169#define REG_COM13 0x3d /* Control 13 */
170#define COM13_GAMMA 0x80 /* Gamma enable */
171#define COM13_UVSAT 0x40 /* UV saturation auto adjustment */
172#define COM13_CMATRIX 0x10 /* Enable color matrix for RGB or YUV */
173#define COM13_UVSWAP 0x01 /* V before U - w/TSLB */
174#define REG_COM14 0x3e /* Control 14 */
175#define COM14_DCWEN 0x10 /* DCW/PCLK-scale enable */
176#define REG_EDGE 0x3f /* Edge enhancement factor */
177#define REG_COM15 0x40 /* Control 15 */
178#define COM15_R10F0 0x00 /* Data range 10 to F0 */
179#define COM15_R01FE 0x80 /* 01 to FE */
180#define COM15_R00FF 0xc0 /* 00 to FF */
181#define COM15_RGB565 0x10 /* RGB565 output */
182#define COM15_RGBFIXME 0x20 /* FIXME */
183#define COM15_RGB555 0x30 /* RGB555 output */
184#define REG_COM16 0x41 /* Control 16 */
185#define COM16_AWBGAIN 0x08 /* AWB gain enable */
186#define REG_COM17 0x42 /* Control 17 */
187#define COM17_AECWIN 0xc0 /* AEC window - must match COM4 */
188#define COM17_CBAR 0x08 /* DSP Color bar */
189
190/*
191 * This matrix defines how the colors are generated, must be
192 * tweaked to adjust hue and saturation.
193 *
194 * Order: v-red, v-green, v-blue, u-red, u-green, u-blue
195 *
196 * They are nine-bit signed quantities, with the sign bit
197 * stored in 0x58. Sign for v-red is bit 0, and up from there.
198 */
199#define REG_CMATRIX_BASE 0x4f
200#define CMATRIX_LEN 6
201#define REG_CMATRIX_SIGN 0x58
202
203
204#define REG_BRIGHT 0x55 /* Brightness */
205#define REG_CONTRAS 0x56 /* Contrast control */
206
207#define REG_GFIX 0x69 /* Fix gain control */
208
209#define REG_RGB444 0x8c /* RGB 444 control */
210#define R444_ENABLE 0x02 /* Turn on RGB444, overrides 5x5 */
211#define R444_RGBX 0x01 /* Empty nibble at end */
212
213#define REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
214#define REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
215
216#define REG_BD50MAX 0xa5 /* 50hz banding step limit */
217#define REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
218#define REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
219#define REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
220#define REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
221#define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
222#define REG_BD60MAX 0xab /* 60hz banding step limit */
223
224
225
226
227/* Returns 0 if OK */
228int stk_sensor_outb(struct stk_camera *dev, u8 reg, u8 val)
229{
230 int i = 0;
231 int tmpval = 0;
232
233 if (stk_camera_write_reg(dev, STK_IIC_TX_INDEX, reg))
234 return 1;
235 if (stk_camera_write_reg(dev, STK_IIC_TX_VALUE, val))
236 return 1;
237 if (stk_camera_write_reg(dev, STK_IIC_OP, STK_IIC_OP_TX))
238 return 1;
239 do {
240 if (stk_camera_read_reg(dev, STK_IIC_STAT, &tmpval))
241 return 1;
242 i++;
243 } while (tmpval == 0 && i < MAX_RETRIES);
244 if (tmpval != STK_IIC_STAT_TX_OK) {
245 if (tmpval)
246 STK_ERROR("stk_sensor_outb failed, status=0x%02x\n",
247 tmpval);
248 return 1;
249 } else
250 return 0;
251}
252
253int stk_sensor_inb(struct stk_camera *dev, u8 reg, u8 *val)
254{
255 int i = 0;
256 int tmpval = 0;
257
258 if (stk_camera_write_reg(dev, STK_IIC_RX_INDEX, reg))
259 return 1;
260 if (stk_camera_write_reg(dev, STK_IIC_OP, STK_IIC_OP_RX))
261 return 1;
262 do {
263 if (stk_camera_read_reg(dev, STK_IIC_STAT, &tmpval))
264 return 1;
265 i++;
266 } while (tmpval == 0 && i < MAX_RETRIES);
267 if (tmpval != STK_IIC_STAT_RX_OK) {
268 if (tmpval)
269 STK_ERROR("stk_sensor_inb failed, status=0x%02x\n",
270 tmpval);
271 return 1;
272 }
273
274 if (stk_camera_read_reg(dev, STK_IIC_RX_VALUE, &tmpval))
275 return 1;
276
277 *val = (u8) tmpval;
278 return 0;
279}
280
281static int stk_sensor_write_regvals(struct stk_camera *dev,
282 struct regval *rv)
283{
284 int ret;
285 if (rv == NULL)
286 return 0;
287 while (rv->reg != 0xff || rv->val != 0xff) {
288 ret = stk_sensor_outb(dev, rv->reg, rv->val);
289 if (ret != 0)
290 return ret;
291 rv++;
292 }
293 return 0;
294}
295
296int stk_sensor_sleep(struct stk_camera *dev)
297{
298 u8 tmp;
299 return stk_sensor_inb(dev, REG_COM2, &tmp)
300 || stk_sensor_outb(dev, REG_COM2, tmp|COM2_SSLEEP);
301}
302
303int stk_sensor_wakeup(struct stk_camera *dev)
304{
305 u8 tmp;
306 return stk_sensor_inb(dev, REG_COM2, &tmp)
307 || stk_sensor_outb(dev, REG_COM2, tmp&~COM2_SSLEEP);
308}
309
310static struct regval ov_initvals[] = {
311 {REG_CLKRC, CLK_PLL},
312 {REG_COM11, 0x01},
313 {0x6a, 0x7d},
314 {REG_AECH, 0x40},
315 {REG_GAIN, 0x00},
316 {REG_BLUE, 0x80},
317 {REG_RED, 0x80},
318 /* Do not enable fast AEC for now */
319 /*{REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC},*/
320 {REG_COM8, COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC},
321 {0x39, 0x50}, {0x38, 0x93},
322 {0x37, 0x00}, {0x35, 0x81},
323 {REG_COM5, 0x20},
324 {REG_COM1, 0x00},
325 {REG_COM3, 0x00},
326 {REG_COM4, 0x00},
327 {REG_PSHFT, 0x00},
328 {0x16, 0x07},
329 {0x33, 0xe2}, {0x34, 0xbf},
330 {REG_COM16, 0x00},
331 {0x96, 0x04},
332 /* Gamma curve values */
333/* { 0x7a, 0x20 }, { 0x7b, 0x10 },
334 { 0x7c, 0x1e }, { 0x7d, 0x35 },
335 { 0x7e, 0x5a }, { 0x7f, 0x69 },
336 { 0x80, 0x76 }, { 0x81, 0x80 },
337 { 0x82, 0x88 }, { 0x83, 0x8f },
338 { 0x84, 0x96 }, { 0x85, 0xa3 },
339 { 0x86, 0xaf }, { 0x87, 0xc4 },
340 { 0x88, 0xd7 }, { 0x89, 0xe8 },
341*/
342 {REG_GFIX, 0x40},
343 {0x8e, 0x00},
344 {REG_COM12, 0x73},
345 {0x8f, 0xdf}, {0x8b, 0x06},
346 {0x8c, 0x20},
347 {0x94, 0x88}, {0x95, 0x88},
348/* {REG_COM15, 0xc1}, TODO */
349 {0x29, 0x3f},
350 {REG_COM6, 0x42},
351 {REG_BD50MAX, 0x80},
352 {REG_HAECC6, 0xb8}, {REG_HAECC7, 0x92},
353 {REG_BD60MAX, 0x0a},
354 {0x90, 0x00}, {0x91, 0x00},
355 {REG_HAECC1, 0x00}, {REG_HAECC2, 0x00},
356 {REG_AEW, 0x68}, {REG_AEB, 0x5c},
357 {REG_VPT, 0xc3},
358 {REG_COM9, 0x2e},
359 {0x2a, 0x00}, {0x2b, 0x00},
360
361 {0xff, 0xff}, /* END MARKER */
362};
363
364/* Probe the I2C bus and initialise the sensor chip */
365int stk_sensor_init(struct stk_camera *dev)
366{
367 u8 idl = 0;
368 u8 idh = 0;
369
370 if (stk_camera_write_reg(dev, STK_IIC_ENABLE, STK_IIC_ENABLE_YES)
371 || stk_camera_write_reg(dev, STK_IIC_ADDR, SENSOR_ADDRESS)
372 || stk_sensor_outb(dev, REG_COM7, COM7_RESET)) {
373 STK_ERROR("Sensor resetting failed\n");
374 return -ENODEV;
375 }
376 msleep(10);
377 /* Read the manufacturer ID: ov = 0x7FA2 */
378 if (stk_sensor_inb(dev, REG_MIDH, &idh)
379 || stk_sensor_inb(dev, REG_MIDL, &idl)) {
380 STK_ERROR("Strange error reading sensor ID\n");
381 return -ENODEV;
382 }
383 if (idh != 0x7F || idl != 0xA2) {
384 STK_ERROR("Huh? you don't have a sensor from ovt\n");
385 return -ENODEV;
386 }
387 if (stk_sensor_inb(dev, REG_PID, &idh)
388 || stk_sensor_inb(dev, REG_VER, &idl)) {
389 STK_ERROR("Could not read sensor model\n");
390 return -ENODEV;
391 }
392 stk_sensor_write_regvals(dev, ov_initvals);
393 msleep(10);
394 STK_INFO("OmniVision sensor detected, id %02X%02X"
395 " at address %x\n", idh, idl, SENSOR_ADDRESS);
396 return 0;
397}
398
399/* V4L2_PIX_FMT_UYVY */
400static struct regval ov_fmt_uyvy[] = {
401 {REG_TSLB, TSLB_YLAST|0x08 },
402 { 0x4f, 0x80 }, /* "matrix coefficient 1" */
403 { 0x50, 0x80 }, /* "matrix coefficient 2" */
404 { 0x51, 0 }, /* vb */
405 { 0x52, 0x22 }, /* "matrix coefficient 4" */
406 { 0x53, 0x5e }, /* "matrix coefficient 5" */
407 { 0x54, 0x80 }, /* "matrix coefficient 6" */
408 {REG_COM13, COM13_UVSAT|COM13_CMATRIX},
409 {REG_COM15, COM15_R00FF },
410 {0xff, 0xff}, /* END MARKER */
411};
412
413/* V4L2_PIX_FMT_RGB565X rrrrrggg gggbbbbb */
414static struct regval ov_fmt_rgbr[] = {
415 { REG_RGB444, 0 }, /* No RGB444 please */
416 {REG_TSLB, 0x00},
417 { REG_COM1, 0x0 },
418 { REG_COM9, 0x38 }, /* 16x gain ceiling; 0x8 is reserved bit */
419 { 0x4f, 0xb3 }, /* "matrix coefficient 1" */
420 { 0x50, 0xb3 }, /* "matrix coefficient 2" */
421 { 0x51, 0 }, /* vb */
422 { 0x52, 0x3d }, /* "matrix coefficient 4" */
423 { 0x53, 0xa7 }, /* "matrix coefficient 5" */
424 { 0x54, 0xe4 }, /* "matrix coefficient 6" */
425 { REG_COM13, COM13_GAMMA },
426 { REG_COM15, COM15_RGB565|COM15_R00FF },
427 { 0xff, 0xff },
428};
429
430/* V4L2_PIX_FMT_RGB565 gggbbbbb rrrrrggg */
431static struct regval ov_fmt_rgbp[] = {
432 { REG_RGB444, 0 }, /* No RGB444 please */
433 {REG_TSLB, TSLB_BYTEORD },
434 { REG_COM1, 0x0 },
435 { REG_COM9, 0x38 }, /* 16x gain ceiling; 0x8 is reserved bit */
436 { 0x4f, 0xb3 }, /* "matrix coefficient 1" */
437 { 0x50, 0xb3 }, /* "matrix coefficient 2" */
438 { 0x51, 0 }, /* vb */
439 { 0x52, 0x3d }, /* "matrix coefficient 4" */
440 { 0x53, 0xa7 }, /* "matrix coefficient 5" */
441 { 0x54, 0xe4 }, /* "matrix coefficient 6" */
442 { REG_COM13, COM13_GAMMA },
443 { REG_COM15, COM15_RGB565|COM15_R00FF },
444 { 0xff, 0xff },
445};
446
447/* V4L2_PIX_FMT_SRGGB8 */
448static struct regval ov_fmt_bayer[] = {
449 /* This changes color order */
450 {REG_TSLB, 0x40}, /* BGGR */
451 /* {REG_TSLB, 0x08}, */ /* BGGR with vertical image flipping */
452 {REG_COM15, COM15_R00FF },
453 {0xff, 0xff}, /* END MARKER */
454};
455/*
456 * Store a set of start/stop values into the camera.
457 */
458static int stk_sensor_set_hw(struct stk_camera *dev,
459 int hstart, int hstop, int vstart, int vstop)
460{
461 int ret;
462 unsigned char v;
463/*
464 * Horizontal: 11 bits, top 8 live in hstart and hstop. Bottom 3 of
465 * hstart are in href[2:0], bottom 3 of hstop in href[5:3]. There is
466 * a mystery "edge offset" value in the top two bits of href.
467 */
468 ret = stk_sensor_outb(dev, REG_HSTART, (hstart >> 3) & 0xff);
469 ret += stk_sensor_outb(dev, REG_HSTOP, (hstop >> 3) & 0xff);
470 ret += stk_sensor_inb(dev, REG_HREF, &v);
471 v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x7);
472 msleep(10);
473 ret += stk_sensor_outb(dev, REG_HREF, v);
474/*
475 * Vertical: similar arrangement (note: this is different from ov7670.c)
476 */
477 ret += stk_sensor_outb(dev, REG_VSTART, (vstart >> 3) & 0xff);
478 ret += stk_sensor_outb(dev, REG_VSTOP, (vstop >> 3) & 0xff);
479 ret += stk_sensor_inb(dev, REG_VREF, &v);
480 v = (v & 0xc0) | ((vstop & 0x7) << 3) | (vstart & 0x7);
481 msleep(10);
482 ret += stk_sensor_outb(dev, REG_VREF, v);
483 return ret;
484}
485
486
487int stk_sensor_configure(struct stk_camera *dev)
488{
489 int com7;
490 /*
491 * We setup the sensor to output dummy lines in low-res modes,
492 * so we don't get absurdly hight framerates.
493 */
494 unsigned dummylines;
495 int flip;
496 struct regval *rv;
497
498 switch (dev->vsettings.mode) {
499 case MODE_QCIF: com7 = COM7_FMT_QCIF;
500 dummylines = 604;
501 break;
502 case MODE_QVGA: com7 = COM7_FMT_QVGA;
503 dummylines = 267;
504 break;
505 case MODE_CIF: com7 = COM7_FMT_CIF;
506 dummylines = 412;
507 break;
508 case MODE_VGA: com7 = COM7_FMT_VGA;
509 dummylines = 11;
510 break;
511 case MODE_SXGA: com7 = COM7_FMT_SXGA;
512 dummylines = 0;
513 break;
514 default: STK_ERROR("Unsupported mode %d\n", dev->vsettings.mode);
515 return -EFAULT;
516 }
517 switch (dev->vsettings.palette) {
518 case V4L2_PIX_FMT_UYVY:
519 com7 |= COM7_YUV;
520 rv = ov_fmt_uyvy;
521 break;
522 case V4L2_PIX_FMT_RGB565:
523 com7 |= COM7_RGB;
524 rv = ov_fmt_rgbp;
525 break;
526 case V4L2_PIX_FMT_RGB565X:
527 com7 |= COM7_RGB;
528 rv = ov_fmt_rgbr;
529 break;
530 case V4L2_PIX_FMT_SBGGR8:
531 com7 |= COM7_PBAYER;
532 rv = ov_fmt_bayer;
533 break;
534 default: STK_ERROR("Unsupported colorspace\n");
535 return -EFAULT;
536 }
537 /*FIXME sometimes the sensor go to a bad state
538 stk_sensor_write_regvals(dev, ov_initvals); */
539 stk_sensor_outb(dev, REG_COM7, com7);
540 msleep(50);
541 stk_sensor_write_regvals(dev, rv);
542 flip = (dev->vsettings.vflip?MVFP_FLIP:0)
543 | (dev->vsettings.hflip?MVFP_MIRROR:0);
544 stk_sensor_outb(dev, REG_MVFP, flip);
545 if (dev->vsettings.palette == V4L2_PIX_FMT_SBGGR8
546 && !dev->vsettings.vflip)
547 stk_sensor_outb(dev, REG_TSLB, 0x08);
548 stk_sensor_outb(dev, REG_ADVFH, dummylines >> 8);
549 stk_sensor_outb(dev, REG_ADVFL, dummylines & 0xff);
550 msleep(50);
551 switch (dev->vsettings.mode) {
552 case MODE_VGA:
553 if (stk_sensor_set_hw(dev, 302, 1582, 6, 486))
554 STK_ERROR("stk_sensor_set_hw failed (VGA)\n");
555 break;
556 case MODE_SXGA:
557 case MODE_CIF:
558 case MODE_QVGA:
559 case MODE_QCIF:
560 /*FIXME These settings seem ignored by the sensor
561 if (stk_sensor_set_hw(dev, 220, 1500, 10, 1034))
562 STK_ERROR("stk_sensor_set_hw failed (SXGA)\n");
563 */
564 break;
565 }
566 msleep(10);
567 return 0;
568}
569
570int stk_sensor_set_brightness(struct stk_camera *dev, int br)
571{
572 if (br < 0 || br > 0xff)
573 return -EINVAL;
574 stk_sensor_outb(dev, REG_AEB, max(0x00, br - 6));
575 stk_sensor_outb(dev, REG_AEW, min(0xff, br + 6));
576 return 0;
577}
578
diff --git a/drivers/media/video/stk-webcam.c b/drivers/media/video/stk-webcam.c
new file mode 100644
index 000000000000..d37e5e2594b4
--- /dev/null
+++ b/drivers/media/video/stk-webcam.c
@@ -0,0 +1,1465 @@
1/*
2 * stk-webcam.c : Driver for Syntek 1125 USB webcam controller
3 *
4 * Copyright (C) 2006 Nicolas VIVIEN
5 * Copyright 2007-2008 Jaime Velasco Juan <jsagarribay@gmail.com>
6 *
7 * Some parts are inspired from cafe_ccic.c
8 * Copyright 2006-2007 Jonathan Corbet
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/errno.h>
29#include <linux/slab.h>
30#include <linux/kref.h>
31
32#include <linux/usb.h>
33#include <linux/vmalloc.h>
34#include <linux/videodev2.h>
35#include <media/v4l2-common.h>
36
37#include "stk-webcam.h"
38
39
40static int hflip = 1;
41module_param(hflip, bool, 0444);
42MODULE_PARM_DESC(hflip, "Horizontal image flip (mirror). Defaults to 1");
43
44static int vflip = 1;
45module_param(vflip, bool, 0444);
46MODULE_PARM_DESC(vflip, "Vertical image flip. Defaults to 1");
47
48static int debug;
49module_param(debug, int, 0444);
50MODULE_PARM_DESC(debug, "Debug v4l ioctls. Defaults to 0");
51
52MODULE_LICENSE("GPL");
53MODULE_AUTHOR("Jaime Velasco Juan <jsagarribay@gmail.com> and Nicolas VIVIEN");
54MODULE_DESCRIPTION("Syntek DC1125 webcam driver");
55
56
57
58/* Some cameras have audio interfaces, we aren't interested in those */
59static struct usb_device_id stkwebcam_table[] = {
60 { USB_DEVICE_AND_INTERFACE_INFO(0x174f, 0xa311, 0xff, 0xff, 0xff) },
61 { USB_DEVICE_AND_INTERFACE_INFO(0x05e1, 0x0501, 0xff, 0xff, 0xff) },
62 { }
63};
64MODULE_DEVICE_TABLE(usb, stkwebcam_table);
65
66void stk_camera_cleanup(struct kref *kref)
67{
68 struct stk_camera *dev = to_stk_camera(kref);
69
70 STK_INFO("Syntek USB2.0 Camera release resources"
71 " video device /dev/video%d\n", dev->vdev.minor);
72 video_unregister_device(&dev->vdev);
73 dev->vdev.priv = NULL;
74
75 if (dev->sio_bufs != NULL || dev->isobufs != NULL)
76 STK_ERROR("We are leaking memory\n");
77 usb_put_intf(dev->interface);
78 kfree(dev);
79}
80
81
82/*
83 * Basic stuff
84 */
85int stk_camera_write_reg(struct stk_camera *dev, u16 index, u8 value)
86{
87 struct usb_device *udev = dev->udev;
88 int ret;
89
90 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
91 0x01,
92 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
93 value,
94 index,
95 NULL,
96 0,
97 500);
98 if (ret < 0)
99 return ret;
100 else
101 return 0;
102}
103
104int stk_camera_read_reg(struct stk_camera *dev, u16 index, int *value)
105{
106 struct usb_device *udev = dev->udev;
107 int ret;
108
109 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
110 0x00,
111 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
112 0x00,
113 index,
114 (u8 *) value,
115 sizeof(u8),
116 500);
117 if (ret < 0)
118 return ret;
119 else
120 return 0;
121}
122
123static int stk_start_stream(struct stk_camera *dev)
124{
125 int value;
126 int i, ret;
127 int value_116, value_117;
128
129 if (!is_present(dev))
130 return -ENODEV;
131 if (!is_memallocd(dev) || !is_initialised(dev)) {
132 STK_ERROR("FIXME: Buffers are not allocated\n");
133 return -EFAULT;
134 }
135 ret = usb_set_interface(dev->udev, 0, 5);
136
137 if (ret < 0)
138 STK_ERROR("usb_set_interface failed !\n");
139 if (stk_sensor_wakeup(dev))
140 STK_ERROR("error awaking the sensor\n");
141
142 stk_camera_read_reg(dev, 0x0116, &value_116);
143 stk_camera_read_reg(dev, 0x0117, &value_117);
144
145 stk_camera_write_reg(dev, 0x0116, 0x0000);
146 stk_camera_write_reg(dev, 0x0117, 0x0000);
147
148 stk_camera_read_reg(dev, 0x0100, &value);
149 stk_camera_write_reg(dev, 0x0100, value | 0x80);
150
151 stk_camera_write_reg(dev, 0x0116, value_116);
152 stk_camera_write_reg(dev, 0x0117, value_117);
153 for (i = 0; i < MAX_ISO_BUFS; i++) {
154 if (dev->isobufs[i].urb) {
155 ret = usb_submit_urb(dev->isobufs[i].urb, GFP_KERNEL);
156 atomic_inc(&dev->urbs_used);
157 if (ret)
158 return ret;
159 }
160 }
161 set_streaming(dev);
162 return 0;
163}
164
165static int stk_stop_stream(struct stk_camera *dev)
166{
167 int value;
168 int i;
169 if (is_present(dev)) {
170 stk_camera_read_reg(dev, 0x0100, &value);
171 stk_camera_write_reg(dev, 0x0100, value & ~0x80);
172 if (dev->isobufs != NULL) {
173 for (i = 0; i < MAX_ISO_BUFS; i++) {
174 if (dev->isobufs[i].urb)
175 usb_kill_urb(dev->isobufs[i].urb);
176 }
177 }
178 unset_streaming(dev);
179
180 if (usb_set_interface(dev->udev, 0, 0))
181 STK_ERROR("usb_set_interface failed !\n");
182 if (stk_sensor_sleep(dev))
183 STK_ERROR("error suspending the sensor\n");
184 }
185 return 0;
186}
187
188/*
189 * This seems to be the shortest init sequence we
190 * must do in order to find the sensor
191 * Bit 5 of reg. 0x0000 here is important, when reset to 0 the sensor
192 * is also reset. Maybe powers down it?
193 * Rest of values don't make a difference
194 */
195
196static struct regval stk1125_initvals[] = {
197 /*TODO: What means this sequence? */
198 {0x0000, 0x24},
199 {0x0100, 0x21},
200 {0x0002, 0x68},
201 {0x0003, 0x80},
202 {0x0005, 0x00},
203 {0x0007, 0x03},
204 {0x000d, 0x00},
205 {0x000f, 0x02},
206 {0x0300, 0x12},
207 {0x0350, 0x41},
208 {0x0351, 0x00},
209 {0x0352, 0x00},
210 {0x0353, 0x00},
211 {0x0018, 0x10},
212 {0x0019, 0x00},
213 {0x001b, 0x0e},
214 {0x001c, 0x46},
215 {0x0300, 0x80},
216 {0x001a, 0x04},
217 {0x0110, 0x00},
218 {0x0111, 0x00},
219 {0x0112, 0x00},
220 {0x0113, 0x00},
221
222 {0xffff, 0xff},
223};
224
225
226static int stk_initialise(struct stk_camera *dev)
227{
228 struct regval *rv;
229 int ret;
230 if (!is_present(dev))
231 return -ENODEV;
232 if (is_initialised(dev))
233 return 0;
234 rv = stk1125_initvals;
235 while (rv->reg != 0xffff) {
236 ret = stk_camera_write_reg(dev, rv->reg, rv->val);
237 if (ret)
238 return ret;
239 rv++;
240 }
241 if (stk_sensor_init(dev) == 0) {
242 set_initialised(dev);
243 return 0;
244 } else
245 return -1;
246}
247
248/* sysfs functions */
249/*FIXME cleanup this */
250
251static ssize_t show_brightness(struct device *class,
252 struct device_attribute *attr, char *buf)
253{
254 struct video_device *vdev = to_video_device(class);
255 struct stk_camera *dev = vdev_to_camera(vdev);
256
257 return sprintf(buf, "%X\n", dev->vsettings.brightness);
258}
259
260static ssize_t store_brightness(struct device *class,
261 struct device_attribute *attr, const char *buf, size_t count)
262{
263 char *endp;
264 unsigned long value;
265 int ret;
266
267 struct video_device *vdev = to_video_device(class);
268 struct stk_camera *dev = vdev_to_camera(vdev);
269
270 value = simple_strtoul(buf, &endp, 16);
271
272 dev->vsettings.brightness = (int) value;
273
274 ret = stk_sensor_set_brightness(dev, value >> 8);
275 if (ret)
276 return ret;
277 else
278 return count;
279}
280
281static ssize_t show_hflip(struct device *class,
282 struct device_attribute *attr, char *buf)
283{
284 struct video_device *vdev = to_video_device(class);
285 struct stk_camera *dev = vdev_to_camera(vdev);
286
287 return sprintf(buf, "%d\n", dev->vsettings.hflip);
288}
289
290static ssize_t store_hflip(struct device *class,
291 struct device_attribute *attr, const char *buf, size_t count)
292{
293 struct video_device *vdev = to_video_device(class);
294 struct stk_camera *dev = vdev_to_camera(vdev);
295
296 if (strncmp(buf, "1", 1) == 0)
297 dev->vsettings.hflip = 1;
298 else if (strncmp(buf, "0", 1) == 0)
299 dev->vsettings.hflip = 0;
300 else
301 return -EINVAL;
302
303 return strlen(buf);
304}
305
306static ssize_t show_vflip(struct device *class,
307 struct device_attribute *attr, char *buf)
308{
309 struct video_device *vdev = to_video_device(class);
310 struct stk_camera *dev = vdev_to_camera(vdev);
311
312 return sprintf(buf, "%d\n", dev->vsettings.vflip);
313}
314
315static ssize_t store_vflip(struct device *class,
316 struct device_attribute *attr, const char *buf, size_t count)
317{
318 struct video_device *vdev = to_video_device(class);
319 struct stk_camera *dev = vdev_to_camera(vdev);
320
321 if (strncmp(buf, "1", 1) == 0)
322 dev->vsettings.vflip = 1;
323 else if (strncmp(buf, "0", 1) == 0)
324 dev->vsettings.vflip = 0;
325 else
326 return -EINVAL;
327
328 return strlen(buf);
329}
330
331static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO,
332 show_brightness, store_brightness);
333static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip);
334static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip);
335
336static int stk_create_sysfs_files(struct video_device *vdev)
337{
338 int ret;
339
340 ret = video_device_create_file(vdev, &dev_attr_brightness);
341 ret += video_device_create_file(vdev, &dev_attr_hflip);
342 ret += video_device_create_file(vdev, &dev_attr_vflip);
343 return ret;
344}
345
346static void stk_remove_sysfs_files(struct video_device *vdev)
347{
348 video_device_remove_file(vdev, &dev_attr_brightness);
349 video_device_remove_file(vdev, &dev_attr_hflip);
350 video_device_remove_file(vdev, &dev_attr_vflip);
351}
352
353
354/* *********************************************** */
355/*
356 * This function is called as an URB transfert is complete (Isochronous pipe).
357 * So, the traitement is done in interrupt time, so it has be fast, not crash,
358 * and not stall. Neat.
359 */
360static void stk_isoc_handler(struct urb *urb)
361{
362 int i;
363 int ret;
364 int framelen;
365 unsigned long flags;
366
367 unsigned char *fill = NULL;
368 unsigned char *iso_buf = NULL;
369
370 struct stk_camera *dev;
371 struct stk_sio_buffer *fb;
372
373 dev = (struct stk_camera *) urb->context;
374
375 if (dev == NULL) {
376 STK_ERROR("isoc_handler called with NULL device !\n");
377 return;
378 }
379
380 if (urb->status == -ENOENT || urb->status == -ECONNRESET
381 || urb->status == -ESHUTDOWN) {
382 atomic_dec(&dev->urbs_used);
383 return;
384 }
385
386 spin_lock_irqsave(&dev->spinlock, flags);
387
388 if (urb->status != -EINPROGRESS && urb->status != 0) {
389 STK_ERROR("isoc_handler: urb->status == %d\n", urb->status);
390 goto resubmit;
391 }
392
393 if (list_empty(&dev->sio_avail)) {
394 /*FIXME Stop streaming after a while */
395 (void) (printk_ratelimit() &&
396 STK_ERROR("isoc_handler without available buffer!\n"));
397 goto resubmit;
398 }
399 fb = list_first_entry(&dev->sio_avail,
400 struct stk_sio_buffer, list);
401 fill = fb->buffer + fb->v4lbuf.bytesused;
402
403 for (i = 0; i < urb->number_of_packets; i++) {
404 if (urb->iso_frame_desc[i].status != 0) {
405 if (urb->iso_frame_desc[i].status != -EXDEV)
406 STK_ERROR("Frame %d has error %d\n", i,
407 urb->iso_frame_desc[i].status);
408 continue;
409 }
410 framelen = urb->iso_frame_desc[i].actual_length;
411 iso_buf = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
412
413 if (framelen <= 4)
414 continue; /* no data */
415
416 /*
417 * we found something informational from there
418 * the isoc frames have to type of headers
419 * type1: 00 xx 00 00 or 20 xx 00 00
420 * type2: 80 xx 00 00 00 00 00 00 or a0 xx 00 00 00 00 00 00
421 * xx is a sequencer which has never been seen over 0x3f
422 * imho data written down looks like bayer, i see similarities
423 * after every 640 bytes
424 */
425 if (*iso_buf & 0x80) {
426 framelen -= 8;
427 iso_buf += 8;
428 /* This marks a new frame */
429 if (fb->v4lbuf.bytesused != 0
430 && fb->v4lbuf.bytesused != dev->frame_size) {
431 (void) (printk_ratelimit() &&
432 STK_ERROR("frame %d, "
433 "bytesused=%d, skipping\n",
434 i, fb->v4lbuf.bytesused));
435 fb->v4lbuf.bytesused = 0;
436 fill = fb->buffer;
437 } else if (fb->v4lbuf.bytesused == dev->frame_size) {
438 list_move_tail(dev->sio_avail.next,
439 &dev->sio_full);
440 wake_up(&dev->wait_frame);
441 if (list_empty(&dev->sio_avail)) {
442 (void) (printk_ratelimit() &&
443 STK_ERROR("No buffer available\n"));
444 goto resubmit;
445 }
446 fb = list_first_entry(&dev->sio_avail,
447 struct stk_sio_buffer, list);
448 fb->v4lbuf.bytesused = 0;
449 fill = fb->buffer;
450 }
451 } else {
452 framelen -= 4;
453 iso_buf += 4;
454 }
455
456 /* Our buffer is full !!! */
457 if (framelen + fb->v4lbuf.bytesused > dev->frame_size) {
458 (void) (printk_ratelimit() &&
459 STK_ERROR("Frame buffer overflow, lost sync\n"));
460 /*FIXME Do something here? */
461 continue;
462 }
463 spin_unlock_irqrestore(&dev->spinlock, flags);
464 memcpy(fill, iso_buf, framelen);
465 spin_lock_irqsave(&dev->spinlock, flags);
466 fill += framelen;
467
468 /* New size of our buffer */
469 fb->v4lbuf.bytesused += framelen;
470 }
471
472resubmit:
473 spin_unlock_irqrestore(&dev->spinlock, flags);
474 urb->dev = dev->udev;
475 ret = usb_submit_urb(urb, GFP_ATOMIC);
476 if (ret != 0) {
477 STK_ERROR("Error (%d) re-submitting urb in stk_isoc_handler.\n",
478 ret);
479 }
480}
481
482/* -------------------------------------------- */
483
484static int stk_prepare_iso(struct stk_camera *dev)
485{
486 void *kbuf;
487 int i, j;
488 struct urb *urb;
489 struct usb_device *udev;
490
491 if (dev == NULL)
492 return -ENXIO;
493 udev = dev->udev;
494
495 if (dev->isobufs)
496 STK_ERROR("isobufs already allocated. Bad\n");
497 else
498 dev->isobufs = kzalloc(MAX_ISO_BUFS * sizeof(*dev->isobufs),
499 GFP_KERNEL);
500 if (dev->isobufs == NULL) {
501 STK_ERROR("Unable to allocate iso buffers\n");
502 return -ENOMEM;
503 }
504 for (i = 0; i < MAX_ISO_BUFS; i++) {
505 if (dev->isobufs[i].data == NULL) {
506 kbuf = kzalloc(ISO_BUFFER_SIZE, GFP_KERNEL);
507 if (kbuf == NULL) {
508 STK_ERROR("Failed to allocate iso buffer %d\n",
509 i);
510 goto isobufs_out;
511 }
512 dev->isobufs[i].data = kbuf;
513 } else
514 STK_ERROR("isobuf data already allocated\n");
515 if (dev->isobufs[i].urb == NULL) {
516 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL);
517 if (urb == NULL) {
518 STK_ERROR("Failed to allocate URB %d\n", i);
519 goto isobufs_out;
520 }
521 dev->isobufs[i].urb = urb;
522 } else {
523 STK_ERROR("Killing URB\n");
524 usb_kill_urb(dev->isobufs[i].urb);
525 urb = dev->isobufs[i].urb;
526 }
527 urb->interval = 1;
528 urb->dev = udev;
529 urb->pipe = usb_rcvisocpipe(udev, dev->isoc_ep);
530 urb->transfer_flags = URB_ISO_ASAP;
531 urb->transfer_buffer = dev->isobufs[i].data;
532 urb->transfer_buffer_length = ISO_BUFFER_SIZE;
533 urb->complete = stk_isoc_handler;
534 urb->context = dev;
535 urb->start_frame = 0;
536 urb->number_of_packets = ISO_FRAMES_PER_DESC;
537
538 for (j = 0; j < ISO_FRAMES_PER_DESC; j++) {
539 urb->iso_frame_desc[j].offset = j * ISO_MAX_FRAME_SIZE;
540 urb->iso_frame_desc[j].length = ISO_MAX_FRAME_SIZE;
541 }
542 }
543 set_memallocd(dev);
544 return 0;
545
546isobufs_out:
547 for (i = 0; i < MAX_ISO_BUFS && dev->isobufs[i].data; i++)
548 kfree(dev->isobufs[i].data);
549 for (i = 0; i < MAX_ISO_BUFS && dev->isobufs[i].urb; i++)
550 usb_free_urb(dev->isobufs[i].urb);
551 kfree(dev->isobufs);
552 dev->isobufs = NULL;
553 return -ENOMEM;
554}
555
556static void stk_clean_iso(struct stk_camera *dev)
557{
558 int i;
559
560 if (dev == NULL || dev->isobufs == NULL)
561 return;
562
563 for (i = 0; i < MAX_ISO_BUFS; i++) {
564 struct urb *urb;
565
566 urb = dev->isobufs[i].urb;
567 if (urb) {
568 if (atomic_read(&dev->urbs_used))
569 usb_kill_urb(urb);
570 usb_free_urb(urb);
571 }
572 kfree(dev->isobufs[i].data);
573 }
574 kfree(dev->isobufs);
575 dev->isobufs = NULL;
576 unset_memallocd(dev);
577}
578
579static int stk_setup_siobuf(struct stk_camera *dev, int index)
580{
581 struct stk_sio_buffer *buf = dev->sio_bufs + index;
582 INIT_LIST_HEAD(&buf->list);
583 buf->v4lbuf.length = PAGE_ALIGN(dev->frame_size);
584 buf->buffer = vmalloc_user(buf->v4lbuf.length);
585 if (buf->buffer == NULL)
586 return -ENOMEM;
587 buf->mapcount = 0;
588 buf->dev = dev;
589 buf->v4lbuf.index = index;
590 buf->v4lbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
591 buf->v4lbuf.field = V4L2_FIELD_NONE;
592 buf->v4lbuf.memory = V4L2_MEMORY_MMAP;
593 buf->v4lbuf.m.offset = 2*index*buf->v4lbuf.length;
594 return 0;
595}
596
597static int stk_free_sio_buffers(struct stk_camera *dev)
598{
599 int i;
600 int nbufs;
601 unsigned long flags;
602 if (dev->n_sbufs == 0 || dev->sio_bufs == NULL)
603 return 0;
604 /*
605 * If any buffers are mapped, we cannot free them at all.
606 */
607 for (i = 0; i < dev->n_sbufs; i++) {
608 if (dev->sio_bufs[i].mapcount > 0)
609 return -EBUSY;
610 }
611 /*
612 * OK, let's do it.
613 */
614 spin_lock_irqsave(&dev->spinlock, flags);
615 INIT_LIST_HEAD(&dev->sio_avail);
616 INIT_LIST_HEAD(&dev->sio_full);
617 nbufs = dev->n_sbufs;
618 dev->n_sbufs = 0;
619 spin_unlock_irqrestore(&dev->spinlock, flags);
620 for (i = 0; i < nbufs; i++) {
621 if (dev->sio_bufs[i].buffer != NULL)
622 vfree(dev->sio_bufs[i].buffer);
623 }
624 kfree(dev->sio_bufs);
625 dev->sio_bufs = NULL;
626 return 0;
627}
628
629static int stk_prepare_sio_buffers(struct stk_camera *dev, unsigned n_sbufs)
630{
631 int i;
632 if (dev->sio_bufs != NULL)
633 STK_ERROR("sio_bufs already allocated\n");
634 else {
635 dev->sio_bufs = kzalloc(n_sbufs * sizeof(struct stk_sio_buffer),
636 GFP_KERNEL);
637 if (dev->sio_bufs == NULL)
638 return -ENOMEM;
639 for (i = 0; i < n_sbufs; i++) {
640 if (stk_setup_siobuf(dev, i))
641 return (dev->n_sbufs > 1)? 0 : -ENOMEM;
642 dev->n_sbufs = i+1;
643 }
644 }
645 return 0;
646}
647
648static int stk_allocate_buffers(struct stk_camera *dev, unsigned n_sbufs)
649{
650 int err;
651 err = stk_prepare_iso(dev);
652 if (err) {
653 stk_clean_iso(dev);
654 return err;
655 }
656 err = stk_prepare_sio_buffers(dev, n_sbufs);
657 if (err) {
658 stk_free_sio_buffers(dev);
659 return err;
660 }
661 return 0;
662}
663
664static void stk_free_buffers(struct stk_camera *dev)
665{
666 stk_clean_iso(dev);
667 stk_free_sio_buffers(dev);
668}
669/* -------------------------------------------- */
670
671/* v4l file operations */
672
673static int v4l_stk_open(struct inode *inode, struct file *fp)
674{
675 struct stk_camera *dev;
676 struct video_device *vdev;
677
678 vdev = video_devdata(fp);
679 dev = vdev_to_camera(vdev);
680
681 if (dev == NULL || !is_present(dev))
682 return -ENXIO;
683 fp->private_data = vdev;
684 kref_get(&dev->kref);
685
686 return 0;
687}
688
689static int v4l_stk_release(struct inode *inode, struct file *fp)
690{
691 struct stk_camera *dev;
692 struct video_device *vdev;
693
694 vdev = video_devdata(fp);
695 if (vdev == NULL) {
696 STK_ERROR("v4l_release called w/o video devdata\n");
697 return -EFAULT;
698 }
699 dev = vdev_to_camera(vdev);
700 if (dev == NULL) {
701 STK_ERROR("v4l_release called on removed device\n");
702 return -ENODEV;
703 }
704
705 if (dev->owner != fp) {
706 kref_put(&dev->kref, stk_camera_cleanup);
707 return 0;
708 }
709
710 stk_stop_stream(dev);
711
712 stk_free_buffers(dev);
713
714 dev->owner = NULL;
715
716 kref_put(&dev->kref, stk_camera_cleanup);
717
718 return 0;
719}
720
721static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
722 size_t count, loff_t *f_pos)
723{
724 int i;
725 int ret;
726 unsigned long flags;
727 struct stk_camera *dev;
728 struct video_device *vdev;
729 struct stk_sio_buffer *sbuf;
730
731 vdev = video_devdata(fp);
732 if (vdev == NULL)
733 return -EFAULT;
734 dev = vdev_to_camera(vdev);
735
736 if (dev == NULL)
737 return -EIO;
738
739 if (!is_present(dev))
740 return -EIO;
741 if (dev->owner && dev->owner != fp)
742 return -EBUSY;
743 dev->owner = fp;
744 if (!is_streaming(dev)) {
745 if (stk_initialise(dev)
746 || stk_allocate_buffers(dev, 3)
747 || stk_start_stream(dev))
748 return -ENOMEM;
749 spin_lock_irqsave(&dev->spinlock, flags);
750 for (i = 0; i < dev->n_sbufs; i++) {
751 list_add_tail(&dev->sio_bufs[i].list, &dev->sio_avail);
752 dev->sio_bufs[i].v4lbuf.flags = V4L2_BUF_FLAG_QUEUED;
753 }
754 spin_unlock_irqrestore(&dev->spinlock, flags);
755 }
756 if (*f_pos == 0) {
757 if (fp->f_flags & O_NONBLOCK && list_empty(&dev->sio_full))
758 return -EWOULDBLOCK;
759 ret = wait_event_interruptible(dev->wait_frame,
760 !list_empty(&dev->sio_full) || !is_present(dev));
761 if (ret)
762 return ret;
763 if (!is_present(dev))
764 return -EIO;
765 }
766 if (count + *f_pos > dev->frame_size)
767 count = dev->frame_size - *f_pos;
768 spin_lock_irqsave(&dev->spinlock, flags);
769 if (list_empty(&dev->sio_full)) {
770 spin_unlock_irqrestore(&dev->spinlock, flags);
771 STK_ERROR("BUG: No siobufs ready\n");
772 return 0;
773 }
774 sbuf = list_first_entry(&dev->sio_full, struct stk_sio_buffer, list);
775 spin_unlock_irqrestore(&dev->spinlock, flags);
776
777 if (copy_to_user(buf, sbuf->buffer + *f_pos, count))
778 return -EFAULT;
779
780 *f_pos += count;
781
782 if (*f_pos >= dev->frame_size) {
783 *f_pos = 0;
784 spin_lock_irqsave(&dev->spinlock, flags);
785 list_move_tail(&sbuf->list, &dev->sio_avail);
786 spin_unlock_irqrestore(&dev->spinlock, flags);
787 }
788 return count;
789}
790
791static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait)
792{
793 struct stk_camera *dev;
794 struct video_device *vdev;
795
796 vdev = video_devdata(fp);
797
798 if (vdev == NULL)
799 return -EFAULT;
800
801 dev = vdev_to_camera(vdev);
802 if (dev == NULL)
803 return -ENODEV;
804
805 poll_wait(fp, &dev->wait_frame, wait);
806
807 if (!is_present(dev))
808 return POLLERR;
809
810 if (!list_empty(&dev->sio_full))
811 return (POLLIN | POLLRDNORM);
812
813 return 0;
814}
815
816
817static void stk_v4l_vm_open(struct vm_area_struct *vma)
818{
819 struct stk_sio_buffer *sbuf = vma->vm_private_data;
820 sbuf->mapcount++;
821}
822static void stk_v4l_vm_close(struct vm_area_struct *vma)
823{
824 struct stk_sio_buffer *sbuf = vma->vm_private_data;
825 sbuf->mapcount--;
826 if (sbuf->mapcount == 0)
827 sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_MAPPED;
828}
829static struct vm_operations_struct stk_v4l_vm_ops = {
830 .open = stk_v4l_vm_open,
831 .close = stk_v4l_vm_close
832};
833
834static int v4l_stk_mmap(struct file *fp, struct vm_area_struct *vma)
835{
836 unsigned int i;
837 int ret;
838 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
839 struct stk_camera *dev;
840 struct video_device *vdev;
841 struct stk_sio_buffer *sbuf = NULL;
842
843 if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
844 return -EINVAL;
845
846 vdev = video_devdata(fp);
847 dev = vdev_to_camera(vdev);
848
849 for (i = 0; i < dev->n_sbufs; i++) {
850 if (dev->sio_bufs[i].v4lbuf.m.offset == offset) {
851 sbuf = dev->sio_bufs + i;
852 break;
853 }
854 }
855 if (sbuf == NULL)
856 return -EINVAL;
857 ret = remap_vmalloc_range(vma, sbuf->buffer, 0);
858 if (ret)
859 return ret;
860 vma->vm_flags |= VM_DONTEXPAND;
861 vma->vm_private_data = sbuf;
862 vma->vm_ops = &stk_v4l_vm_ops;
863 sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_MAPPED;
864 stk_v4l_vm_open(vma);
865 return 0;
866}
867
868/* v4l ioctl handlers */
869
870static int stk_vidioc_querycap(struct file *filp,
871 void *priv, struct v4l2_capability *cap)
872{
873 strcpy(cap->driver, "stk");
874 strcpy(cap->card, "stk");
875 cap->version = DRIVER_VERSION_NUM;
876
877 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
878 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
879 return 0;
880}
881
882static int stk_vidioc_enum_input(struct file *filp,
883 void *priv, struct v4l2_input *input)
884{
885 if (input->index != 0)
886 return -EINVAL;
887
888 strcpy(input->name, "Syntek USB Camera");
889 input->type = V4L2_INPUT_TYPE_CAMERA;
890 return 0;
891}
892
893
894static int stk_vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
895{
896 *i = 0;
897 return 0;
898}
899
900static int stk_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
901{
902 if (i != 0)
903 return -EINVAL;
904 else
905 return 0;
906}
907
908/* from vivi.c */
909static int stk_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id *a)
910{
911 return 0;
912}
913
914/* List of all V4Lv2 controls supported by the driver */
915static struct v4l2_queryctrl stk_controls[] = {
916 {
917 .id = V4L2_CID_BRIGHTNESS,
918 .type = V4L2_CTRL_TYPE_INTEGER,
919 .name = "Brightness",
920 .minimum = 0,
921 .maximum = 0xffff,
922 .step = 0x0100,
923 .default_value = 0x6000,
924 },
925 /*TODO: get more controls to work */
926};
927
928static int stk_vidioc_queryctrl(struct file *filp,
929 void *priv, struct v4l2_queryctrl *c)
930{
931 int i;
932 int nbr;
933 nbr = ARRAY_SIZE(stk_controls);
934
935 for (i = 0; i < nbr; i++) {
936 if (stk_controls[i].id == c->id) {
937 memcpy(c, &stk_controls[i],
938 sizeof(struct v4l2_queryctrl));
939 return 0;
940 }
941 }
942 return -EINVAL;
943}
944
945static int stk_vidioc_g_ctrl(struct file *filp,
946 void *priv, struct v4l2_control *c)
947{
948 struct stk_camera *dev = priv;
949 switch (c->id) {
950 case V4L2_CID_BRIGHTNESS:
951 c->value = dev->vsettings.brightness;
952 break;
953 default:
954 return -EINVAL;
955 }
956 return 0;
957}
958
959static int stk_vidioc_s_ctrl(struct file *filp,
960 void *priv, struct v4l2_control *c)
961{
962 struct stk_camera *dev = priv;
963 switch (c->id) {
964 case V4L2_CID_BRIGHTNESS:
965 dev->vsettings.brightness = c->value;
966 return stk_sensor_set_brightness(dev, c->value >> 8);
967 default:
968 return -EINVAL;
969 }
970 return 0;
971}
972
973
974static int stk_vidioc_enum_fmt_cap(struct file *filp,
975 void *priv, struct v4l2_fmtdesc *fmtd)
976{
977 fmtd->flags = 0;
978
979 switch (fmtd->index) {
980 case 0:
981 fmtd->pixelformat = V4L2_PIX_FMT_RGB565;
982 strcpy(fmtd->description, "r5g6b5");
983 break;
984 case 1:
985 fmtd->pixelformat = V4L2_PIX_FMT_RGB565X;
986 strcpy(fmtd->description, "r5g6b5BE");
987 break;
988 case 2:
989 fmtd->pixelformat = V4L2_PIX_FMT_UYVY;
990 strcpy(fmtd->description, "yuv4:2:2");
991 break;
992 case 3:
993 fmtd->pixelformat = V4L2_PIX_FMT_SBGGR8;
994 strcpy(fmtd->description, "Raw bayer");
995 break;
996 default:
997 return -EINVAL;
998 }
999 return 0;
1000}
1001
1002static struct stk_size {
1003 unsigned w;
1004 unsigned h;
1005 enum stk_mode m;
1006} stk_sizes[] = {
1007 { .w = 1280, .h = 1024, .m = MODE_SXGA, },
1008 { .w = 640, .h = 480, .m = MODE_VGA, },
1009 { .w = 352, .h = 288, .m = MODE_CIF, },
1010 { .w = 320, .h = 240, .m = MODE_QVGA, },
1011 { .w = 176, .h = 144, .m = MODE_QCIF, },
1012};
1013
1014static int stk_vidioc_g_fmt_cap(struct file *filp,
1015 void *priv, struct v4l2_format *f)
1016{
1017 struct v4l2_pix_format *pix_format = &f->fmt.pix;
1018 struct stk_camera *dev = priv;
1019 int i;
1020
1021 for (i = 0; i < ARRAY_SIZE(stk_sizes)
1022 && stk_sizes[i].m != dev->vsettings.mode;
1023 i++);
1024 if (i == ARRAY_SIZE(stk_sizes)) {
1025 STK_ERROR("ERROR: mode invalid\n");
1026 return -EINVAL;
1027 }
1028 pix_format->width = stk_sizes[i].w;
1029 pix_format->height = stk_sizes[i].h;
1030 pix_format->field = V4L2_FIELD_NONE;
1031 pix_format->colorspace = V4L2_COLORSPACE_SRGB;
1032 pix_format->priv = 0;
1033 pix_format->pixelformat = dev->vsettings.palette;
1034 if (dev->vsettings.palette == V4L2_PIX_FMT_SBGGR8)
1035 pix_format->bytesperline = pix_format->width;
1036 else
1037 pix_format->bytesperline = 2 * pix_format->width;
1038 pix_format->sizeimage = pix_format->bytesperline
1039 * pix_format->height;
1040 return 0;
1041}
1042
1043static int stk_vidioc_try_fmt_cap(struct file *filp,
1044 void *priv, struct v4l2_format *fmtd)
1045{
1046 int i;
1047 switch (fmtd->fmt.pix.pixelformat) {
1048 case V4L2_PIX_FMT_RGB565:
1049 case V4L2_PIX_FMT_RGB565X:
1050 case V4L2_PIX_FMT_UYVY:
1051 case V4L2_PIX_FMT_SBGGR8:
1052 break;
1053 default:
1054 return -EINVAL;
1055 }
1056 for (i = 1; i < ARRAY_SIZE(stk_sizes); i++) {
1057 if (fmtd->fmt.pix.width > stk_sizes[i].w)
1058 break;
1059 }
1060 if (i == ARRAY_SIZE(stk_sizes)
1061 || (abs(fmtd->fmt.pix.width - stk_sizes[i-1].w)
1062 < abs(fmtd->fmt.pix.width - stk_sizes[i].w))) {
1063 fmtd->fmt.pix.height = stk_sizes[i-1].h;
1064 fmtd->fmt.pix.width = stk_sizes[i-1].w;
1065 fmtd->fmt.pix.priv = i - 1;
1066 } else {
1067 fmtd->fmt.pix.height = stk_sizes[i].h;
1068 fmtd->fmt.pix.width = stk_sizes[i].w;
1069 fmtd->fmt.pix.priv = i;
1070 }
1071
1072 fmtd->fmt.pix.field = V4L2_FIELD_NONE;
1073 fmtd->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
1074 if (fmtd->fmt.pix.pixelformat == V4L2_PIX_FMT_SBGGR8)
1075 fmtd->fmt.pix.bytesperline = fmtd->fmt.pix.width;
1076 else
1077 fmtd->fmt.pix.bytesperline = 2 * fmtd->fmt.pix.width;
1078 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.bytesperline
1079 * fmtd->fmt.pix.height;
1080 return 0;
1081}
1082
1083static int stk_vidioc_s_fmt_cap(struct file *filp,
1084 void *priv, struct v4l2_format *fmtd)
1085{
1086 int ret;
1087 struct stk_camera *dev = priv;
1088
1089 if (dev == NULL)
1090 return -ENODEV;
1091 if (!is_present(dev))
1092 return -ENODEV;
1093 if (is_streaming(dev))
1094 return -EBUSY;
1095 if (dev->owner && dev->owner != filp)
1096 return -EBUSY;
1097 dev->owner = filp;
1098 ret = stk_vidioc_try_fmt_cap(filp, priv, fmtd);
1099 if (ret)
1100 return ret;
1101
1102 dev->vsettings.palette = fmtd->fmt.pix.pixelformat;
1103 stk_free_buffers(dev);
1104 dev->frame_size = fmtd->fmt.pix.sizeimage;
1105 dev->vsettings.mode = stk_sizes[fmtd->fmt.pix.priv].m;
1106
1107 stk_initialise(dev);
1108 /* This registers controls some timings, not sure of what. */
1109 stk_camera_write_reg(dev, 0x001b, 0x0e);
1110 if (dev->vsettings.mode == MODE_SXGA)
1111 stk_camera_write_reg(dev, 0x001c, 0x0e);
1112 else
1113 stk_camera_write_reg(dev, 0x001c, 0x46);
1114 /*
1115 * Registers 0x0115 0x0114 are the size of each line (bytes),
1116 * regs 0x0117 0x0116 are the heigth of the image.
1117 */
1118 stk_camera_write_reg(dev, 0x0115,
1119 (fmtd->fmt.pix.bytesperline >> 8) & 0xff);
1120 stk_camera_write_reg(dev, 0x0114,
1121 fmtd->fmt.pix.bytesperline & 0xff);
1122 stk_camera_write_reg(dev, 0x0117,
1123 (fmtd->fmt.pix.height >> 8) & 0xff);
1124 stk_camera_write_reg(dev, 0x0116,
1125 fmtd->fmt.pix.height & 0xff);
1126 return stk_sensor_configure(dev);
1127}
1128
1129static int stk_vidioc_reqbufs(struct file *filp,
1130 void *priv, struct v4l2_requestbuffers *rb)
1131{
1132 struct stk_camera *dev = priv;
1133
1134 if (dev == NULL)
1135 return -ENODEV;
1136 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1137 return -EINVAL;
1138 if (rb->memory != V4L2_MEMORY_MMAP)
1139 return -EINVAL;
1140 if (is_streaming(dev)
1141 || (dev->owner && dev->owner != filp))
1142 return -EBUSY;
1143 dev->owner = filp;
1144
1145 /*FIXME If they ask for zero, we must stop streaming and free */
1146 if (rb->count < 3)
1147 rb->count = 3;
1148 /* Arbitrary limit */
1149 else if (rb->count > 5)
1150 rb->count = 5;
1151
1152 stk_allocate_buffers(dev, rb->count);
1153 rb->count = dev->n_sbufs;
1154 return 0;
1155}
1156
1157static int stk_vidioc_querybuf(struct file *filp,
1158 void *priv, struct v4l2_buffer *buf)
1159{
1160 int index;
1161 struct stk_camera *dev = priv;
1162 struct stk_sio_buffer *sbuf;
1163
1164 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1165 return -EINVAL;
1166
1167 index = buf->index;
1168
1169 if (index < 0 || index >= dev->n_sbufs)
1170 return -EINVAL;
1171 sbuf = dev->sio_bufs + buf->index;
1172 *buf = sbuf->v4lbuf;
1173 return 0;
1174}
1175
1176static int stk_vidioc_qbuf(struct file *filp,
1177 void *priv, struct v4l2_buffer *buf)
1178{
1179 struct stk_camera *dev = priv;
1180 struct stk_sio_buffer *sbuf;
1181 unsigned long flags;
1182 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1183 return -EINVAL;
1184
1185 if (buf->memory != V4L2_MEMORY_MMAP)
1186 return -EINVAL;
1187
1188 if (buf->index < 0 || buf->index >= dev->n_sbufs)
1189 return -EINVAL;
1190 sbuf = dev->sio_bufs + buf->index;
1191 if (sbuf->v4lbuf.flags & V4L2_BUF_FLAG_QUEUED)
1192 return 0;
1193 sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_QUEUED;
1194 sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_DONE;
1195 spin_lock_irqsave(&dev->spinlock, flags);
1196 list_add_tail(&sbuf->list, &dev->sio_avail);
1197 *buf = sbuf->v4lbuf;
1198 spin_unlock_irqrestore(&dev->spinlock, flags);
1199 return 0;
1200}
1201
1202static int stk_vidioc_dqbuf(struct file *filp,
1203 void *priv, struct v4l2_buffer *buf)
1204{
1205 struct stk_camera *dev = priv;
1206 struct stk_sio_buffer *sbuf;
1207 unsigned long flags;
1208 int ret;
1209
1210 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE
1211 || !is_streaming(dev))
1212 return -EINVAL;
1213
1214 if (filp->f_flags & O_NONBLOCK && list_empty(&dev->sio_full))
1215 return -EWOULDBLOCK;
1216 ret = wait_event_interruptible(dev->wait_frame,
1217 !list_empty(&dev->sio_full) || !is_present(dev));
1218 if (ret)
1219 return ret;
1220 if (!is_present(dev))
1221 return -EIO;
1222
1223 spin_lock_irqsave(&dev->spinlock, flags);
1224 sbuf = list_first_entry(&dev->sio_full, struct stk_sio_buffer, list);
1225 list_del_init(&sbuf->list);
1226 spin_unlock_irqrestore(&dev->spinlock, flags);
1227 sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_QUEUED;
1228 sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_DONE;
1229 sbuf->v4lbuf.sequence = ++dev->sequence;
1230 do_gettimeofday(&sbuf->v4lbuf.timestamp);
1231
1232 *buf = sbuf->v4lbuf;
1233 return 0;
1234}
1235
1236static int stk_vidioc_streamon(struct file *filp,
1237 void *priv, enum v4l2_buf_type type)
1238{
1239 struct stk_camera *dev = priv;
1240 if (is_streaming(dev))
1241 return 0;
1242 if (dev->sio_bufs == NULL)
1243 return -EINVAL;
1244 dev->sequence = 0;
1245 return stk_start_stream(dev);
1246}
1247
1248static int stk_vidioc_streamoff(struct file *filp,
1249 void *priv, enum v4l2_buf_type type)
1250{
1251 struct stk_camera *dev = priv;
1252 unsigned long flags;
1253 int i;
1254 stk_stop_stream(dev);
1255 spin_lock_irqsave(&dev->spinlock, flags);
1256 INIT_LIST_HEAD(&dev->sio_avail);
1257 INIT_LIST_HEAD(&dev->sio_full);
1258 for (i = 0; i < dev->n_sbufs; i++) {
1259 INIT_LIST_HEAD(&dev->sio_bufs[i].list);
1260 dev->sio_bufs[i].v4lbuf.flags = 0;
1261 }
1262 spin_unlock_irqrestore(&dev->spinlock, flags);
1263 return 0;
1264}
1265
1266
1267static int stk_vidioc_g_parm(struct file *filp,
1268 void *priv, struct v4l2_streamparm *sp)
1269{
1270 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1271 return -EINVAL;
1272
1273 sp->parm.capture.capability = 0;
1274 sp->parm.capture.capturemode = 0;
1275 /*FIXME This is not correct */
1276 sp->parm.capture.timeperframe.numerator = 1;
1277 sp->parm.capture.timeperframe.denominator = 30;
1278 sp->parm.capture.readbuffers = 2;
1279 sp->parm.capture.extendedmode = 0;
1280 return 0;
1281}
1282
1283static struct file_operations v4l_stk_fops = {
1284 .owner = THIS_MODULE,
1285 .open = v4l_stk_open,
1286 .release = v4l_stk_release,
1287 .read = v4l_stk_read,
1288 .poll = v4l_stk_poll,
1289 .mmap = v4l_stk_mmap,
1290 .ioctl = video_ioctl2,
1291 .llseek = no_llseek
1292};
1293
1294static void stk_v4l_dev_release(struct video_device *vd)
1295{
1296}
1297
1298static struct video_device stk_v4l_data = {
1299 .name = "stkwebcam",
1300 .type = VFL_TYPE_GRABBER,
1301 .type2 = VID_TYPE_CAPTURE,
1302 .minor = -1,
1303 .tvnorms = V4L2_STD_UNKNOWN,
1304 .current_norm = V4L2_STD_UNKNOWN,
1305 .fops = &v4l_stk_fops,
1306 .release = stk_v4l_dev_release,
1307
1308 .vidioc_querycap = stk_vidioc_querycap,
1309 .vidioc_enum_fmt_cap = stk_vidioc_enum_fmt_cap,
1310 .vidioc_try_fmt_cap = stk_vidioc_try_fmt_cap,
1311 .vidioc_s_fmt_cap = stk_vidioc_s_fmt_cap,
1312 .vidioc_g_fmt_cap = stk_vidioc_g_fmt_cap,
1313 .vidioc_enum_input = stk_vidioc_enum_input,
1314 .vidioc_s_input = stk_vidioc_s_input,
1315 .vidioc_g_input = stk_vidioc_g_input,
1316 .vidioc_s_std = stk_vidioc_s_std,
1317 .vidioc_reqbufs = stk_vidioc_reqbufs,
1318 .vidioc_querybuf = stk_vidioc_querybuf,
1319 .vidioc_qbuf = stk_vidioc_qbuf,
1320 .vidioc_dqbuf = stk_vidioc_dqbuf,
1321 .vidioc_streamon = stk_vidioc_streamon,
1322 .vidioc_streamoff = stk_vidioc_streamoff,
1323 .vidioc_queryctrl = stk_vidioc_queryctrl,
1324 .vidioc_g_ctrl = stk_vidioc_g_ctrl,
1325 .vidioc_s_ctrl = stk_vidioc_s_ctrl,
1326 .vidioc_g_parm = stk_vidioc_g_parm,
1327};
1328
1329
1330static int stk_register_video_device(struct stk_camera *dev)
1331{
1332 int err;
1333
1334 dev->vdev = stk_v4l_data;
1335 dev->vdev.debug = debug;
1336 dev->vdev.dev = &dev->interface->dev;
1337 dev->vdev.priv = dev;
1338 err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
1339 if (err)
1340 STK_ERROR("v4l registration failed\n");
1341 else
1342 STK_INFO("Syntek USB2.0 Camera is now controlling video device"
1343 " /dev/video%d\n", dev->vdev.minor);
1344 return err;
1345}
1346
1347
1348/* USB Stuff */
1349
1350static int stk_camera_probe(struct usb_interface *interface,
1351 const struct usb_device_id *id)
1352{
1353 int i;
1354 int err;
1355
1356 struct stk_camera *dev = NULL;
1357 struct usb_device *udev = interface_to_usbdev(interface);
1358 struct usb_host_interface *iface_desc;
1359 struct usb_endpoint_descriptor *endpoint;
1360
1361 dev = kzalloc(sizeof(struct stk_camera), GFP_KERNEL);
1362 if (dev == NULL) {
1363 STK_ERROR("Out of memory !\n");
1364 return -ENOMEM;
1365 }
1366
1367 kref_init(&dev->kref);
1368 spin_lock_init(&dev->spinlock);
1369 init_waitqueue_head(&dev->wait_frame);
1370
1371 dev->udev = udev;
1372 dev->interface = interface;
1373 usb_get_intf(interface);
1374
1375 dev->vsettings.vflip = vflip;
1376 dev->vsettings.hflip = hflip;
1377 dev->n_sbufs = 0;
1378 set_present(dev);
1379
1380 /* Set up the endpoint information
1381 * use only the first isoc-in endpoint
1382 * for the current alternate setting */
1383 iface_desc = interface->cur_altsetting;
1384
1385 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1386 endpoint = &iface_desc->endpoint[i].desc;
1387
1388 if (!dev->isoc_ep
1389 && ((endpoint->bEndpointAddress
1390 & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
1391 && ((endpoint->bmAttributes
1392 & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC)) {
1393 /* we found an isoc in endpoint */
1394 dev->isoc_ep = (endpoint->bEndpointAddress & 0xF);
1395 break;
1396 }
1397 }
1398 if (!dev->isoc_ep) {
1399 STK_ERROR("Could not find isoc-in endpoint");
1400 kref_put(&dev->kref, stk_camera_cleanup);
1401 return -ENODEV;
1402 }
1403 dev->vsettings.brightness = 0x7fff;
1404 dev->vsettings.palette = V4L2_PIX_FMT_RGB565;
1405 dev->vsettings.mode = MODE_VGA;
1406 dev->frame_size = 640*480*2;
1407
1408 INIT_LIST_HEAD(&dev->sio_avail);
1409 INIT_LIST_HEAD(&dev->sio_full);
1410
1411 usb_set_intfdata(interface, dev);
1412
1413 err = stk_register_video_device(dev);
1414 if (err) {
1415 kref_put(&dev->kref, stk_camera_cleanup);
1416 return err;
1417 }
1418
1419 stk_create_sysfs_files(&dev->vdev);
1420
1421 return 0;
1422}
1423
1424static void stk_camera_disconnect(struct usb_interface *interface)
1425{
1426 struct stk_camera *dev = usb_get_intfdata(interface);
1427
1428 usb_set_intfdata(interface, NULL);
1429 unset_present(dev);
1430
1431 wake_up_interruptible(&dev->wait_frame);
1432 stk_remove_sysfs_files(&dev->vdev);
1433
1434 kref_put(&dev->kref, stk_camera_cleanup);
1435}
1436
1437static struct usb_driver stk_camera_driver = {
1438 .name = "stkwebcam",
1439 .probe = stk_camera_probe,
1440 .disconnect = stk_camera_disconnect,
1441 .id_table = stkwebcam_table,
1442};
1443
1444
1445static int __init stk_camera_init(void)
1446{
1447 int result;
1448
1449 result = usb_register(&stk_camera_driver);
1450 if (result)
1451 STK_ERROR("usb_register failed ! Error number %d\n", result);
1452
1453
1454 return result;
1455}
1456
1457static void __exit stk_camera_exit(void)
1458{
1459 usb_deregister(&stk_camera_driver);
1460}
1461
1462module_init(stk_camera_init);
1463module_exit(stk_camera_exit);
1464
1465
diff --git a/drivers/media/video/stk-webcam.h b/drivers/media/video/stk-webcam.h
new file mode 100644
index 000000000000..7e989d1ac1e0
--- /dev/null
+++ b/drivers/media/video/stk-webcam.h
@@ -0,0 +1,138 @@
1/*
2 * stk-webcam.h : Driver for Syntek 1125 USB webcam controller
3 *
4 * Copyright (C) 2006 Nicolas VIVIEN
5 * Copyright 2007-2008 Jaime Velasco Juan <jsagarribay@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef STKWEBCAM_H
23#define STKWEBCAM_H
24
25#include <linux/usb.h>
26#include <media/v4l2-common.h>
27
28#define DRIVER_VERSION "v0.0.1"
29#define DRIVER_VERSION_NUM 0x000001
30
31#define MAX_ISO_BUFS 3
32#define ISO_FRAMES_PER_DESC 16
33#define ISO_MAX_FRAME_SIZE 3 * 1024
34#define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
35
36
37#define PREFIX "stkwebcam: "
38#define STK_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args)
39#define STK_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args)
40#define STK_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args)
41
42struct stk_iso_buf {
43 void *data;
44 int length;
45 int read;
46 struct urb *urb;
47};
48
49/* Streaming IO buffers */
50struct stk_sio_buffer {
51 struct v4l2_buffer v4lbuf;
52 char *buffer;
53 int mapcount;
54 struct stk_camera *dev;
55 struct list_head list;
56};
57
58enum stk_mode {MODE_VGA, MODE_SXGA, MODE_CIF, MODE_QVGA, MODE_QCIF};
59
60struct stk_video {
61 enum stk_mode mode;
62 int brightness;
63 __u32 palette;
64 int hflip;
65 int vflip;
66};
67
68enum stk_status {
69 S_PRESENT = 1,
70 S_INITIALISED = 2,
71 S_MEMALLOCD = 4,
72 S_STREAMING = 8,
73};
74#define is_present(dev) ((dev)->status & S_PRESENT)
75#define is_initialised(dev) ((dev)->status & S_INITIALISED)
76#define is_streaming(dev) ((dev)->status & S_STREAMING)
77#define is_memallocd(dev) ((dev)->status & S_MEMALLOCD)
78#define set_present(dev) ((dev)->status = S_PRESENT)
79#define unset_present(dev) ((dev)->status &= \
80 ~(S_PRESENT|S_INITIALISED|S_STREAMING))
81#define set_initialised(dev) ((dev)->status |= S_INITIALISED)
82#define set_memallocd(dev) ((dev)->status |= S_MEMALLOCD)
83#define unset_memallocd(dev) ((dev)->status &= ~S_MEMALLOCD)
84#define set_streaming(dev) ((dev)->status |= S_STREAMING)
85#define unset_streaming(dev) ((dev)->status &= ~S_STREAMING)
86
87struct regval {
88 unsigned reg;
89 unsigned val;
90};
91
92struct stk_camera {
93 struct video_device vdev;
94 struct usb_device *udev;
95 struct usb_interface *interface;
96 int webcam_model;
97 struct file *owner;
98
99 u8 isoc_ep;
100
101 struct kref kref;
102 /* Not sure if this is right */
103 atomic_t urbs_used;
104
105 struct stk_video vsettings;
106
107 enum stk_status status;
108
109 spinlock_t spinlock;
110 wait_queue_head_t wait_frame;
111
112 struct stk_iso_buf *isobufs;
113
114 int frame_size;
115 /* Streaming buffers */
116 unsigned int n_sbufs;
117 struct stk_sio_buffer *sio_bufs;
118 struct list_head sio_avail;
119 struct list_head sio_full;
120 unsigned sequence;
121};
122
123#define to_stk_camera(d) container_of(d, struct stk_camera, kref)
124#define vdev_to_camera(d) container_of(d, struct stk_camera, vdev)
125
126void stk_camera_delete(struct kref *);
127int stk_camera_write_reg(struct stk_camera *, u16, u8);
128int stk_camera_read_reg(struct stk_camera *, u16, int *);
129
130int stk_sensor_outb(struct stk_camera *dev, u8 reg, u8 val);
131int stk_sensor_inb(struct stk_camera *dev, u8 reg, u8 *val);
132int stk_sensor_init(struct stk_camera *);
133int stk_sensor_configure(struct stk_camera *);
134int stk_sensor_sleep(struct stk_camera *dev);
135int stk_sensor_wakeup(struct stk_camera *dev);
136int stk_sensor_set_brightness(struct stk_camera *dev, int br);
137
138#endif
diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c
index 43225802a551..b4d10f7a4e57 100644
--- a/drivers/media/video/tda7432.c
+++ b/drivers/media/video/tda7432.c
@@ -8,6 +8,7 @@
8 * Muting and tone control by Jonathan Isom <jisom@ematic.com> 8 * Muting and tone control by Jonathan Isom <jisom@ematic.com>
9 * 9 *
10 * Copyright (c) 2000 Eric Sandeen <eric_sandeen@bigfoot.com> 10 * Copyright (c) 2000 Eric Sandeen <eric_sandeen@bigfoot.com>
11 * Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
11 * This code is placed under the terms of the GNU General Public License 12 * This code is placed under the terms of the GNU General Public License
12 * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu) 13 * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu)
13 * Which was based on tda8425.c by Greg Alexander (c) 1998 14 * Which was based on tda8425.c by Greg Alexander (c) 1998
@@ -276,7 +277,7 @@ static void do_tda7432_init(struct i2c_client *client)
276 t->volume = 0x3b ; /* -27dB Volume */ 277 t->volume = 0x3b ; /* -27dB Volume */
277 if (loudness) /* Turn loudness on? */ 278 if (loudness) /* Turn loudness on? */
278 t->volume |= TDA7432_LD_ON; 279 t->volume |= TDA7432_LD_ON;
279 t->muted = VIDEO_AUDIO_MUTE; 280 t->muted = 1;
280 t->treble = TDA7432_TREBLE_0DB; /* 0dB Treble */ 281 t->treble = TDA7432_TREBLE_0DB; /* 0dB Treble */
281 t->bass = TDA7432_BASS_0DB; /* 0dB Bass */ 282 t->bass = TDA7432_BASS_0DB; /* 0dB Bass */
282 t->lf = TDA7432_ATTEN_0DB; /* 0dB attenuation */ 283 t->lf = TDA7432_ATTEN_0DB; /* 0dB attenuation */
@@ -332,151 +333,160 @@ static int tda7432_detach(struct i2c_client *client)
332 return 0; 333 return 0;
333} 334}
334 335
335static int tda7432_command(struct i2c_client *client, 336static int tda7432_get_ctrl(struct i2c_client *client,
336 unsigned int cmd, void *arg) 337 struct v4l2_control *ctrl)
337{ 338{
338 struct tda7432 *t = i2c_get_clientdata(client); 339 struct tda7432 *t = i2c_get_clientdata(client);
339 v4l_dbg(2, debug,client,"In tda7432_command\n");
340 if (debug>1)
341 v4l_i2c_print_ioctl(client,cmd);
342 340
343 switch (cmd) { 341 switch (ctrl->id) {
344 /* --- v4l ioctls --- */ 342 case V4L2_CID_AUDIO_MUTE:
345 /* take care: bttv does userspace copying, we'll get a 343 ctrl->value=t->muted;
346 kernel pointer here... */ 344 return 0;
347 345 case V4L2_CID_AUDIO_VOLUME:
348 /* Query card - scale from TDA7432 settings to V4L settings */
349 case VIDIOCGAUDIO:
350 {
351 struct video_audio *va = arg;
352
353 va->flags |= VIDEO_AUDIO_VOLUME |
354 VIDEO_AUDIO_BASS |
355 VIDEO_AUDIO_TREBLE |
356 VIDEO_AUDIO_MUTABLE;
357 if (t->muted)
358 va->flags |= VIDEO_AUDIO_MUTE;
359 va->mode |= VIDEO_SOUND_STEREO;
360 /* Master volume control
361 * V4L volume is min 0, max 65535
362 * TDA7432 Volume:
363 * Min (-79dB) is 0x6f
364 * Max (+20dB) is 0x07 (630)
365 * Max (0dB) is 0x20 (829)
366 * (Mask out bit 7 of vol - it's for the loudness setting)
367 */
368 if (!maxvol){ /* max +20db */ 346 if (!maxvol){ /* max +20db */
369 va->volume = ( 0x6f - (t->volume & 0x7F) ) * 630; 347 ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 630;
370 } else { /* max 0db */ 348 } else { /* max 0db */
371 va->volume = ( 0x6f - (t->volume & 0x7F) ) * 829; 349 ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 829;
372 } 350 }
373 351 return 0;
374 /* Balance depends on L,R attenuation 352 case V4L2_CID_AUDIO_BALANCE:
375 * V4L balance is 0 to 65535, middle is 32768 353 {
376 * TDA7432 attenuation: min (0dB) is 0, max (-37.5dB) is 0x1f
377 * to scale up to V4L numbers, mult by 1057
378 * attenuation exists for lf, lr, rf, rr
379 * we use only lf and rf (front channels)
380 */
381
382 if ( (t->lf) < (t->rf) ) 354 if ( (t->lf) < (t->rf) )
383 /* right is attenuated, balance shifted left */ 355 /* right is attenuated, balance shifted left */
384 va->balance = (32768 - 1057*(t->rf)); 356 ctrl->value = (32768 - 1057*(t->rf));
385 else 357 else
386 /* left is attenuated, balance shifted right */ 358 /* left is attenuated, balance shifted right */
387 va->balance = (32768 + 1057*(t->lf)); 359 ctrl->value = (32768 + 1057*(t->lf));
388 360 return 0;
361 }
362 case V4L2_CID_AUDIO_BASS:
363 {
389 /* Bass/treble 4 bits each */ 364 /* Bass/treble 4 bits each */
390 va->bass=t->bass; 365 int bass=t->bass;
391 if(va->bass >= 0x8) 366 if(bass >= 0x8)
392 va->bass = ~(va->bass - 0x8) & 0xf; 367 bass = ~(bass - 0x8) & 0xf;
393 va->bass = (va->bass << 12)+(va->bass << 8)+(va->bass << 4)+(va->bass); 368 ctrl->value = (bass << 12)+(bass << 8)+(bass << 4)+(bass);
394 va->treble=t->treble; 369 return 0;
395 if(va->treble >= 0x8)
396 va->treble = ~(va->treble - 0x8) & 0xf;
397 va->treble = (va->treble << 12)+(va->treble << 8)+(va->treble << 4)+(va->treble);
398
399 break; /* VIDIOCGAUDIO case */
400 } 370 }
401 371 case V4L2_CID_AUDIO_TREBLE:
402 /* Set card - scale from V4L settings to TDA7432 settings */
403 case VIDIOCSAUDIO:
404 { 372 {
405 struct video_audio *va = arg; 373 int treble=t->treble;
374 if(treble >= 0x8)
375 treble = ~(treble - 0x8) & 0xf;
376 ctrl->value = (treble << 12)+(treble << 8)+(treble << 4)+(treble);
377 return 0;
378 }
379 }
380 return -EINVAL;
381}
406 382
407 if(va->flags & VIDEO_AUDIO_VOLUME){ 383static int tda7432_set_ctrl(struct i2c_client *client,
408 if(!maxvol){ /* max +20db */ 384 struct v4l2_control *ctrl)
409 t->volume = 0x6f - ((va->volume)/630); 385{
410 } else { /* max 0db */ 386 struct tda7432 *t = i2c_get_clientdata(client);
411 t->volume = 0x6f - ((va->volume)/829);
412 }
413 387
388 switch (ctrl->id) {
389 case V4L2_CID_AUDIO_MUTE:
390 t->muted=ctrl->value;
391 break;
392 case V4L2_CID_AUDIO_VOLUME:
393 if(!maxvol){ /* max +20db */
394 t->volume = 0x6f - ((ctrl->value)/630);
395 } else { /* max 0db */
396 t->volume = 0x6f - ((ctrl->value)/829);
397 }
414 if (loudness) /* Turn on the loudness bit */ 398 if (loudness) /* Turn on the loudness bit */
415 t->volume |= TDA7432_LD_ON; 399 t->volume |= TDA7432_LD_ON;
416 400
417 tda7432_write(client,TDA7432_VL, t->volume); 401 tda7432_write(client,TDA7432_VL, t->volume);
418 } 402 return 0;
419 403 case V4L2_CID_AUDIO_BALANCE:
420 if(va->flags & VIDEO_AUDIO_BASS) 404 if (ctrl->value < 32768) {
421 {
422 t->bass = va->bass >> 12;
423 if(t->bass>= 0x8)
424 t->bass = (~t->bass & 0xf) + 0x8 ;
425 }
426 if(va->flags & VIDEO_AUDIO_TREBLE)
427 {
428 t->treble= va->treble >> 12;
429 if(t->treble>= 0x8)
430 t->treble = (~t->treble & 0xf) + 0x8 ;
431 }
432 if(va->flags & (VIDEO_AUDIO_TREBLE| VIDEO_AUDIO_BASS))
433 tda7432_write(client,TDA7432_TN, 0x10 | (t->bass << 4) | t->treble );
434
435 if(va->flags & VIDEO_AUDIO_BALANCE) {
436 if (va->balance < 32768)
437 {
438 /* shifted to left, attenuate right */ 405 /* shifted to left, attenuate right */
439 t->rr = (32768 - va->balance)/1057; 406 t->rr = (32768 - ctrl->value)/1057;
440 t->rf = t->rr; 407 t->rf = t->rr;
441 t->lr = TDA7432_ATTEN_0DB; 408 t->lr = TDA7432_ATTEN_0DB;
442 t->lf = TDA7432_ATTEN_0DB; 409 t->lf = TDA7432_ATTEN_0DB;
443 } 410 } else if(ctrl->value > 32769) {
444 else if(va->balance > 32769)
445 {
446 /* shifted to right, attenuate left */ 411 /* shifted to right, attenuate left */
447 t->lf = (va->balance - 32768)/1057; 412 t->lf = (ctrl->value - 32768)/1057;
448 t->lr = t->lf; 413 t->lr = t->lf;
449 t->rr = TDA7432_ATTEN_0DB; 414 t->rr = TDA7432_ATTEN_0DB;
450 t->rf = TDA7432_ATTEN_0DB; 415 t->rf = TDA7432_ATTEN_0DB;
451 } 416 } else {
452 else
453 {
454 /* centered */ 417 /* centered */
455 t->rr = TDA7432_ATTEN_0DB; 418 t->rr = TDA7432_ATTEN_0DB;
456 t->rf = TDA7432_ATTEN_0DB; 419 t->rf = TDA7432_ATTEN_0DB;
457 t->lf = TDA7432_ATTEN_0DB; 420 t->lf = TDA7432_ATTEN_0DB;
458 t->lr = TDA7432_ATTEN_0DB; 421 t->lr = TDA7432_ATTEN_0DB;
459 } 422 }
460 } 423 break;
424 case V4L2_CID_AUDIO_BASS:
425 t->bass = ctrl->value >> 12;
426 if(t->bass>= 0x8)
427 t->bass = (~t->bass & 0xf) + 0x8 ;
428
429 tda7432_write(client,TDA7432_TN, 0x10 | (t->bass << 4) | t->treble );
430 return 0;
431 case V4L2_CID_AUDIO_TREBLE:
432 t->treble= ctrl->value >> 12;
433 if(t->treble>= 0x8)
434 t->treble = (~t->treble & 0xf) + 0x8 ;
435
436 tda7432_write(client,TDA7432_TN, 0x10 | (t->bass << 4) | t->treble );
437 return 0;
438 default:
439 return -EINVAL;
440 }
461 441
462 t->muted=(va->flags & VIDEO_AUDIO_MUTE); 442 /* Used for both mute and balance changes */
463 if (t->muted) 443 if (t->muted)
464 { 444 {
465 /* Mute & update balance*/ 445 /* Mute & update balance*/
466 tda7432_write(client,TDA7432_LF, t->lf | TDA7432_MUTE); 446 tda7432_write(client,TDA7432_LF, t->lf | TDA7432_MUTE);
467 tda7432_write(client,TDA7432_LR, t->lr | TDA7432_MUTE); 447 tda7432_write(client,TDA7432_LR, t->lr | TDA7432_MUTE);
468 tda7432_write(client,TDA7432_RF, t->rf | TDA7432_MUTE); 448 tda7432_write(client,TDA7432_RF, t->rf | TDA7432_MUTE);
469 tda7432_write(client,TDA7432_RR, t->rr | TDA7432_MUTE); 449 tda7432_write(client,TDA7432_RR, t->rr | TDA7432_MUTE);
470 } else { 450 } else {
471 tda7432_write(client,TDA7432_LF, t->lf); 451 tda7432_write(client,TDA7432_LF, t->lf);
472 tda7432_write(client,TDA7432_LR, t->lr); 452 tda7432_write(client,TDA7432_LR, t->lr);
473 tda7432_write(client,TDA7432_RF, t->rf); 453 tda7432_write(client,TDA7432_RF, t->rf);
474 tda7432_write(client,TDA7432_RR, t->rr); 454 tda7432_write(client,TDA7432_RR, t->rr);
475 } 455 }
456 return 0;
457}
476 458
477 break; 459static int tda7432_command(struct i2c_client *client,
460 unsigned int cmd, void *arg)
461{
462 v4l_dbg(2, debug,client,"In tda7432_command\n");
463 if (debug>1)
464 v4l_i2c_print_ioctl(client,cmd);
465
466 switch (cmd) {
467 /* --- v4l ioctls --- */
468 /* take care: bttv does userspace copying, we'll get a
469 kernel pointer here... */
470 case VIDIOC_QUERYCTRL:
471 {
472 struct v4l2_queryctrl *qc = arg;
473
474 switch (qc->id) {
475 case V4L2_CID_AUDIO_MUTE:
476 case V4L2_CID_AUDIO_VOLUME:
477 case V4L2_CID_AUDIO_BALANCE:
478 case V4L2_CID_AUDIO_BASS:
479 case V4L2_CID_AUDIO_TREBLE:
480 default:
481 return -EINVAL;
482 }
483 return v4l2_ctrl_query_fill_std(qc);
484 }
485 case VIDIOC_S_CTRL:
486 return tda7432_set_ctrl(client, arg);
478 487
479 } /* end of VIDEOCSAUDIO case */ 488 case VIDIOC_G_CTRL:
489 return tda7432_get_ctrl(client, arg);
480 490
481 } /* end of (cmd) switch */ 491 } /* end of (cmd) switch */
482 492
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index 0e5cf459d3ed..55bc89a6f069 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -25,12 +25,14 @@
25#include <linux/videodev.h> 25#include <linux/videodev.h>
26#include "tuner-i2c.h" 26#include "tuner-i2c.h"
27#include "tda8290.h" 27#include "tda8290.h"
28#include "tda827x.h"
29#include "tda18271.h"
28 30
29static int debug = 0; 31static int debug;
30module_param(debug, int, 0644); 32module_param(debug, int, 0644);
31MODULE_PARM_DESC(debug, "enable verbose debug messages"); 33MODULE_PARM_DESC(debug, "enable verbose debug messages");
32 34
33#define PREFIX "tda8290 " 35#define PREFIX "tda8290"
34 36
35/* ---------------------------------------------------------------------- */ 37/* ---------------------------------------------------------------------- */
36 38
@@ -38,345 +40,71 @@ struct tda8290_priv {
38 struct tuner_i2c_props i2c_props; 40 struct tuner_i2c_props i2c_props;
39 41
40 unsigned char tda8290_easy_mode; 42 unsigned char tda8290_easy_mode;
41 unsigned char tda827x_lpsel;
42 unsigned char tda827x_addr;
43 unsigned char tda827x_ver;
44 unsigned int sgIF;
45
46 u32 frequency;
47
48 unsigned int *lna_cfg;
49 int (*tuner_callback) (void *dev, int command,int arg);
50};
51
52/* ---------------------------------------------------------------------- */
53
54struct tda827x_data {
55 u32 lomax;
56 u8 spd;
57 u8 bs;
58 u8 bp;
59 u8 cp;
60 u8 gc3;
61 u8 div1p5;
62};
63
64 /* Note lomax entry is lo / 62500 */
65
66static struct tda827x_data tda827x_analog[] = {
67 { .lomax = 992, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 62 MHz */
68 { .lomax = 1056, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 66 MHz */
69 { .lomax = 1216, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 76 MHz */
70 { .lomax = 1344, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 84 MHz */
71 { .lomax = 1488, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 93 MHz */
72 { .lomax = 1568, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 98 MHz */
73 { .lomax = 1744, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 109 MHz */
74 { .lomax = 1968, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 123 MHz */
75 { .lomax = 2128, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 133 MHz */
76 { .lomax = 2416, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 151 MHz */
77 { .lomax = 2464, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 154 MHz */
78 { .lomax = 2896, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 181 MHz */
79 { .lomax = 2960, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 185 MHz */
80 { .lomax = 3472, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 217 MHz */
81 { .lomax = 3904, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 244 MHz */
82 { .lomax = 4240, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 265 MHz */
83 { .lomax = 4832, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 302 MHz */
84 { .lomax = 5184, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 324 MHz */
85 { .lomax = 5920, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 370 MHz */
86 { .lomax = 7264, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 454 MHz */
87 { .lomax = 7888, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 493 MHz */
88 { .lomax = 8480, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 530 MHz */
89 { .lomax = 8864, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 554 MHz */
90 { .lomax = 9664, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 604 MHz */
91 { .lomax = 11088, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 696 MHz */
92 { .lomax = 11840, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 740 MHz */
93 { .lomax = 13120, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 820 MHz */
94 { .lomax = 13840, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 865 MHz */
95 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} /* End */
96};
97
98static void tda827x_set_analog_params(struct dvb_frontend *fe,
99 struct analog_parameters *params)
100{
101 unsigned char tuner_reg[8];
102 unsigned char reg2[2];
103 u32 N;
104 int i;
105 struct tda8290_priv *priv = fe->tuner_priv;
106 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0};
107 unsigned int freq = params->frequency;
108
109 if (params->mode == V4L2_TUNER_RADIO)
110 freq = freq / 1000;
111
112 N = freq + priv->sgIF;
113 i = 0;
114 while (tda827x_analog[i].lomax < N) {
115 if(tda827x_analog[i + 1].lomax == 0)
116 break;
117 i++;
118 }
119
120 N = N << tda827x_analog[i].spd;
121
122 tuner_reg[0] = 0;
123 tuner_reg[1] = (unsigned char)(N>>8);
124 tuner_reg[2] = (unsigned char) N;
125 tuner_reg[3] = 0x40;
126 tuner_reg[4] = 0x52 + (priv->tda827x_lpsel << 5);
127 tuner_reg[5] = (tda827x_analog[i].spd << 6) + (tda827x_analog[i].div1p5 <<5) +
128 (tda827x_analog[i].bs <<3) + tda827x_analog[i].bp;
129 tuner_reg[6] = 0x8f + (tda827x_analog[i].gc3 << 4);
130 tuner_reg[7] = 0x8f;
131
132 msg.buf = tuner_reg;
133 msg.len = 8;
134 i2c_transfer(priv->i2c_props.adap, &msg, 1);
135
136 msg.buf= reg2;
137 msg.len = 2;
138 reg2[0] = 0x80;
139 reg2[1] = 0;
140 i2c_transfer(priv->i2c_props.adap, &msg, 1);
141
142 reg2[0] = 0x60;
143 reg2[1] = 0xbf;
144 i2c_transfer(priv->i2c_props.adap, &msg, 1);
145
146 reg2[0] = 0x30;
147 reg2[1] = tuner_reg[4] + 0x80;
148 i2c_transfer(priv->i2c_props.adap, &msg, 1);
149
150 msleep(1);
151 reg2[0] = 0x30;
152 reg2[1] = tuner_reg[4] + 4;
153 i2c_transfer(priv->i2c_props.adap, &msg, 1);
154
155 msleep(1);
156 reg2[0] = 0x30;
157 reg2[1] = tuner_reg[4];
158 i2c_transfer(priv->i2c_props.adap, &msg, 1);
159
160 msleep(550);
161 reg2[0] = 0x30;
162 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_analog[i].cp ;
163 i2c_transfer(priv->i2c_props.adap, &msg, 1);
164
165 reg2[0] = 0x60;
166 reg2[1] = 0x3f;
167 i2c_transfer(priv->i2c_props.adap, &msg, 1);
168
169 reg2[0] = 0x80;
170 reg2[1] = 0x08; // Vsync en
171 i2c_transfer(priv->i2c_props.adap, &msg, 1);
172}
173 43
174static void tda827x_agcf(struct dvb_frontend *fe) 44 unsigned char tda827x_addr;
175{
176 struct tda8290_priv *priv = fe->tuner_priv;
177 unsigned char data[] = {0x80, 0x0c};
178 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
179 .flags = 0, .len = 2};
180 i2c_transfer(priv->i2c_props.adap, &msg, 1);
181}
182
183/* ---------------------------------------------------------------------- */
184 45
185struct tda827xa_data { 46 unsigned char ver;
186 u32 lomax; 47#define TDA8290 1
187 u8 svco; 48#define TDA8295 2
188 u8 spd; 49#define TDA8275 4
189 u8 scr; 50#define TDA8275A 8
190 u8 sbs; 51#define TDA18271 16
191 u8 gc3;
192};
193 52
194static struct tda827xa_data tda827xa_analog[] = { 53 struct tda827x_config cfg;
195 { .lomax = 910, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3}, /* 56.875 MHz */
196 { .lomax = 1076, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 67.25 MHz */
197 { .lomax = 1300, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 81.25 MHz */
198 { .lomax = 1560, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 97.5 MHz */
199 { .lomax = 1820, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1}, /* 113.75 MHz */
200 { .lomax = 2152, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 134.5 MHz */
201 { .lomax = 2464, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 154 MHz */
202 { .lomax = 2600, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 162.5 MHz */
203 { .lomax = 2928, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 183 MHz */
204 { .lomax = 3120, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1}, /* 195 MHz */
205 { .lomax = 3640, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3}, /* 227.5 MHz */
206 { .lomax = 4304, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3}, /* 269 MHz */
207 { .lomax = 5200, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1}, /* 325 MHz */
208 { .lomax = 6240, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 390 MHz */
209 { .lomax = 7280, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 455 MHz */
210 { .lomax = 8320, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 520 MHz */
211 { .lomax = 8608, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1}, /* 538 MHz */
212 { .lomax = 8864, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 554 MHz */
213 { .lomax = 9920, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 620 MHz */
214 { .lomax = 10400, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 650 MHz */
215 { .lomax = 11200, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 700 MHz */
216 { .lomax = 12480, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 780 MHz */
217 { .lomax = 13120, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 820 MHz */
218 { .lomax = 13920, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 870 MHz */
219 { .lomax = 14576, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0}, /* 911 MHz */
220 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */
221}; 54};
222 55
223static void tda827xa_lna_gain(struct dvb_frontend *fe, int high, 56/*---------------------------------------------------------------------*/
224 struct analog_parameters *params)
225{
226 struct tda8290_priv *priv = fe->tuner_priv;
227 unsigned char buf[] = {0x22, 0x01};
228 int arg;
229 struct i2c_msg msg = {.addr = priv->i2c_props.addr, .flags = 0, .buf = buf, .len = sizeof(buf)};
230
231 if ((priv->lna_cfg == NULL) || (priv->tuner_callback == NULL))
232 return;
233
234 if (*priv->lna_cfg) {
235 if (high)
236 tuner_dbg("setting LNA to high gain\n");
237 else
238 tuner_dbg("setting LNA to low gain\n");
239 }
240 switch (*priv->lna_cfg) {
241 case 0: /* no LNA */
242 break;
243 case 1: /* switch is GPIO 0 of tda8290 */
244 case 2:
245 /* turn Vsync on */
246 if (params->std & V4L2_STD_MN)
247 arg = 1;
248 else
249 arg = 0;
250 if (priv->tuner_callback)
251 priv->tuner_callback(priv->i2c_props.adap->algo_data, 1, arg);
252 buf[1] = high ? 0 : 1;
253 if (*priv->lna_cfg == 2)
254 buf[1] = high ? 1 : 0;
255 i2c_transfer(priv->i2c_props.adap, &msg, 1);
256 break;
257 case 3: /* switch with GPIO of saa713x */
258 if (priv->tuner_callback)
259 priv->tuner_callback(priv->i2c_props.adap->algo_data, 0, high);
260 break;
261 }
262}
263 57
264static void tda827xa_set_analog_params(struct dvb_frontend *fe, 58static int tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
265 struct analog_parameters *params)
266{ 59{
267 unsigned char tuner_reg[11]; 60 struct tda8290_priv *priv = fe->analog_demod_priv;
268 u32 N;
269 int i;
270 struct tda8290_priv *priv = fe->tuner_priv;
271 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0, .buf = tuner_reg};
272 unsigned int freq = params->frequency;
273 61
274 tda827xa_lna_gain(fe, 1, params); 62 unsigned char enable[2] = { 0x21, 0xC0 };
275 msleep(10); 63 unsigned char disable[2] = { 0x21, 0x00 };
276 64 unsigned char *msg;
277 if (params->mode == V4L2_TUNER_RADIO)
278 freq = freq / 1000;
279 65
280 N = freq + priv->sgIF; 66 if (close) {
281 i = 0; 67 msg = enable;
282 while (tda827xa_analog[i].lomax < N) { 68 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
283 if(tda827xa_analog[i + 1].lomax == 0) 69 /* let the bridge stabilize */
284 break; 70 msleep(20);
285 i++; 71 } else {
72 msg = disable;
73 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
286 } 74 }
287 75
288 N = N << tda827xa_analog[i].spd; 76 return 0;
289
290 tuner_reg[0] = 0;
291 tuner_reg[1] = (unsigned char)(N>>8);
292 tuner_reg[2] = (unsigned char) N;
293 tuner_reg[3] = 0;
294 tuner_reg[4] = 0x16;
295 tuner_reg[5] = (tda827xa_analog[i].spd << 5) + (tda827xa_analog[i].svco << 3) +
296 tda827xa_analog[i].sbs;
297 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
298 tuner_reg[7] = 0x1c;
299 tuner_reg[8] = 4;
300 tuner_reg[9] = 0x20;
301 tuner_reg[10] = 0x00;
302 msg.len = 11;
303 i2c_transfer(priv->i2c_props.adap, &msg, 1);
304
305 tuner_reg[0] = 0x90;
306 tuner_reg[1] = 0xff;
307 tuner_reg[2] = 0xe0;
308 tuner_reg[3] = 0;
309 tuner_reg[4] = 0x99 + (priv->tda827x_lpsel << 1);
310 msg.len = 5;
311 i2c_transfer(priv->i2c_props.adap, &msg, 1);
312
313 tuner_reg[0] = 0xa0;
314 tuner_reg[1] = 0xc0;
315 msg.len = 2;
316 i2c_transfer(priv->i2c_props.adap, &msg, 1);
317
318 tuner_reg[0] = 0x30;
319 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
320 i2c_transfer(priv->i2c_props.adap, &msg, 1);
321
322 msg.flags = I2C_M_RD;
323 i2c_transfer(priv->i2c_props.adap, &msg, 1);
324 msg.flags = 0;
325 tuner_reg[1] >>= 4;
326 tuner_dbg("AGC2 gain is: %d\n", tuner_reg[1]);
327 if (tuner_reg[1] < 1)
328 tda827xa_lna_gain(fe, 0, params);
329
330 msleep(100);
331 tuner_reg[0] = 0x60;
332 tuner_reg[1] = 0x3c;
333 i2c_transfer(priv->i2c_props.adap, &msg, 1);
334
335 msleep(163);
336 tuner_reg[0] = 0x50;
337 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
338 i2c_transfer(priv->i2c_props.adap, &msg, 1);
339
340 tuner_reg[0] = 0x80;
341 tuner_reg[1] = 0x28;
342 i2c_transfer(priv->i2c_props.adap, &msg, 1);
343
344 tuner_reg[0] = 0xb0;
345 tuner_reg[1] = 0x01;
346 i2c_transfer(priv->i2c_props.adap, &msg, 1);
347
348 tuner_reg[0] = 0xc0;
349 tuner_reg[1] = 0x19 + (priv->tda827x_lpsel << 1);
350 i2c_transfer(priv->i2c_props.adap, &msg, 1);
351}
352
353static void tda827xa_agcf(struct dvb_frontend *fe)
354{
355 struct tda8290_priv *priv = fe->tuner_priv;
356 unsigned char data[] = {0x80, 0x2c};
357 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
358 .flags = 0, .len = 2};
359 i2c_transfer(priv->i2c_props.adap, &msg, 1);
360} 77}
361 78
362/*---------------------------------------------------------------------*/ 79static int tda8295_i2c_bridge(struct dvb_frontend *fe, int close)
363
364static void tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
365{ 80{
366 struct tda8290_priv *priv = fe->tuner_priv; 81 struct tda8290_priv *priv = fe->analog_demod_priv;
367 82
368 unsigned char enable[2] = { 0x21, 0xC0 }; 83 unsigned char enable[2] = { 0x45, 0xc1 };
369 unsigned char disable[2] = { 0x21, 0x00 }; 84 unsigned char disable[2] = { 0x46, 0x00 };
85 unsigned char buf[3] = { 0x45, 0x01, 0x00 };
370 unsigned char *msg; 86 unsigned char *msg;
371 if(close) { 87
88 if (close) {
372 msg = enable; 89 msg = enable;
373 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); 90 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
374 /* let the bridge stabilize */ 91 /* let the bridge stabilize */
375 msleep(20); 92 msleep(20);
376 } else { 93 } else {
377 msg = disable; 94 msg = disable;
95 tuner_i2c_xfer_send(&priv->i2c_props, msg, 1);
96 tuner_i2c_xfer_recv(&priv->i2c_props, &msg[1], 1);
97
98 buf[2] = msg[1];
99 buf[2] &= ~0x04;
100 tuner_i2c_xfer_send(&priv->i2c_props, buf, 3);
101 msleep(5);
102
103 msg[1] |= 0x04;
378 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2); 104 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
379 } 105 }
106
107 return 0;
380} 108}
381 109
382/*---------------------------------------------------------------------*/ 110/*---------------------------------------------------------------------*/
@@ -384,55 +112,43 @@ static void tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
384static void set_audio(struct dvb_frontend *fe, 112static void set_audio(struct dvb_frontend *fe,
385 struct analog_parameters *params) 113 struct analog_parameters *params)
386{ 114{
387 struct tda8290_priv *priv = fe->tuner_priv; 115 struct tda8290_priv *priv = fe->analog_demod_priv;
388 char* mode; 116 char* mode;
389 117
390 priv->tda827x_lpsel = 0;
391 if (params->std & V4L2_STD_MN) { 118 if (params->std & V4L2_STD_MN) {
392 priv->sgIF = 92;
393 priv->tda8290_easy_mode = 0x01; 119 priv->tda8290_easy_mode = 0x01;
394 priv->tda827x_lpsel = 1;
395 mode = "MN"; 120 mode = "MN";
396 } else if (params->std & V4L2_STD_B) { 121 } else if (params->std & V4L2_STD_B) {
397 priv->sgIF = 108;
398 priv->tda8290_easy_mode = 0x02; 122 priv->tda8290_easy_mode = 0x02;
399 mode = "B"; 123 mode = "B";
400 } else if (params->std & V4L2_STD_GH) { 124 } else if (params->std & V4L2_STD_GH) {
401 priv->sgIF = 124;
402 priv->tda8290_easy_mode = 0x04; 125 priv->tda8290_easy_mode = 0x04;
403 mode = "GH"; 126 mode = "GH";
404 } else if (params->std & V4L2_STD_PAL_I) { 127 } else if (params->std & V4L2_STD_PAL_I) {
405 priv->sgIF = 124;
406 priv->tda8290_easy_mode = 0x08; 128 priv->tda8290_easy_mode = 0x08;
407 mode = "I"; 129 mode = "I";
408 } else if (params->std & V4L2_STD_DK) { 130 } else if (params->std & V4L2_STD_DK) {
409 priv->sgIF = 124;
410 priv->tda8290_easy_mode = 0x10; 131 priv->tda8290_easy_mode = 0x10;
411 mode = "DK"; 132 mode = "DK";
412 } else if (params->std & V4L2_STD_SECAM_L) { 133 } else if (params->std & V4L2_STD_SECAM_L) {
413 priv->sgIF = 124;
414 priv->tda8290_easy_mode = 0x20; 134 priv->tda8290_easy_mode = 0x20;
415 mode = "L"; 135 mode = "L";
416 } else if (params->std & V4L2_STD_SECAM_LC) { 136 } else if (params->std & V4L2_STD_SECAM_LC) {
417 priv->sgIF = 20;
418 priv->tda8290_easy_mode = 0x40; 137 priv->tda8290_easy_mode = 0x40;
419 mode = "LC"; 138 mode = "LC";
420 } else { 139 } else {
421 priv->sgIF = 124;
422 priv->tda8290_easy_mode = 0x10; 140 priv->tda8290_easy_mode = 0x10;
423 mode = "xx"; 141 mode = "xx";
424 } 142 }
425 143
426 if (params->mode == V4L2_TUNER_RADIO) 144 tuner_dbg("setting tda829x to system %s\n", mode);
427 priv->sgIF = 88; /* if frequency is 5.5 MHz */
428
429 tuner_dbg("setting tda8290 to system %s\n", mode);
430} 145}
431 146
432static int tda8290_set_params(struct dvb_frontend *fe, 147static void tda8290_set_params(struct dvb_frontend *fe,
433 struct analog_parameters *params) 148 struct analog_parameters *params)
434{ 149{
435 struct tda8290_priv *priv = fe->tuner_priv; 150 struct tda8290_priv *priv = fe->analog_demod_priv;
151
436 unsigned char soft_reset[] = { 0x00, 0x00 }; 152 unsigned char soft_reset[] = { 0x00, 0x00 };
437 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode }; 153 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
438 unsigned char expert_mode[] = { 0x01, 0x80 }; 154 unsigned char expert_mode[] = { 0x01, 0x80 };
@@ -457,8 +173,8 @@ static int tda8290_set_params(struct dvb_frontend *fe,
457 173
458 set_audio(fe, params); 174 set_audio(fe, params);
459 175
460 if (priv->lna_cfg) 176 if (priv->cfg.config)
461 tuner_dbg("tda827xa config is 0x%02x\n", *priv->lna_cfg); 177 tuner_dbg("tda827xa config is 0x%02x\n", *priv->cfg.config);
462 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2); 178 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
463 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2); 179 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
464 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2); 180 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
@@ -475,10 +191,10 @@ static int tda8290_set_params(struct dvb_frontend *fe,
475 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2); 191 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
476 192
477 tda8290_i2c_bridge(fe, 1); 193 tda8290_i2c_bridge(fe, 1);
478 if (priv->tda827x_ver != 0) 194
479 tda827xa_set_analog_params(fe, params); 195 if (fe->ops.tuner_ops.set_analog_params)
480 else 196 fe->ops.tuner_ops.set_analog_params(fe, params);
481 tda827x_set_analog_params(fe, params); 197
482 for (i = 0; i < 3; i++) { 198 for (i = 0; i < 3; i++) {
483 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1); 199 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
484 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1); 200 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
@@ -507,10 +223,8 @@ static int tda8290_set_params(struct dvb_frontend *fe,
507 if ((agc_stat > 115) || !(pll_stat & 0x80)) { 223 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
508 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n", 224 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
509 agc_stat, pll_stat & 0x80); 225 agc_stat, pll_stat & 0x80);
510 if (priv->tda827x_ver != 0) 226 if (priv->cfg.agcf)
511 tda827xa_agcf(fe); 227 priv->cfg.agcf(fe);
512 else
513 tda827x_agcf(fe);
514 msleep(100); 228 msleep(100);
515 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1); 229 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
516 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1); 230 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
@@ -541,99 +255,242 @@ static int tda8290_set_params(struct dvb_frontend *fe,
541 255
542 tda8290_i2c_bridge(fe, 0); 256 tda8290_i2c_bridge(fe, 0);
543 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2); 257 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
258}
259
260/*---------------------------------------------------------------------*/
261
262static void tda8295_power(struct dvb_frontend *fe, int enable)
263{
264 struct tda8290_priv *priv = fe->analog_demod_priv;
265 unsigned char buf[] = { 0x30, 0x00 }; /* clb_stdbt */
544 266
545 priv->frequency = (V4L2_TUNER_RADIO == params->mode) ? 267 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
546 params->frequency * 125 / 2 : params->frequency * 62500; 268 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
547 269
548 return 0; 270 if (enable)
271 buf[1] = 0x01;
272 else
273 buf[1] = 0x03;
274
275 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
276}
277
278static void tda8295_set_easy_mode(struct dvb_frontend *fe, int enable)
279{
280 struct tda8290_priv *priv = fe->analog_demod_priv;
281 unsigned char buf[] = { 0x01, 0x00 };
282
283 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
284 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
285
286 if (enable)
287 buf[1] = 0x01; /* rising edge sets regs 0x02 - 0x23 */
288 else
289 buf[1] = 0x00; /* reset active bit */
290
291 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
292}
293
294static void tda8295_set_video_std(struct dvb_frontend *fe)
295{
296 struct tda8290_priv *priv = fe->analog_demod_priv;
297 unsigned char buf[] = { 0x00, priv->tda8290_easy_mode };
298
299 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
300
301 tda8295_set_easy_mode(fe, 1);
302 msleep(20);
303 tda8295_set_easy_mode(fe, 0);
549} 304}
550 305
551/*---------------------------------------------------------------------*/ 306/*---------------------------------------------------------------------*/
552 307
553static int tda8290_has_signal(struct dvb_frontend *fe) 308static void tda8295_agc1_out(struct dvb_frontend *fe, int enable)
554{ 309{
555 struct tda8290_priv *priv = fe->tuner_priv; 310 struct tda8290_priv *priv = fe->analog_demod_priv;
556 int ret; 311 unsigned char buf[] = { 0x02, 0x00 }; /* DIV_FUNC */
557 312
558 unsigned char i2c_get_afc[1] = { 0x1B }; 313 tuner_i2c_xfer_send(&priv->i2c_props, &buf[0], 1);
559 unsigned char afc = 0; 314 tuner_i2c_xfer_recv(&priv->i2c_props, &buf[1], 1);
560 315
561 /* for now, report based on afc status */ 316 if (enable)
562 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc)); 317 buf[1] &= ~0x40;
563 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1); 318 else
319 buf[1] |= 0x40;
564 320
565 ret = (afc & 0x80) ? 65535 : 0; 321 tuner_i2c_xfer_send(&priv->i2c_props, buf, 2);
322}
323
324static void tda8295_agc2_out(struct dvb_frontend *fe, int enable)
325{
326 struct tda8290_priv *priv = fe->analog_demod_priv;
327 unsigned char set_gpio_cf[] = { 0x44, 0x00 };
328 unsigned char set_gpio_val[] = { 0x46, 0x00 };
329
330 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_cf[0], 1);
331 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_cf[1], 1);
332 tuner_i2c_xfer_send(&priv->i2c_props, &set_gpio_val[0], 1);
333 tuner_i2c_xfer_recv(&priv->i2c_props, &set_gpio_val[1], 1);
566 334
567 tuner_dbg("AFC status: %d\n", ret); 335 set_gpio_cf[1] &= 0xf0; /* clear GPIO_0 bits 3-0 */
568 336
569 return ret; 337 if (enable) {
338 set_gpio_cf[1] |= 0x01; /* config GPIO_0 as Open Drain Out */
339 set_gpio_val[1] &= 0xfe; /* set GPIO_0 pin low */
340 }
341 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_cf, 2);
342 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_val, 2);
570} 343}
571 344
572static int tda8290_get_status(struct dvb_frontend *fe, u32 *status) 345static int tda8295_has_signal(struct dvb_frontend *fe)
573{ 346{
574 *status = 0; 347 struct tda8290_priv *priv = fe->analog_demod_priv;
575 348
576 if (tda8290_has_signal(fe)) 349 unsigned char hvpll_stat = 0x26;
577 *status = TUNER_STATUS_LOCKED; 350 unsigned char ret;
578 351
579 return 0; 352 tuner_i2c_xfer_send(&priv->i2c_props, &hvpll_stat, 1);
353 tuner_i2c_xfer_recv(&priv->i2c_props, &ret, 1);
354 return (ret & 0x01) ? 65535 : 0;
580} 355}
581 356
582static int tda8290_get_rf_strength(struct dvb_frontend *fe, u16 *strength) 357/*---------------------------------------------------------------------*/
358
359static void tda8295_set_params(struct dvb_frontend *fe,
360 struct analog_parameters *params)
583{ 361{
584 *strength = tda8290_has_signal(fe); 362 struct tda8290_priv *priv = fe->analog_demod_priv;
585 363
586 return 0; 364 unsigned char blanking_mode[] = { 0x1d, 0x00 };
365
366 set_audio(fe, params);
367
368 tuner_dbg("%s: freq = %d\n", __FUNCTION__, params->frequency);
369
370 tda8295_power(fe, 1);
371 tda8295_agc1_out(fe, 1);
372
373 tuner_i2c_xfer_send(&priv->i2c_props, &blanking_mode[0], 1);
374 tuner_i2c_xfer_recv(&priv->i2c_props, &blanking_mode[1], 1);
375
376 tda8295_set_video_std(fe);
377
378 blanking_mode[1] = 0x03;
379 tuner_i2c_xfer_send(&priv->i2c_props, blanking_mode, 2);
380 msleep(20);
381
382 tda8295_i2c_bridge(fe, 1);
383
384 if (fe->ops.tuner_ops.set_analog_params)
385 fe->ops.tuner_ops.set_analog_params(fe, params);
386
387 if (priv->cfg.agcf)
388 priv->cfg.agcf(fe);
389
390 if (tda8295_has_signal(fe))
391 tuner_dbg("tda8295 is locked\n");
392 else
393 tuner_dbg("tda8295 not locked, no signal?\n");
394
395 tda8295_i2c_bridge(fe, 0);
396}
397
398/*---------------------------------------------------------------------*/
399
400static int tda8290_has_signal(struct dvb_frontend *fe)
401{
402 struct tda8290_priv *priv = fe->analog_demod_priv;
403
404 unsigned char i2c_get_afc[1] = { 0x1B };
405 unsigned char afc = 0;
406
407 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
408 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
409 return (afc & 0x80)? 65535:0;
587} 410}
588 411
589/*---------------------------------------------------------------------*/ 412/*---------------------------------------------------------------------*/
590 413
591static int tda8290_standby(struct dvb_frontend *fe) 414static void tda8290_standby(struct dvb_frontend *fe)
592{ 415{
593 struct tda8290_priv *priv = fe->tuner_priv; 416 struct tda8290_priv *priv = fe->analog_demod_priv;
417
594 unsigned char cb1[] = { 0x30, 0xD0 }; 418 unsigned char cb1[] = { 0x30, 0xD0 };
595 unsigned char tda8290_standby[] = { 0x00, 0x02 }; 419 unsigned char tda8290_standby[] = { 0x00, 0x02 };
596 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; 420 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
597 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; 421 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
598 422
599 tda8290_i2c_bridge(fe, 1); 423 tda8290_i2c_bridge(fe, 1);
600 if (priv->tda827x_ver != 0) 424 if (priv->ver & TDA8275A)
601 cb1[1] = 0x90; 425 cb1[1] = 0x90;
602 i2c_transfer(priv->i2c_props.adap, &msg, 1); 426 i2c_transfer(priv->i2c_props.adap, &msg, 1);
603 tda8290_i2c_bridge(fe, 0); 427 tda8290_i2c_bridge(fe, 0);
604 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2); 428 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
605 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2); 429 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
606
607 return 0;
608} 430}
609 431
432static void tda8295_standby(struct dvb_frontend *fe)
433{
434 tda8295_agc1_out(fe, 0); /* Put AGC in tri-state */
435
436 tda8295_power(fe, 0);
437}
610 438
611static void tda8290_init_if(struct dvb_frontend *fe) 439static void tda8290_init_if(struct dvb_frontend *fe)
612{ 440{
613 struct tda8290_priv *priv = fe->tuner_priv; 441 struct tda8290_priv *priv = fe->analog_demod_priv;
614 442
615 unsigned char set_VS[] = { 0x30, 0x6F }; 443 unsigned char set_VS[] = { 0x30, 0x6F };
616 unsigned char set_GP00_CF[] = { 0x20, 0x01 }; 444 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
617 unsigned char set_GP01_CF[] = { 0x20, 0x0B }; 445 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
618 446
619 if ((priv->lna_cfg) && 447 if ((priv->cfg.config) &&
620 ((*priv->lna_cfg == 1) || (*priv->lna_cfg == 2))) 448 ((*priv->cfg.config == 1) || (*priv->cfg.config == 2)))
621 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2); 449 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
622 else 450 else
623 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2); 451 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
624 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2); 452 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
625} 453}
626 454
455static void tda8295_init_if(struct dvb_frontend *fe)
456{
457 struct tda8290_priv *priv = fe->analog_demod_priv;
458
459 static unsigned char set_adc_ctl[] = { 0x33, 0x14 };
460 static unsigned char set_adc_ctl2[] = { 0x34, 0x00 };
461 static unsigned char set_pll_reg6[] = { 0x3e, 0x63 };
462 static unsigned char set_pll_reg0[] = { 0x38, 0x23 };
463 static unsigned char set_pll_reg7[] = { 0x3f, 0x01 };
464 static unsigned char set_pll_reg10[] = { 0x42, 0x61 };
465 static unsigned char set_gpio_reg0[] = { 0x44, 0x0b };
466
467 tda8295_power(fe, 1);
468
469 tda8295_set_easy_mode(fe, 0);
470 tda8295_set_video_std(fe);
471
472 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl, 2);
473 tuner_i2c_xfer_send(&priv->i2c_props, set_adc_ctl2, 2);
474 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg6, 2);
475 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg0, 2);
476 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg7, 2);
477 tuner_i2c_xfer_send(&priv->i2c_props, set_pll_reg10, 2);
478 tuner_i2c_xfer_send(&priv->i2c_props, set_gpio_reg0, 2);
479
480 tda8295_agc1_out(fe, 0);
481 tda8295_agc2_out(fe, 0);
482}
483
627static void tda8290_init_tuner(struct dvb_frontend *fe) 484static void tda8290_init_tuner(struct dvb_frontend *fe)
628{ 485{
629 struct tda8290_priv *priv = fe->tuner_priv; 486 struct tda8290_priv *priv = fe->analog_demod_priv;
630 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, 487 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
631 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; 488 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
632 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b, 489 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
633 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b }; 490 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
634 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, 491 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
635 .buf=tda8275_init, .len = 14}; 492 .buf=tda8275_init, .len = 14};
636 if (priv->tda827x_ver != 0) 493 if (priv->ver & TDA8275A)
637 msg.buf = tda8275a_init; 494 msg.buf = tda8275a_init;
638 495
639 tda8290_i2c_bridge(fe, 1); 496 tda8290_i2c_bridge(fe, 1);
@@ -643,58 +500,42 @@ static void tda8290_init_tuner(struct dvb_frontend *fe)
643 500
644/*---------------------------------------------------------------------*/ 501/*---------------------------------------------------------------------*/
645 502
646static int tda8290_release(struct dvb_frontend *fe) 503static void tda829x_release(struct dvb_frontend *fe)
647{ 504{
648 kfree(fe->tuner_priv); 505 struct tda8290_priv *priv = fe->analog_demod_priv;
649 fe->tuner_priv = NULL;
650 506
651 return 0; 507 /* only try to release the tuner if we've
652} 508 * attached it from within this module */
509 if (priv->ver & (TDA18271 | TDA8275 | TDA8275A))
510 if (fe->ops.tuner_ops.release)
511 fe->ops.tuner_ops.release(fe);
653 512
654static int tda8290_get_frequency(struct dvb_frontend *fe, u32 *frequency) 513 kfree(fe->analog_demod_priv);
655{ 514 fe->analog_demod_priv = NULL;
656 struct tda8290_priv *priv = fe->tuner_priv;
657 *frequency = priv->frequency;
658 return 0;
659} 515}
660 516
661static struct dvb_tuner_ops tda8290_tuner_ops = { 517static struct tda18271_config tda829x_tda18271_config = {
662 .sleep = tda8290_standby, 518 .gate = TDA18271_GATE_ANALOG,
663 .set_analog_params = tda8290_set_params,
664 .release = tda8290_release,
665 .get_frequency = tda8290_get_frequency,
666 .get_status = tda8290_get_status,
667 .get_rf_strength = tda8290_get_rf_strength,
668}; 519};
669 520
670struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe, 521static int tda829x_find_tuner(struct dvb_frontend *fe)
671 struct i2c_adapter* i2c_adap,
672 u8 i2c_addr,
673 struct tda8290_config *cfg)
674{ 522{
675 struct tda8290_priv *priv = NULL; 523 struct tda8290_priv *priv = fe->analog_demod_priv;
676 u8 data; 524 struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
677 int i, ret, tuners_found; 525 int i, ret, tuners_found;
678 u32 tuner_addrs; 526 u32 tuner_addrs;
679 struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1}; 527 u8 data;
528 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
680 529
681 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL); 530 if (NULL == analog_ops->i2c_gate_ctrl)
682 if (priv == NULL) 531 return -EINVAL;
683 return NULL;
684 fe->tuner_priv = priv;
685 532
686 priv->i2c_props.addr = i2c_addr; 533 analog_ops->i2c_gate_ctrl(fe, 1);
687 priv->i2c_props.adap = i2c_adap;
688 if (cfg) {
689 priv->lna_cfg = cfg->lna_cfg;
690 priv->tuner_callback = cfg->tuner_callback;
691 }
692 534
693 tda8290_i2c_bridge(fe, 1);
694 /* probe for tuner chip */ 535 /* probe for tuner chip */
695 tuners_found = 0; 536 tuners_found = 0;
696 tuner_addrs = 0; 537 tuner_addrs = 0;
697 for (i=0x60; i<= 0x63; i++) { 538 for (i = 0x60; i <= 0x63; i++) {
698 msg.addr = i; 539 msg.addr = i;
699 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); 540 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
700 if (ret == 1) { 541 if (ret == 1) {
@@ -706,20 +547,23 @@ struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe,
706 behind the bridge and we choose the highest address that doesn't 547 behind the bridge and we choose the highest address that doesn't
707 give a response now 548 give a response now
708 */ 549 */
709 tda8290_i2c_bridge(fe, 0); 550
710 if(tuners_found > 1) 551 analog_ops->i2c_gate_ctrl(fe, 0);
552
553 if (tuners_found > 1)
711 for (i = 0; i < tuners_found; i++) { 554 for (i = 0; i < tuners_found; i++) {
712 msg.addr = tuner_addrs & 0xff; 555 msg.addr = tuner_addrs & 0xff;
713 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); 556 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
714 if(ret == 1) 557 if (ret == 1)
715 tuner_addrs = tuner_addrs >> 8; 558 tuner_addrs = tuner_addrs >> 8;
716 else 559 else
717 break; 560 break;
718 } 561 }
562
719 if (tuner_addrs == 0) { 563 if (tuner_addrs == 0) {
720 tuner_addrs = 0x61; 564 tuner_addrs = 0x60;
721 tuner_info("could not clearly identify tuner address, defaulting to %x\n", 565 tuner_info("could not clearly identify tuner address, "
722 tuner_addrs); 566 "defaulting to %x\n", tuner_addrs);
723 } else { 567 } else {
724 tuner_addrs = tuner_addrs & 0xff; 568 tuner_addrs = tuner_addrs & 0xff;
725 tuner_info("setting tuner address to %x\n", tuner_addrs); 569 tuner_info("setting tuner address to %x\n", tuner_addrs);
@@ -727,42 +571,181 @@ struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe,
727 priv->tda827x_addr = tuner_addrs; 571 priv->tda827x_addr = tuner_addrs;
728 msg.addr = tuner_addrs; 572 msg.addr = tuner_addrs;
729 573
730 tda8290_i2c_bridge(fe, 1); 574 analog_ops->i2c_gate_ctrl(fe, 1);
731 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); 575 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
732 if( ret != 1) 576
733 tuner_warn("TDA827x access failed!\n"); 577 if (ret != 1) {
734 578 tuner_warn("tuner access failed!\n");
735 memcpy(&fe->ops.tuner_ops, &tda8290_tuner_ops, 579 return -EREMOTEIO;
736 sizeof(struct dvb_tuner_ops)); 580 }
737 581
738 if ((data & 0x3c) == 0) { 582 if ((data == 0x83) || (data == 0x84)) {
739 strlcpy(fe->ops.tuner_ops.info.name, "tda8290+75", 583 priv->ver |= TDA18271;
740 sizeof(fe->ops.tuner_ops.info.name)); 584 tda18271_attach(fe, priv->tda827x_addr,
741 fe->ops.tuner_ops.info.frequency_min = 55000000; 585 priv->i2c_props.adap,
742 fe->ops.tuner_ops.info.frequency_max = 860000000; 586 &tda829x_tda18271_config);
743 fe->ops.tuner_ops.info.frequency_step = 250000;
744 priv->tda827x_ver = 0;
745 } else { 587 } else {
746 strlcpy(fe->ops.tuner_ops.info.name, "tda8290+75a", 588 if ((data & 0x3c) == 0)
747 sizeof(fe->ops.tuner_ops.info.name)); 589 priv->ver |= TDA8275;
748 fe->ops.tuner_ops.info.frequency_min = 44000000; 590 else
749 fe->ops.tuner_ops.info.frequency_max = 906000000; 591 priv->ver |= TDA8275A;
750 fe->ops.tuner_ops.info.frequency_step = 62500; 592
751 priv->tda827x_ver = 2; 593 tda827x_attach(fe, priv->tda827x_addr,
594 priv->i2c_props.adap, &priv->cfg);
595 }
596 if (fe->ops.tuner_ops.init)
597 fe->ops.tuner_ops.init(fe);
598
599 if (fe->ops.tuner_ops.sleep)
600 fe->ops.tuner_ops.sleep(fe);
601
602 analog_ops->i2c_gate_ctrl(fe, 0);
603
604 return 0;
605}
606
607static int tda8290_probe(struct tuner_i2c_props *i2c_props)
608{
609#define TDA8290_ID 0x89
610 unsigned char tda8290_id[] = { 0x1f, 0x00 };
611
612 /* detect tda8290 */
613 tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
614 tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);
615
616 if (tda8290_id[1] == TDA8290_ID) {
617 if (debug)
618 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
619 __FUNCTION__, i2c_adapter_id(i2c_props->adap),
620 i2c_props->addr);
621 return 0;
622 }
623
624 return -ENODEV;
625}
626
627static int tda8295_probe(struct tuner_i2c_props *i2c_props)
628{
629#define TDA8295_ID 0x8a
630 unsigned char tda8295_id[] = { 0x2f, 0x00 };
631
632 /* detect tda8295 */
633 tuner_i2c_xfer_send(i2c_props, &tda8295_id[0], 1);
634 tuner_i2c_xfer_recv(i2c_props, &tda8295_id[1], 1);
635
636 if (tda8295_id[1] == TDA8295_ID) {
637 if (debug)
638 printk(KERN_DEBUG "%s: tda8295 detected @ %d-%04x\n",
639 __FUNCTION__, i2c_adapter_id(i2c_props->adap),
640 i2c_props->addr);
641 return 0;
752 } 642 }
753 643
754 priv->tda827x_lpsel = 0; 644 return -ENODEV;
645}
646
647static struct analog_demod_ops tda8290_ops = {
648 .set_params = tda8290_set_params,
649 .has_signal = tda8290_has_signal,
650 .standby = tda8290_standby,
651 .release = tda829x_release,
652 .i2c_gate_ctrl = tda8290_i2c_bridge,
653};
654
655static struct analog_demod_ops tda8295_ops = {
656 .set_params = tda8295_set_params,
657 .has_signal = tda8295_has_signal,
658 .standby = tda8295_standby,
659 .release = tda829x_release,
660 .i2c_gate_ctrl = tda8295_i2c_bridge,
661};
662
663struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
664 struct i2c_adapter *i2c_adap, u8 i2c_addr,
665 struct tda829x_config *cfg)
666{
667 struct tda8290_priv *priv = NULL;
668 char *name;
669
670 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
671 if (priv == NULL)
672 return NULL;
673 fe->analog_demod_priv = priv;
674
675 priv->i2c_props.addr = i2c_addr;
676 priv->i2c_props.adap = i2c_adap;
677 if (cfg) {
678 priv->cfg.config = cfg->lna_cfg;
679 priv->cfg.tuner_callback = cfg->tuner_callback;
680 }
681
682 if (tda8290_probe(&priv->i2c_props) == 0) {
683 priv->ver = TDA8290;
684 memcpy(&fe->ops.analog_ops, &tda8290_ops,
685 sizeof(struct analog_demod_ops));
686 }
687
688 if (tda8295_probe(&priv->i2c_props) == 0) {
689 priv->ver = TDA8295;
690 memcpy(&fe->ops.analog_ops, &tda8295_ops,
691 sizeof(struct analog_demod_ops));
692 }
693
694 if ((!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) &&
695 (tda829x_find_tuner(fe) < 0))
696 goto fail;
697
698 switch (priv->ver) {
699 case TDA8290:
700 name = "tda8290";
701 break;
702 case TDA8295:
703 name = "tda8295";
704 break;
705 case TDA8290 | TDA8275:
706 name = "tda8290+75";
707 break;
708 case TDA8295 | TDA8275:
709 name = "tda8295+75";
710 break;
711 case TDA8290 | TDA8275A:
712 name = "tda8290+75a";
713 break;
714 case TDA8295 | TDA8275A:
715 name = "tda8295+75a";
716 break;
717 case TDA8290 | TDA18271:
718 name = "tda8290+18271";
719 break;
720 case TDA8295 | TDA18271:
721 name = "tda8295+18271";
722 break;
723 default:
724 goto fail;
725 }
726 tuner_info("type set to %s\n", name);
727
728 fe->ops.analog_ops.info.name = name;
729
730 if (priv->ver & TDA8290) {
731 tda8290_init_tuner(fe);
732 tda8290_init_if(fe);
733 } else if (priv->ver & TDA8295)
734 tda8295_init_if(fe);
755 735
756 tda8290_init_tuner(fe);
757 tda8290_init_if(fe);
758 return fe; 736 return fe;
737
738fail:
739 tda829x_release(fe);
740 return NULL;
759} 741}
742EXPORT_SYMBOL_GPL(tda829x_attach);
760 743
761int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr) 744int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
762{ 745{
763 struct tuner_i2c_props i2c_props = { 746 struct tuner_i2c_props i2c_props = {
764 .adap = i2c_adap, 747 .adap = i2c_adap,
765 .addr = i2c_addr 748 .addr = i2c_addr,
766 }; 749 };
767 750
768 unsigned char soft_reset[] = { 0x00, 0x00 }; 751 unsigned char soft_reset[] = { 0x00, 0x00 };
@@ -771,7 +754,27 @@ int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr)
771 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 }; 754 unsigned char restore_9886[] = { 0x00, 0xd6, 0x30 };
772 unsigned char addr_dto_lsb = 0x07; 755 unsigned char addr_dto_lsb = 0x07;
773 unsigned char data; 756 unsigned char data;
757#define PROBE_BUFFER_SIZE 8
758 unsigned char buf[PROBE_BUFFER_SIZE];
759 int i;
760
761 /* rule out tda9887, which would return the same byte repeatedly */
762 tuner_i2c_xfer_send(&i2c_props, soft_reset, 1);
763 tuner_i2c_xfer_recv(&i2c_props, buf, PROBE_BUFFER_SIZE);
764 for (i = 1; i < PROBE_BUFFER_SIZE; i++) {
765 if (buf[i] != buf[0])
766 break;
767 }
774 768
769 /* all bytes are equal, not a tda829x - probably a tda9887 */
770 if (i == PROBE_BUFFER_SIZE)
771 return -ENODEV;
772
773 if ((tda8290_probe(&i2c_props) == 0) ||
774 (tda8295_probe(&i2c_props) == 0))
775 return 0;
776
777 /* fall back to old probing method */
775 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2); 778 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
776 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2); 779 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
777 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1); 780 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
@@ -786,14 +789,12 @@ int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr)
786 } 789 }
787 } 790 }
788 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3); 791 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
789 return -1; 792 return -ENODEV;
790} 793}
794EXPORT_SYMBOL_GPL(tda829x_probe);
791 795
792EXPORT_SYMBOL_GPL(tda8290_probe); 796MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
793EXPORT_SYMBOL_GPL(tda8290_attach); 797MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
794
795MODULE_DESCRIPTION("Philips TDA8290 + TDA8275 / TDA8275a tuner driver");
796MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann");
797MODULE_LICENSE("GPL"); 798MODULE_LICENSE("GPL");
798 799
799/* 800/*
diff --git a/drivers/media/video/tda8290.h b/drivers/media/video/tda8290.h
index 107b24b05aa1..dc8ef310b7b2 100644
--- a/drivers/media/video/tda8290.h
+++ b/drivers/media/video/tda8290.h
@@ -20,33 +20,36 @@
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include "dvb_frontend.h" 21#include "dvb_frontend.h"
22 22
23struct tda8290_config 23struct tda829x_config {
24{
25 unsigned int *lna_cfg; 24 unsigned int *lna_cfg;
26 int (*tuner_callback) (void *dev, int command,int arg); 25 int (*tuner_callback) (void *dev, int command, int arg);
26
27 unsigned int probe_tuner:1;
28#define TDA829X_PROBE_TUNER 0
29#define TDA829X_DONT_PROBE 1
27}; 30};
28 31
29#if defined(CONFIG_TUNER_TDA8290) || (defined(CONFIG_TUNER_TDA8290_MODULE) && defined(MODULE)) 32#if defined(CONFIG_TUNER_TDA8290) || (defined(CONFIG_TUNER_TDA8290_MODULE) && defined(MODULE))
30extern int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr); 33extern int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr);
31 34
32extern struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe, 35extern struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
33 struct i2c_adapter* i2c_adap, 36 struct i2c_adapter *i2c_adap,
34 u8 i2c_addr, 37 u8 i2c_addr,
35 struct tda8290_config *cfg); 38 struct tda829x_config *cfg);
36#else 39#else
37static inline int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr) 40static inline int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
38{ 41{
39 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n", 42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
40 __FUNCTION__);
41 return -EINVAL; 43 return -EINVAL;
42} 44}
43 45
44static inline struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe, 46static inline struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
45 struct i2c_adapter* i2c_adap, 47 struct i2c_adapter *i2c_adap,
46 u8 i2c_addr, 48 u8 i2c_addr,
47 struct tda8290_config *cfg) 49 struct tda829x_config *cfg)
48{ 50{
49 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 51 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
52 __FUNCTION__);
50 return NULL; 53 return NULL;
51} 54}
52#endif 55#endif
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index d11044170872..3c0557130a70 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -7,6 +7,7 @@
7 * 7 *
8 * Copyright (c) 2000 Guillaume Delvit based on Gerd Knorr source and 8 * Copyright (c) 2000 Guillaume Delvit based on Gerd Knorr source and
9 * Eric Sandeen 9 * Eric Sandeen
10 * Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
10 * This code is placed under the terms of the GNU General Public License 11 * This code is placed under the terms of the GNU General Public License
11 * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu) 12 * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu)
12 * Which was based on tda8425.c by Greg Alexander (c) 1998 13 * Which was based on tda8425.c by Greg Alexander (c) 1998
@@ -268,87 +269,143 @@ static int tda9875_detach(struct i2c_client *client)
268 return 0; 269 return 0;
269} 270}
270 271
271static int tda9875_command(struct i2c_client *client, 272static int tda9875_get_ctrl(struct i2c_client *client,
272 unsigned int cmd, void *arg) 273 struct v4l2_control *ctrl)
273{ 274{
274 struct tda9875 *t = i2c_get_clientdata(client); 275 struct tda9875 *t = i2c_get_clientdata(client);
275 276
276 dprintk("In tda9875_command...\n"); 277 switch (ctrl->id) {
278 case V4L2_CID_AUDIO_VOLUME:
279 {
280 int left = (t->lvol+84)*606;
281 int right = (t->rvol+84)*606;
277 282
278 switch (cmd) { 283 ctrl->value=max(left,right);
279 /* --- v4l ioctls --- */ 284 return 0;
280 /* take care: bttv does userspace copying, we'll get a 285 }
281 kernel pointer here... */ 286 case V4L2_CID_AUDIO_BALANCE:
282 case VIDIOCGAUDIO:
283 { 287 {
284 struct video_audio *va = arg; 288 int left = (t->lvol+84)*606;
285 int left,right; 289 int right = (t->rvol+84)*606;
290 int volume = max(left,right);
291 int balance = (32768*min(left,right))/
292 (volume ? volume : 1);
293 ctrl->value=(left<right)?
294 (65535-balance) : balance;
295 return 0;
296 }
297 case V4L2_CID_AUDIO_BASS:
298 ctrl->value = (t->bass+12)*2427; /* min -12 max +15 */
299 return 0;
300 case V4L2_CID_AUDIO_TREBLE:
301 ctrl->value = (t->treble+12)*2730;/* min -12 max +12 */
302 return 0;
303 }
304 return -EINVAL;
305}
286 306
287 dprintk("VIDIOCGAUDIO\n"); 307static int tda9875_set_ctrl(struct i2c_client *client,
308 struct v4l2_control *ctrl)
309{
310 struct tda9875 *t = i2c_get_clientdata(client);
311 int chvol=0, volume, balance, left, right;
288 312
289 va->flags |= VIDEO_AUDIO_VOLUME | 313 switch (ctrl->id) {
290 VIDEO_AUDIO_BASS | 314 case V4L2_CID_AUDIO_VOLUME:
291 VIDEO_AUDIO_TREBLE; 315 left = (t->lvol+84)*606;
316 right = (t->rvol+84)*606;
317
318 volume = max(left,right);
319 balance = (32768*min(left,right))/
320 (volume ? volume : 1);
321 balance =(left<right)?
322 (65535-balance) : balance;
323
324 volume = ctrl->value;
292 325
293 /* min is -84 max is 24 */ 326 chvol=1;
327 break;
328 case V4L2_CID_AUDIO_BALANCE:
294 left = (t->lvol+84)*606; 329 left = (t->lvol+84)*606;
295 right = (t->rvol+84)*606; 330 right = (t->rvol+84)*606;
296 va->volume=max(left,right); 331
297 va->balance=(32768*min(left,right))/ 332 volume=max(left,right);
298 (va->volume ? va->volume : 1); 333
299 va->balance=(left<right)? 334 balance = ctrl->value;
300 (65535-va->balance) : va->balance; 335
301 va->bass = (t->bass+12)*2427; /* min -12 max +15 */ 336 chvol=1;
302 va->treble = (t->treble+12)*2730;/* min -12 max +12 */ 337 break;
303 va->mode |= VIDEO_SOUND_MONO; 338 case V4L2_CID_AUDIO_BASS:
304 339 t->bass = ((ctrl->value/2400)-12) & 0xff;
305 break; /* VIDIOCGAUDIO case */ 340 if (t->bass > 15)
341 t->bass = 15;
342 if (t->bass < -12)
343 t->bass = -12 & 0xff;
344 break;
345 case V4L2_CID_AUDIO_TREBLE:
346 t->treble = ((ctrl->value/2700)-12) & 0xff;
347 if (t->treble > 12)
348 t->treble = 12;
349 if (t->treble < -12)
350 t->treble = -12 & 0xff;
351 break;
352 default:
353 return -EINVAL;
306 } 354 }
307 355
308 case VIDIOCSAUDIO: 356 if (chvol) {
309 { 357 left = (min(65536 - balance,32768) *
310 struct video_audio *va = arg; 358 volume) / 32768;
311 int left,right; 359 right = (min(balance,32768) *
312 360 volume) / 32768;
313 dprintk("VIDEOCSAUDIO...\n");
314 left = (min(65536 - va->balance,32768) *
315 va->volume) / 32768;
316 right = (min(va->balance,(__u16)32768) *
317 va->volume) / 32768;
318 t->lvol = ((left/606)-84) & 0xff; 361 t->lvol = ((left/606)-84) & 0xff;
319 if (t->lvol > 24) 362 if (t->lvol > 24)
320 t->lvol = 24; 363 t->lvol = 24;
321 if (t->lvol < -84) 364 if (t->lvol < -84)
322 t->lvol = -84 & 0xff; 365 t->lvol = -84 & 0xff;
323 366
324 t->rvol = ((right/606)-84) & 0xff; 367 t->rvol = ((right/606)-84) & 0xff;
325 if (t->rvol > 24) 368 if (t->rvol > 24)
326 t->rvol = 24; 369 t->rvol = 24;
327 if (t->rvol < -84) 370 if (t->rvol < -84)
328 t->rvol = -84 & 0xff; 371 t->rvol = -84 & 0xff;
329 372 }
330 t->bass = ((va->bass/2400)-12) & 0xff;
331 if (t->bass > 15)
332 t->bass = 15;
333 if (t->bass < -12)
334 t->bass = -12 & 0xff;
335
336 t->treble = ((va->treble/2700)-12) & 0xff;
337 if (t->treble > 12)
338 t->treble = 12;
339 if (t->treble < -12)
340 t->treble = -12 & 0xff;
341 373
374//printk("tda9875 bal:%04x vol:%04x bass:%04x treble:%04x\n",va->balance,va->volume,va->bass,va->treble);
342 375
376 tda9875_set(client);
343 377
344//printk("tda9875 bal:%04x vol:%04x bass:%04x treble:%04x\n",va->balance,va->volume,va->bass,va->treble); 378 return 0;
379}
345 380
346 381
347 tda9875_set(client); 382static int tda9875_command(struct i2c_client *client,
383 unsigned int cmd, void *arg)
384{
385 dprintk("In tda9875_command...\n");
348 386
349 break; 387 switch (cmd) {
388 /* --- v4l ioctls --- */
389 /* take care: bttv does userspace copying, we'll get a
390 kernel pointer here... */
391 case VIDIOC_QUERYCTRL:
392 {
393 struct v4l2_queryctrl *qc = arg;
394
395 switch (qc->id) {
396 case V4L2_CID_AUDIO_VOLUME:
397 case V4L2_CID_AUDIO_BASS:
398 case V4L2_CID_AUDIO_TREBLE:
399 default:
400 return -EINVAL;
401 }
402 return v4l2_ctrl_query_fill_std(qc);
403 }
404 case VIDIOC_S_CTRL:
405 return tda9875_set_ctrl(client, arg);
350 406
351 } /* end of VIDEOCSAUDIO case */ 407 case VIDIOC_G_CTRL:
408 return tda9875_get_ctrl(client, arg);
352 409
353 default: /* Not VIDEOCGAUDIO or VIDEOCSAUDIO */ 410 default: /* Not VIDEOCGAUDIO or VIDEOCSAUDIO */
354 411
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index be5387f11afb..106c93b8203f 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -9,7 +9,8 @@
9#include <linux/videodev.h> 9#include <linux/videodev.h>
10#include <media/v4l2-common.h> 10#include <media/v4l2-common.h>
11#include <media/tuner.h> 11#include <media/tuner.h>
12#include "tuner-driver.h" 12#include "tuner-i2c.h"
13#include "tda9887.h"
13 14
14 15
15/* Chips: 16/* Chips:
@@ -20,18 +21,20 @@
20 Used as part of several tuners 21 Used as part of several tuners
21*/ 22*/
22 23
23#define tda9887_info(fmt, arg...) do {\ 24static int debug;
24 printk(KERN_INFO "%s %d-%04x: " fmt, t->i2c.name, \ 25module_param(debug, int, 0644);
25 i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0) 26MODULE_PARM_DESC(debug, "enable verbose debug messages");
26#define tda9887_dbg(fmt, arg...) do {\ 27
27 if (tuner_debug) \ 28#define PREFIX "tda9887"
28 printk(KERN_INFO "%s %d-%04x: " fmt, t->i2c.name, \
29 i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
30 29
31struct tda9887_priv { 30struct tda9887_priv {
32 struct tuner_i2c_props i2c_props; 31 struct tuner_i2c_props i2c_props;
33 32
34 unsigned char data[4]; 33 unsigned char data[4];
34 unsigned int config;
35 unsigned int mode;
36 unsigned int audmode;
37 v4l2_std_id std;
35}; 38};
36 39
37/* ---------------------------------------------------------------------- */ 40/* ---------------------------------------------------------------------- */
@@ -262,8 +265,10 @@ static struct tvnorm radio_mono = {
262 265
263/* ---------------------------------------------------------------------- */ 266/* ---------------------------------------------------------------------- */
264 267
265static void dump_read_message(struct tuner *t, unsigned char *buf) 268static void dump_read_message(struct dvb_frontend *fe, unsigned char *buf)
266{ 269{
270 struct tda9887_priv *priv = fe->analog_demod_priv;
271
267 static char *afc[16] = { 272 static char *afc[16] = {
268 "- 12.5 kHz", 273 "- 12.5 kHz",
269 "- 37.5 kHz", 274 "- 37.5 kHz",
@@ -282,16 +287,18 @@ static void dump_read_message(struct tuner *t, unsigned char *buf)
282 "+ 37.5 kHz", 287 "+ 37.5 kHz",
283 "+ 12.5 kHz", 288 "+ 12.5 kHz",
284 }; 289 };
285 tda9887_info("read: 0x%2x\n", buf[0]); 290 tuner_info("read: 0x%2x\n", buf[0]);
286 tda9887_info(" after power on : %s\n", (buf[0] & 0x01) ? "yes" : "no"); 291 tuner_info(" after power on : %s\n", (buf[0] & 0x01) ? "yes" : "no");
287 tda9887_info(" afc : %s\n", afc[(buf[0] >> 1) & 0x0f]); 292 tuner_info(" afc : %s\n", afc[(buf[0] >> 1) & 0x0f]);
288 tda9887_info(" fmif level : %s\n", (buf[0] & 0x20) ? "high" : "low"); 293 tuner_info(" fmif level : %s\n", (buf[0] & 0x20) ? "high" : "low");
289 tda9887_info(" afc window : %s\n", (buf[0] & 0x40) ? "in" : "out"); 294 tuner_info(" afc window : %s\n", (buf[0] & 0x40) ? "in" : "out");
290 tda9887_info(" vfi level : %s\n", (buf[0] & 0x80) ? "high" : "low"); 295 tuner_info(" vfi level : %s\n", (buf[0] & 0x80) ? "high" : "low");
291} 296}
292 297
293static void dump_write_message(struct tuner *t, unsigned char *buf) 298static void dump_write_message(struct dvb_frontend *fe, unsigned char *buf)
294{ 299{
300 struct tda9887_priv *priv = fe->analog_demod_priv;
301
295 static char *sound[4] = { 302 static char *sound[4] = {
296 "AM/TV", 303 "AM/TV",
297 "FM/radio", 304 "FM/radio",
@@ -330,86 +337,90 @@ static void dump_write_message(struct tuner *t, unsigned char *buf)
330 "44 MHz", 337 "44 MHz",
331 }; 338 };
332 339
333 tda9887_info("write: byte B 0x%02x\n",buf[1]); 340 tuner_info("write: byte B 0x%02x\n", buf[1]);
334 tda9887_info(" B0 video mode : %s\n", 341 tuner_info(" B0 video mode : %s\n",
335 (buf[1] & 0x01) ? "video trap" : "sound trap"); 342 (buf[1] & 0x01) ? "video trap" : "sound trap");
336 tda9887_info(" B1 auto mute fm : %s\n", 343 tuner_info(" B1 auto mute fm : %s\n",
337 (buf[1] & 0x02) ? "yes" : "no"); 344 (buf[1] & 0x02) ? "yes" : "no");
338 tda9887_info(" B2 carrier mode : %s\n", 345 tuner_info(" B2 carrier mode : %s\n",
339 (buf[1] & 0x04) ? "QSS" : "Intercarrier"); 346 (buf[1] & 0x04) ? "QSS" : "Intercarrier");
340 tda9887_info(" B3-4 tv sound/radio : %s\n", 347 tuner_info(" B3-4 tv sound/radio : %s\n",
341 sound[(buf[1] & 0x18) >> 3]); 348 sound[(buf[1] & 0x18) >> 3]);
342 tda9887_info(" B5 force mute audio: %s\n", 349 tuner_info(" B5 force mute audio: %s\n",
343 (buf[1] & 0x20) ? "yes" : "no"); 350 (buf[1] & 0x20) ? "yes" : "no");
344 tda9887_info(" B6 output port 1 : %s\n", 351 tuner_info(" B6 output port 1 : %s\n",
345 (buf[1] & 0x40) ? "high (inactive)" : "low (active)"); 352 (buf[1] & 0x40) ? "high (inactive)" : "low (active)");
346 tda9887_info(" B7 output port 2 : %s\n", 353 tuner_info(" B7 output port 2 : %s\n",
347 (buf[1] & 0x80) ? "high (inactive)" : "low (active)"); 354 (buf[1] & 0x80) ? "high (inactive)" : "low (active)");
348 355
349 tda9887_info("write: byte C 0x%02x\n",buf[2]); 356 tuner_info("write: byte C 0x%02x\n", buf[2]);
350 tda9887_info(" C0-4 top adjustment : %s dB\n", adjust[buf[2] & 0x1f]); 357 tuner_info(" C0-4 top adjustment : %s dB\n",
351 tda9887_info(" C5-6 de-emphasis : %s\n", deemph[(buf[2] & 0x60) >> 5]); 358 adjust[buf[2] & 0x1f]);
352 tda9887_info(" C7 audio gain : %s\n", 359 tuner_info(" C5-6 de-emphasis : %s\n",
353 (buf[2] & 0x80) ? "-6" : "0"); 360 deemph[(buf[2] & 0x60) >> 5]);
354 361 tuner_info(" C7 audio gain : %s\n",
355 tda9887_info("write: byte E 0x%02x\n",buf[3]); 362 (buf[2] & 0x80) ? "-6" : "0");
356 tda9887_info(" E0-1 sound carrier : %s\n", 363
357 carrier[(buf[3] & 0x03)]); 364 tuner_info("write: byte E 0x%02x\n", buf[3]);
358 tda9887_info(" E6 l pll gating : %s\n", 365 tuner_info(" E0-1 sound carrier : %s\n",
359 (buf[3] & 0x40) ? "36" : "13"); 366 carrier[(buf[3] & 0x03)]);
367 tuner_info(" E6 l pll gating : %s\n",
368 (buf[3] & 0x40) ? "36" : "13");
360 369
361 if (buf[1] & 0x08) { 370 if (buf[1] & 0x08) {
362 /* radio */ 371 /* radio */
363 tda9887_info(" E2-4 video if : %s\n", 372 tuner_info(" E2-4 video if : %s\n",
364 rif[(buf[3] & 0x0c) >> 2]); 373 rif[(buf[3] & 0x0c) >> 2]);
365 tda9887_info(" E7 vif agc output : %s\n", 374 tuner_info(" E7 vif agc output : %s\n",
366 (buf[3] & 0x80) 375 (buf[3] & 0x80)
367 ? ((buf[3] & 0x10) ? "fm-agc radio" : "sif-agc radio") 376 ? ((buf[3] & 0x10) ? "fm-agc radio" :
368 : "fm radio carrier afc"); 377 "sif-agc radio")
378 : "fm radio carrier afc");
369 } else { 379 } else {
370 /* video */ 380 /* video */
371 tda9887_info(" E2-4 video if : %s\n", 381 tuner_info(" E2-4 video if : %s\n",
372 vif[(buf[3] & 0x1c) >> 2]); 382 vif[(buf[3] & 0x1c) >> 2]);
373 tda9887_info(" E5 tuner gain : %s\n", 383 tuner_info(" E5 tuner gain : %s\n",
374 (buf[3] & 0x80) 384 (buf[3] & 0x80)
375 ? ((buf[3] & 0x20) ? "external" : "normal") 385 ? ((buf[3] & 0x20) ? "external" : "normal")
376 : ((buf[3] & 0x20) ? "minimum" : "normal")); 386 : ((buf[3] & 0x20) ? "minimum" : "normal"));
377 tda9887_info(" E7 vif agc output : %s\n", 387 tuner_info(" E7 vif agc output : %s\n",
378 (buf[3] & 0x80) 388 (buf[3] & 0x80) ? ((buf[3] & 0x20)
379 ? ((buf[3] & 0x20) 389 ? "pin3 port, pin22 vif agc out"
380 ? "pin3 port, pin22 vif agc out" 390 : "pin22 port, pin3 vif acg ext in")
381 : "pin22 port, pin3 vif acg ext in") 391 : "pin3+pin22 port");
382 : "pin3+pin22 port");
383 } 392 }
384 tda9887_info("--\n"); 393 tuner_info("--\n");
385} 394}
386 395
387/* ---------------------------------------------------------------------- */ 396/* ---------------------------------------------------------------------- */
388 397
389static int tda9887_set_tvnorm(struct tuner *t, char *buf) 398static int tda9887_set_tvnorm(struct dvb_frontend *fe)
390{ 399{
400 struct tda9887_priv *priv = fe->analog_demod_priv;
391 struct tvnorm *norm = NULL; 401 struct tvnorm *norm = NULL;
402 char *buf = priv->data;
392 int i; 403 int i;
393 404
394 if (t->mode == V4L2_TUNER_RADIO) { 405 if (priv->mode == V4L2_TUNER_RADIO) {
395 if (t->audmode == V4L2_TUNER_MODE_MONO) 406 if (priv->audmode == V4L2_TUNER_MODE_MONO)
396 norm = &radio_mono; 407 norm = &radio_mono;
397 else 408 else
398 norm = &radio_stereo; 409 norm = &radio_stereo;
399 } else { 410 } else {
400 for (i = 0; i < ARRAY_SIZE(tvnorms); i++) { 411 for (i = 0; i < ARRAY_SIZE(tvnorms); i++) {
401 if (tvnorms[i].std & t->std) { 412 if (tvnorms[i].std & priv->std) {
402 norm = tvnorms+i; 413 norm = tvnorms+i;
403 break; 414 break;
404 } 415 }
405 } 416 }
406 } 417 }
407 if (NULL == norm) { 418 if (NULL == norm) {
408 tda9887_dbg("Unsupported tvnorm entry - audio muted\n"); 419 tuner_dbg("Unsupported tvnorm entry - audio muted\n");
409 return -1; 420 return -1;
410 } 421 }
411 422
412 tda9887_dbg("configure for: %s\n",norm->name); 423 tuner_dbg("configure for: %s\n", norm->name);
413 buf[1] = norm->b; 424 buf[1] = norm->b;
414 buf[2] = norm->c; 425 buf[2] = norm->c;
415 buf[3] = norm->e; 426 buf[3] = norm->e;
@@ -426,8 +437,11 @@ module_param(port2, int, 0644);
426module_param(qss, int, 0644); 437module_param(qss, int, 0644);
427module_param(adjust, int, 0644); 438module_param(adjust, int, 0644);
428 439
429static int tda9887_set_insmod(struct tuner *t, char *buf) 440static int tda9887_set_insmod(struct dvb_frontend *fe)
430{ 441{
442 struct tda9887_priv *priv = fe->analog_demod_priv;
443 char *buf = priv->data;
444
431 if (UNSET != port1) { 445 if (UNSET != port1) {
432 if (port1) 446 if (port1)
433 buf[1] |= cOutputPort1Inactive; 447 buf[1] |= cOutputPort1Inactive;
@@ -455,27 +469,30 @@ static int tda9887_set_insmod(struct tuner *t, char *buf)
455 return 0; 469 return 0;
456} 470}
457 471
458static int tda9887_set_config(struct tuner *t, char *buf) 472static int tda9887_do_config(struct dvb_frontend *fe)
459{ 473{
460 if (t->tda9887_config & TDA9887_PORT1_ACTIVE) 474 struct tda9887_priv *priv = fe->analog_demod_priv;
475 char *buf = priv->data;
476
477 if (priv->config & TDA9887_PORT1_ACTIVE)
461 buf[1] &= ~cOutputPort1Inactive; 478 buf[1] &= ~cOutputPort1Inactive;
462 if (t->tda9887_config & TDA9887_PORT1_INACTIVE) 479 if (priv->config & TDA9887_PORT1_INACTIVE)
463 buf[1] |= cOutputPort1Inactive; 480 buf[1] |= cOutputPort1Inactive;
464 if (t->tda9887_config & TDA9887_PORT2_ACTIVE) 481 if (priv->config & TDA9887_PORT2_ACTIVE)
465 buf[1] &= ~cOutputPort2Inactive; 482 buf[1] &= ~cOutputPort2Inactive;
466 if (t->tda9887_config & TDA9887_PORT2_INACTIVE) 483 if (priv->config & TDA9887_PORT2_INACTIVE)
467 buf[1] |= cOutputPort2Inactive; 484 buf[1] |= cOutputPort2Inactive;
468 485
469 if (t->tda9887_config & TDA9887_QSS) 486 if (priv->config & TDA9887_QSS)
470 buf[1] |= cQSS; 487 buf[1] |= cQSS;
471 if (t->tda9887_config & TDA9887_INTERCARRIER) 488 if (priv->config & TDA9887_INTERCARRIER)
472 buf[1] &= ~cQSS; 489 buf[1] &= ~cQSS;
473 490
474 if (t->tda9887_config & TDA9887_AUTOMUTE) 491 if (priv->config & TDA9887_AUTOMUTE)
475 buf[1] |= cAutoMuteFmActive; 492 buf[1] |= cAutoMuteFmActive;
476 if (t->tda9887_config & TDA9887_DEEMPHASIS_MASK) { 493 if (priv->config & TDA9887_DEEMPHASIS_MASK) {
477 buf[2] &= ~0x60; 494 buf[2] &= ~0x60;
478 switch (t->tda9887_config & TDA9887_DEEMPHASIS_MASK) { 495 switch (priv->config & TDA9887_DEEMPHASIS_MASK) {
479 case TDA9887_DEEMPHASIS_NONE: 496 case TDA9887_DEEMPHASIS_NONE:
480 buf[2] |= cDeemphasisOFF; 497 buf[2] |= cDeemphasisOFF;
481 break; 498 break;
@@ -487,21 +504,22 @@ static int tda9887_set_config(struct tuner *t, char *buf)
487 break; 504 break;
488 } 505 }
489 } 506 }
490 if (t->tda9887_config & TDA9887_TOP_SET) { 507 if (priv->config & TDA9887_TOP_SET) {
491 buf[2] &= ~cTopMask; 508 buf[2] &= ~cTopMask;
492 buf[2] |= (t->tda9887_config >> 8) & cTopMask; 509 buf[2] |= (priv->config >> 8) & cTopMask;
493 } 510 }
494 if ((t->tda9887_config & TDA9887_INTERCARRIER_NTSC) && (t->std & V4L2_STD_NTSC)) 511 if ((priv->config & TDA9887_INTERCARRIER_NTSC) &&
512 (priv->std & V4L2_STD_NTSC))
495 buf[1] &= ~cQSS; 513 buf[1] &= ~cQSS;
496 if (t->tda9887_config & TDA9887_GATING_18) 514 if (priv->config & TDA9887_GATING_18)
497 buf[3] &= ~cGating_36; 515 buf[3] &= ~cGating_36;
498 516
499 if (t->mode == V4L2_TUNER_RADIO) { 517 if (priv->mode == V4L2_TUNER_RADIO) {
500 if (t->tda9887_config & TDA9887_RIF_41_3) { 518 if (priv->config & TDA9887_RIF_41_3) {
501 buf[3] &= ~cVideoIFMask; 519 buf[3] &= ~cVideoIFMask;
502 buf[3] |= cRadioIF_41_30; 520 buf[3] |= cRadioIF_41_30;
503 } 521 }
504 if (t->tda9887_config & TDA9887_GAIN_NORMAL) 522 if (priv->config & TDA9887_GAIN_NORMAL)
505 buf[3] &= ~cTunerGainLow; 523 buf[3] &= ~cTunerGainLow;
506 } 524 }
507 525
@@ -510,26 +528,26 @@ static int tda9887_set_config(struct tuner *t, char *buf)
510 528
511/* ---------------------------------------------------------------------- */ 529/* ---------------------------------------------------------------------- */
512 530
513static int tda9887_status(struct tuner *t) 531static int tda9887_status(struct dvb_frontend *fe)
514{ 532{
515 struct tda9887_priv *priv = t->priv; 533 struct tda9887_priv *priv = fe->analog_demod_priv;
516 unsigned char buf[1]; 534 unsigned char buf[1];
517 int rc; 535 int rc;
518 536
519 memset(buf,0,sizeof(buf)); 537 memset(buf,0,sizeof(buf));
520 if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,buf,1))) 538 if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,buf,1)))
521 tda9887_info("i2c i/o error: rc == %d (should be 1)\n",rc); 539 tuner_info("i2c i/o error: rc == %d (should be 1)\n", rc);
522 dump_read_message(t, buf); 540 dump_read_message(fe, buf);
523 return 0; 541 return 0;
524} 542}
525 543
526static void tda9887_configure(struct tuner *t) 544static void tda9887_configure(struct dvb_frontend *fe)
527{ 545{
528 struct tda9887_priv *priv = t->priv; 546 struct tda9887_priv *priv = fe->analog_demod_priv;
529 int rc; 547 int rc;
530 548
531 memset(priv->data,0,sizeof(priv->data)); 549 memset(priv->data,0,sizeof(priv->data));
532 tda9887_set_tvnorm(t,priv->data); 550 tda9887_set_tvnorm(fe);
533 551
534 /* A note on the port settings: 552 /* A note on the port settings:
535 These settings tend to depend on the specifics of the board. 553 These settings tend to depend on the specifics of the board.
@@ -547,38 +565,38 @@ static void tda9887_configure(struct tuner *t)
547 priv->data[1] |= cOutputPort1Inactive; 565 priv->data[1] |= cOutputPort1Inactive;
548 priv->data[1] |= cOutputPort2Inactive; 566 priv->data[1] |= cOutputPort2Inactive;
549 567
550 tda9887_set_config(t,priv->data); 568 tda9887_do_config(fe);
551 tda9887_set_insmod(t,priv->data); 569 tda9887_set_insmod(fe);
552 570
553 if (t->mode == T_STANDBY) { 571 if (priv->mode == T_STANDBY)
554 priv->data[1] |= cForcedMuteAudioON; 572 priv->data[1] |= cForcedMuteAudioON;
555 }
556 573
557 tda9887_dbg("writing: b=0x%02x c=0x%02x e=0x%02x\n", 574 tuner_dbg("writing: b=0x%02x c=0x%02x e=0x%02x\n",
558 priv->data[1],priv->data[2],priv->data[3]); 575 priv->data[1], priv->data[2], priv->data[3]);
559 if (tuner_debug > 1) 576 if (debug > 1)
560 dump_write_message(t, priv->data); 577 dump_write_message(fe, priv->data);
561 578
562 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,priv->data,4))) 579 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,priv->data,4)))
563 tda9887_info("i2c i/o error: rc == %d (should be 4)\n",rc); 580 tuner_info("i2c i/o error: rc == %d (should be 4)\n", rc);
564 581
565 if (tuner_debug > 2) { 582 if (debug > 2) {
566 msleep_interruptible(1000); 583 msleep_interruptible(1000);
567 tda9887_status(t); 584 tda9887_status(fe);
568 } 585 }
569} 586}
570 587
571/* ---------------------------------------------------------------------- */ 588/* ---------------------------------------------------------------------- */
572 589
573static void tda9887_tuner_status(struct tuner *t) 590static void tda9887_tuner_status(struct dvb_frontend *fe)
574{ 591{
575 struct tda9887_priv *priv = t->priv; 592 struct tda9887_priv *priv = fe->analog_demod_priv;
576 tda9887_info("Data bytes: b=0x%02x c=0x%02x e=0x%02x\n", priv->data[1], priv->data[2], priv->data[3]); 593 tuner_info("Data bytes: b=0x%02x c=0x%02x e=0x%02x\n",
594 priv->data[1], priv->data[2], priv->data[3]);
577} 595}
578 596
579static int tda9887_get_afc(struct tuner *t) 597static int tda9887_get_afc(struct dvb_frontend *fe)
580{ 598{
581 struct tda9887_priv *priv = t->priv; 599 struct tda9887_priv *priv = fe->analog_demod_priv;
582 static int AFC_BITS_2_kHz[] = { 600 static int AFC_BITS_2_kHz[] = {
583 -12500, -37500, -62500, -97500, 601 -12500, -37500, -62500, -97500,
584 -112500, -137500, -162500, -187500, 602 -112500, -137500, -162500, -187500,
@@ -594,52 +612,79 @@ static int tda9887_get_afc(struct tuner *t)
594 return afc; 612 return afc;
595} 613}
596 614
597static void tda9887_standby(struct tuner *t) 615static void tda9887_standby(struct dvb_frontend *fe)
616{
617 struct tda9887_priv *priv = fe->analog_demod_priv;
618
619 priv->mode = T_STANDBY;
620
621 tda9887_configure(fe);
622}
623
624static void tda9887_set_params(struct dvb_frontend *fe,
625 struct analog_parameters *params)
598{ 626{
599 tda9887_configure(t); 627 struct tda9887_priv *priv = fe->analog_demod_priv;
628
629 priv->mode = params->mode;
630 priv->audmode = params->audmode;
631 priv->std = params->std;
632 tda9887_configure(fe);
600} 633}
601 634
602static void tda9887_set_freq(struct tuner *t, unsigned int freq) 635static int tda9887_set_config(struct dvb_frontend *fe, void *priv_cfg)
603{ 636{
604 tda9887_configure(t); 637 struct tda9887_priv *priv = fe->analog_demod_priv;
638
639 priv->config = *(unsigned int *)priv_cfg;
640 tda9887_configure(fe);
641
642 return 0;
605} 643}
606 644
607static void tda9887_release(struct tuner *t) 645static void tda9887_release(struct dvb_frontend *fe)
608{ 646{
609 kfree(t->priv); 647 kfree(fe->analog_demod_priv);
610 t->priv = NULL; 648 fe->analog_demod_priv = NULL;
611} 649}
612 650
613static struct tuner_operations tda9887_tuner_ops = { 651static struct analog_demod_ops tda9887_ops = {
614 .set_tv_freq = tda9887_set_freq, 652 .info = {
615 .set_radio_freq = tda9887_set_freq, 653 .name = "tda9887",
654 },
655 .set_params = tda9887_set_params,
616 .standby = tda9887_standby, 656 .standby = tda9887_standby,
617 .tuner_status = tda9887_tuner_status, 657 .tuner_status = tda9887_tuner_status,
618 .get_afc = tda9887_get_afc, 658 .get_afc = tda9887_get_afc,
619 .release = tda9887_release, 659 .release = tda9887_release,
660 .set_config = tda9887_set_config,
620}; 661};
621 662
622int tda9887_tuner_init(struct tuner *t) 663struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
664 struct i2c_adapter *i2c_adap,
665 u8 i2c_addr)
623{ 666{
624 struct tda9887_priv *priv = NULL; 667 struct tda9887_priv *priv = NULL;
625 668
626 priv = kzalloc(sizeof(struct tda9887_priv), GFP_KERNEL); 669 priv = kzalloc(sizeof(struct tda9887_priv), GFP_KERNEL);
627 if (priv == NULL) 670 if (priv == NULL)
628 return -ENOMEM; 671 return NULL;
629 t->priv = priv; 672 fe->analog_demod_priv = priv;
630
631 priv->i2c_props.addr = t->i2c.addr;
632 priv->i2c_props.adap = t->i2c.adapter;
633 673
634 strlcpy(t->i2c.name, "tda9887", sizeof(t->i2c.name)); 674 priv->i2c_props.addr = i2c_addr;
675 priv->i2c_props.adap = i2c_adap;
676 priv->mode = T_STANDBY;
635 677
636 tda9887_info("tda988[5/6/7] found @ 0x%x (%s)\n", t->i2c.addr, 678 tuner_info("tda988[5/6/7] found\n");
637 t->i2c.driver->driver.name);
638 679
639 memcpy(&t->ops, &tda9887_tuner_ops, sizeof(struct tuner_operations)); 680 memcpy(&fe->ops.analog_ops, &tda9887_ops,
681 sizeof(struct analog_demod_ops));
640 682
641 return 0; 683 return fe;
642} 684}
685EXPORT_SYMBOL_GPL(tda9887_attach);
686
687MODULE_LICENSE("GPL");
643 688
644/* 689/*
645 * Overrides for Emacs so that we follow Linus's tabbing style. 690 * Overrides for Emacs so that we follow Linus's tabbing style.
diff --git a/drivers/media/video/tda9887.h b/drivers/media/video/tda9887.h
new file mode 100644
index 000000000000..8f873a8e6ed2
--- /dev/null
+++ b/drivers/media/video/tda9887.h
@@ -0,0 +1,38 @@
1/*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15*/
16
17#ifndef __TDA9887_H__
18#define __TDA9887_H__
19
20#include <linux/i2c.h>
21#include "dvb_frontend.h"
22
23/* ------------------------------------------------------------------------ */
24#if defined(CONFIG_TUNER_TDA9887) || (defined(CONFIG_TUNER_TDA9887_MODULE) && defined(MODULE))
25extern struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
26 struct i2c_adapter *i2c_adap,
27 u8 i2c_addr);
28#else
29static inline struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
30 struct i2c_adapter *i2c_adap,
31 u8 i2c_addr)
32{
33 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
34 return NULL;
35}
36#endif
37
38#endif /* __TDA9887_H__ */
diff --git a/drivers/media/video/tea5761.c b/drivers/media/video/tea5761.c
index 2150222a3860..5326eeceaacd 100644
--- a/drivers/media/video/tea5761.c
+++ b/drivers/media/video/tea5761.c
@@ -18,7 +18,7 @@ static int debug = 0;
18module_param(debug, int, 0644); 18module_param(debug, int, 0644);
19MODULE_PARM_DESC(debug, "enable verbose debug messages"); 19MODULE_PARM_DESC(debug, "enable verbose debug messages");
20 20
21#define PREFIX "tea5761 " 21#define PREFIX "tea5761"
22 22
23struct tea5761_priv { 23struct tea5761_priv {
24 struct tuner_i2c_props i2c_props; 24 struct tuner_i2c_props i2c_props;
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
index 71df419df7bc..e1b48d87e7b7 100644
--- a/drivers/media/video/tea5767.c
+++ b/drivers/media/video/tea5767.c
@@ -20,12 +20,14 @@ static int debug = 0;
20module_param(debug, int, 0644); 20module_param(debug, int, 0644);
21MODULE_PARM_DESC(debug, "enable verbose debug messages"); 21MODULE_PARM_DESC(debug, "enable verbose debug messages");
22 22
23#define PREFIX "tea5767 " 23#define PREFIX "tea5767"
24 24
25struct tea5767_priv { 25/*****************************************************************************/
26 struct tuner_i2c_props i2c_props;
27 26
28 u32 frequency; 27struct tea5767_priv {
28 struct tuner_i2c_props i2c_props;
29 u32 frequency;
30 struct tea5767_ctrl ctrl;
29}; 31};
30 32
31/*****************************************************************************/ 33/*****************************************************************************/
@@ -127,17 +129,10 @@ struct tea5767_priv {
127/* Reserved for future extensions */ 129/* Reserved for future extensions */
128#define TEA5767_RESERVED_MASK 0xff 130#define TEA5767_RESERVED_MASK 0xff
129 131
130enum tea5767_xtal_freq {
131 TEA5767_LOW_LO_32768 = 0,
132 TEA5767_HIGH_LO_32768 = 1,
133 TEA5767_LOW_LO_13MHz = 2,
134 TEA5767_HIGH_LO_13MHz = 3,
135};
136
137
138/*****************************************************************************/ 132/*****************************************************************************/
139 133
140static void tea5767_status_dump(unsigned char *buffer) 134static void tea5767_status_dump(struct tea5767_priv *priv,
135 unsigned char *buffer)
141{ 136{
142 unsigned int div, frq; 137 unsigned int div, frq;
143 138
@@ -153,7 +148,7 @@ static void tea5767_status_dump(unsigned char *buffer)
153 148
154 div = ((buffer[0] & 0x3f) << 8) | buffer[1]; 149 div = ((buffer[0] & 0x3f) << 8) | buffer[1];
155 150
156 switch (TEA5767_HIGH_LO_32768) { 151 switch (priv->ctrl.xtal_freq) {
157 case TEA5767_HIGH_LO_13MHz: 152 case TEA5767_HIGH_LO_13MHz:
158 frq = (div * 50000 - 700000 - 225000) / 4; /* Freq in KHz */ 153 frq = (div * 50000 - 700000 - 225000) / 4; /* Freq in KHz */
159 break; 154 break;
@@ -202,13 +197,10 @@ static int set_radio_freq(struct dvb_frontend *fe,
202 197
203 tuner_dbg("radio freq = %d.%03d MHz\n", frq/16000,(frq/16)%1000); 198 tuner_dbg("radio freq = %d.%03d MHz\n", frq/16000,(frq/16)%1000);
204 199
205 /* Rounds freq to next decimal value - for 62.5 KHz step */ 200 buffer[2] = 0;
206 /* frq = 20*(frq/16)+radio_frq[frq%16]; */
207 201
208 buffer[2] = TEA5767_PORT1_HIGH; 202 if (priv->ctrl.port1)
209 buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL | 203 buffer[2] |= TEA5767_PORT1_HIGH;
210 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND;
211 buffer[4] = 0;
212 204
213 if (params->audmode == V4L2_TUNER_MODE_MONO) { 205 if (params->audmode == V4L2_TUNER_MODE_MONO) {
214 tuner_dbg("TEA5767 set to mono\n"); 206 tuner_dbg("TEA5767 set to mono\n");
@@ -217,18 +209,45 @@ static int set_radio_freq(struct dvb_frontend *fe,
217 tuner_dbg("TEA5767 set to stereo\n"); 209 tuner_dbg("TEA5767 set to stereo\n");
218 } 210 }
219 211
220 /* Should be replaced */ 212
221 switch (TEA5767_HIGH_LO_32768) { 213 buffer[3] = 0;
214
215 if (priv->ctrl.port2)
216 buffer[3] |= TEA5767_PORT2_HIGH;
217
218 if (priv->ctrl.high_cut)
219 buffer[3] |= TEA5767_HIGH_CUT_CTRL;
220
221 if (priv->ctrl.st_noise)
222 buffer[3] |= TEA5767_ST_NOISE_CTL;
223
224 if (priv->ctrl.soft_mute)
225 buffer[3] |= TEA5767_SOFT_MUTE;
226
227 if (priv->ctrl.japan_band)
228 buffer[3] |= TEA5767_JAPAN_BAND;
229
230 buffer[4] = 0;
231
232 if (priv->ctrl.deemph_75)
233 buffer[4] |= TEA5767_DEEMPH_75;
234
235 if (priv->ctrl.pllref)
236 buffer[4] |= TEA5767_PLLREF_ENABLE;
237
238
239 /* Rounds freq to next decimal value - for 62.5 KHz step */
240 /* frq = 20*(frq/16)+radio_frq[frq%16]; */
241
242 switch (priv->ctrl.xtal_freq) {
222 case TEA5767_HIGH_LO_13MHz: 243 case TEA5767_HIGH_LO_13MHz:
223 tuner_dbg("radio HIGH LO inject xtal @ 13 MHz\n"); 244 tuner_dbg("radio HIGH LO inject xtal @ 13 MHz\n");
224 buffer[2] |= TEA5767_HIGH_LO_INJECT; 245 buffer[2] |= TEA5767_HIGH_LO_INJECT;
225 buffer[4] |= TEA5767_PLLREF_ENABLE;
226 div = (frq * (4000 / 16) + 700000 + 225000 + 25000) / 50000; 246 div = (frq * (4000 / 16) + 700000 + 225000 + 25000) / 50000;
227 break; 247 break;
228 case TEA5767_LOW_LO_13MHz: 248 case TEA5767_LOW_LO_13MHz:
229 tuner_dbg("radio LOW LO inject xtal @ 13 MHz\n"); 249 tuner_dbg("radio LOW LO inject xtal @ 13 MHz\n");
230 250
231 buffer[4] |= TEA5767_PLLREF_ENABLE;
232 div = (frq * (4000 / 16) - 700000 - 225000 + 25000) / 50000; 251 div = (frq * (4000 / 16) - 700000 - 225000 + 25000) / 50000;
233 break; 252 break;
234 case TEA5767_LOW_LO_32768: 253 case TEA5767_LOW_LO_32768:
@@ -256,7 +275,7 @@ static int set_radio_freq(struct dvb_frontend *fe,
256 if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) 275 if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5)))
257 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 276 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
258 else 277 else
259 tea5767_status_dump(buffer); 278 tea5767_status_dump(priv, buffer);
260 } 279 }
261 280
262 priv->frequency = frq * 125 / 2; 281 priv->frequency = frq * 125 / 2;
@@ -382,7 +401,6 @@ int tea5767_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr)
382 return EINVAL; 401 return EINVAL;
383 } 402 }
384 403
385 printk(KERN_WARNING "TEA5767 detected.\n");
386 return 0; 404 return 0;
387} 405}
388 406
@@ -398,6 +416,16 @@ static int tea5767_get_frequency(struct dvb_frontend *fe, u32 *frequency)
398{ 416{
399 struct tea5767_priv *priv = fe->tuner_priv; 417 struct tea5767_priv *priv = fe->tuner_priv;
400 *frequency = priv->frequency; 418 *frequency = priv->frequency;
419
420 return 0;
421}
422
423static int tea5767_set_config (struct dvb_frontend *fe, void *priv_cfg)
424{
425 struct tea5767_priv *priv = fe->tuner_priv;
426
427 memcpy(&priv->ctrl, priv_cfg, sizeof(priv->ctrl));
428
401 return 0; 429 return 0;
402} 430}
403 431
@@ -407,6 +435,7 @@ static struct dvb_tuner_ops tea5767_tuner_ops = {
407 }, 435 },
408 436
409 .set_analog_params = set_radio_freq, 437 .set_analog_params = set_radio_freq,
438 .set_config = tea5767_set_config,
410 .sleep = tea5767_standby, 439 .sleep = tea5767_standby,
411 .release = tea5767_release, 440 .release = tea5767_release,
412 .get_frequency = tea5767_get_frequency, 441 .get_frequency = tea5767_get_frequency,
@@ -425,8 +454,14 @@ struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe,
425 return NULL; 454 return NULL;
426 fe->tuner_priv = priv; 455 fe->tuner_priv = priv;
427 456
428 priv->i2c_props.addr = i2c_addr; 457 priv->i2c_props.addr = i2c_addr;
429 priv->i2c_props.adap = i2c_adap; 458 priv->i2c_props.adap = i2c_adap;
459 priv->ctrl.xtal_freq = TEA5767_HIGH_LO_32768;
460 priv->ctrl.port1 = 1;
461 priv->ctrl.port2 = 1;
462 priv->ctrl.high_cut = 1;
463 priv->ctrl.st_noise = 1;
464 priv->ctrl.japan_band = 1;
430 465
431 memcpy(&fe->ops.tuner_ops, &tea5767_tuner_ops, 466 memcpy(&fe->ops.tuner_ops, &tea5767_tuner_ops,
432 sizeof(struct dvb_tuner_ops)); 467 sizeof(struct dvb_tuner_ops));
@@ -436,7 +471,6 @@ struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe,
436 return fe; 471 return fe;
437} 472}
438 473
439
440EXPORT_SYMBOL_GPL(tea5767_attach); 474EXPORT_SYMBOL_GPL(tea5767_attach);
441EXPORT_SYMBOL_GPL(tea5767_autodetection); 475EXPORT_SYMBOL_GPL(tea5767_autodetection);
442 476
diff --git a/drivers/media/video/tea5767.h b/drivers/media/video/tea5767.h
index 5d78281adcc2..a44451f61145 100644
--- a/drivers/media/video/tea5767.h
+++ b/drivers/media/video/tea5767.h
@@ -20,6 +20,25 @@
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include "dvb_frontend.h" 21#include "dvb_frontend.h"
22 22
23enum tea5767_xtal {
24 TEA5767_LOW_LO_32768 = 0,
25 TEA5767_HIGH_LO_32768 = 1,
26 TEA5767_LOW_LO_13MHz = 2,
27 TEA5767_HIGH_LO_13MHz = 3,
28};
29
30struct tea5767_ctrl {
31 unsigned int port1:1;
32 unsigned int port2:1;
33 unsigned int high_cut:1;
34 unsigned int st_noise:1;
35 unsigned int soft_mute:1;
36 unsigned int japan_band:1;
37 unsigned int deemph_75:1;
38 unsigned int pllref:1;
39 enum tea5767_xtal xtal_freq;
40};
41
23#if defined(CONFIG_TUNER_TEA5767) || (defined(CONFIG_TUNER_TEA5767_MODULE) && defined(MODULE)) 42#if defined(CONFIG_TUNER_TEA5767) || (defined(CONFIG_TUNER_TEA5767_MODULE) && defined(MODULE))
24extern int tea5767_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr); 43extern int tea5767_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr);
25 44
diff --git a/drivers/media/video/tlv320aic23b.c b/drivers/media/video/tlv320aic23b.c
index 76b2e96429d9..dc7b9c220b90 100644
--- a/drivers/media/video/tlv320aic23b.c
+++ b/drivers/media/video/tlv320aic23b.c
@@ -31,6 +31,7 @@
31#include <linux/i2c-id.h> 31#include <linux/i2c-id.h>
32#include <linux/videodev.h> 32#include <linux/videodev.h>
33#include <media/v4l2-common.h> 33#include <media/v4l2-common.h>
34#include <media/v4l2-i2c-drv-legacy.h>
34 35
35MODULE_DESCRIPTION("tlv320aic23b driver"); 36MODULE_DESCRIPTION("tlv320aic23b driver");
36MODULE_AUTHOR("Scott Alfter, Ulf Eklund, Hans Verkuil"); 37MODULE_AUTHOR("Scott Alfter, Ulf Eklund, Hans Verkuil");
@@ -56,37 +57,35 @@ static int tlv320aic23b_write(struct i2c_client *client, int reg, u16 val)
56 return -1; 57 return -1;
57 } 58 }
58 59
59 for (i = 0; i < 3; i++) { 60 for (i = 0; i < 3; i++)
60 if (i2c_smbus_write_byte_data(client, (reg << 1) | 61 if (i2c_smbus_write_byte_data(client,
61 (val >> 8), val & 0xff) == 0) { 62 (reg << 1) | (val >> 8), val & 0xff) == 0)
62 return 0; 63 return 0;
63 }
64 }
65 v4l_err(client, "I2C: cannot write %03x to register R%d\n", val, reg); 64 v4l_err(client, "I2C: cannot write %03x to register R%d\n", val, reg);
66 return -1; 65 return -1;
67} 66}
68 67
69static int tlv320aic23b_command(struct i2c_client *client, unsigned int cmd, 68static int tlv320aic23b_command(struct i2c_client *client,
70 void *arg) 69 unsigned int cmd, void *arg)
71{ 70{
72 struct tlv320aic23b_state *state = i2c_get_clientdata(client); 71 struct tlv320aic23b_state *state = i2c_get_clientdata(client);
73 struct v4l2_control *ctrl = arg; 72 struct v4l2_control *ctrl = arg;
74 u32* freq = arg; 73 u32 *freq = arg;
75 74
76 switch (cmd) { 75 switch (cmd) {
77 case VIDIOC_INT_AUDIO_CLOCK_FREQ: 76 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
78 switch (*freq) { 77 switch (*freq) {
79 case 32000: /* set sample rate to 32 kHz */ 78 case 32000: /* set sample rate to 32 kHz */
80 tlv320aic23b_write(client, 8, 0x018); 79 tlv320aic23b_write(client, 8, 0x018);
81 break; 80 break;
82 case 44100: /* set sample rate to 44.1 kHz */ 81 case 44100: /* set sample rate to 44.1 kHz */
83 tlv320aic23b_write(client, 8, 0x022); 82 tlv320aic23b_write(client, 8, 0x022);
84 break; 83 break;
85 case 48000: /* set sample rate to 48 kHz */ 84 case 48000: /* set sample rate to 48 kHz */
86 tlv320aic23b_write(client, 8, 0x000); 85 tlv320aic23b_write(client, 8, 0x000);
87 break; 86 break;
88 default: 87 default:
89 return -EINVAL; 88 return -EINVAL;
90 } 89 }
91 break; 90 break;
92 91
@@ -126,92 +125,53 @@ static int tlv320aic23b_command(struct i2c_client *client, unsigned int cmd,
126 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 125 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
127 */ 126 */
128 127
129static struct i2c_driver i2c_driver; 128static int tlv320aic23b_probe(struct i2c_client *client)
130
131static int tlv320aic23b_attach(struct i2c_adapter *adapter, int address, int kind)
132{ 129{
133 struct i2c_client *client;
134 struct tlv320aic23b_state *state; 130 struct tlv320aic23b_state *state;
135 131
136 /* Check if the adapter supports the needed features */ 132 /* Check if the adapter supports the needed features */
137 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 133 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
138 return 0; 134 return -EIO;
139
140 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
141 if (client == 0)
142 return -ENOMEM;
143
144 client->addr = address;
145 client->adapter = adapter;
146 client->driver = &i2c_driver;
147 snprintf(client->name, sizeof(client->name) - 1, "tlv320aic23b");
148 135
149 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name); 136 v4l_info(client, "chip found @ 0x%x (%s)\n",
137 client->addr << 1, client->adapter->name);
150 138
151 state = kmalloc(sizeof(struct tlv320aic23b_state), GFP_KERNEL); 139 state = kmalloc(sizeof(struct tlv320aic23b_state), GFP_KERNEL);
152 if (state == NULL) { 140 if (state == NULL)
153 kfree(client);
154 return -ENOMEM; 141 return -ENOMEM;
155 }
156 state->muted = 0; 142 state->muted = 0;
157 i2c_set_clientdata(client, state); 143 i2c_set_clientdata(client, state);
158 144
159 /* initialize tlv320aic23b */ 145 /* Initialize tlv320aic23b */
160 tlv320aic23b_write(client, 15, 0x000); /* RESET */ 146
161 tlv320aic23b_write(client, 6, 0x00A); /* turn off DAC & mic input */ 147 /* RESET */
162 tlv320aic23b_write(client, 7, 0x049); /* left-justified, 24-bit, master mode */ 148 tlv320aic23b_write(client, 15, 0x000);
163 tlv320aic23b_write(client, 0, 0x119); /* set gain on both channels to +3.0 dB */ 149 /* turn off DAC & mic input */
164 tlv320aic23b_write(client, 8, 0x000); /* set sample rate to 48 kHz */ 150 tlv320aic23b_write(client, 6, 0x00A);
165 tlv320aic23b_write(client, 9, 0x001); /* activate digital interface */ 151 /* left-justified, 24-bit, master mode */
166 152 tlv320aic23b_write(client, 7, 0x049);
167 i2c_attach_client(client); 153 /* set gain on both channels to +3.0 dB */
168 154 tlv320aic23b_write(client, 0, 0x119);
155 /* set sample rate to 48 kHz */
156 tlv320aic23b_write(client, 8, 0x000);
157 /* activate digital interface */
158 tlv320aic23b_write(client, 9, 0x001);
169 return 0; 159 return 0;
170} 160}
171 161
172static int tlv320aic23b_probe(struct i2c_adapter *adapter) 162static int tlv320aic23b_remove(struct i2c_client *client)
173{ 163{
174 if (adapter->class & I2C_CLASS_TV_ANALOG) 164 kfree(i2c_get_clientdata(client));
175 return i2c_probe(adapter, &addr_data, tlv320aic23b_attach);
176 return 0;
177}
178
179static int tlv320aic23b_detach(struct i2c_client *client)
180{
181 int err;
182
183 err = i2c_detach_client(client);
184 if (err) {
185 return err;
186 }
187 kfree(client);
188
189 return 0; 165 return 0;
190} 166}
191 167
192/* ----------------------------------------------------------------------- */ 168/* ----------------------------------------------------------------------- */
193 169
194/* i2c implementation */
195static struct i2c_driver i2c_driver = {
196 .driver = {
197 .name = "tlv320aic23b",
198 },
199 .id = I2C_DRIVERID_TLV320AIC23B,
200 .attach_adapter = tlv320aic23b_probe,
201 .detach_client = tlv320aic23b_detach,
202 .command = tlv320aic23b_command,
203};
204
205 170
206static int __init tlv320aic23b_init_module(void) 171static struct v4l2_i2c_driver_data v4l2_i2c_data = {
207{ 172 .name = "tlv320aic23b",
208 return i2c_add_driver(&i2c_driver); 173 .driverid = I2C_DRIVERID_TLV320AIC23B,
209} 174 .command = tlv320aic23b_command,
210 175 .probe = tlv320aic23b_probe,
211static void __exit tlv320aic23b_cleanup_module(void) 176 .remove = tlv320aic23b_remove,
212{ 177};
213 i2c_del_driver(&i2c_driver);
214}
215
216module_init(tlv320aic23b_init_module);
217module_exit(tlv320aic23b_cleanup_module);
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 9e99f3636d3d..ba538f6fbcc3 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -19,15 +19,41 @@
19#include <media/tuner.h> 19#include <media/tuner.h>
20#include <media/tuner-types.h> 20#include <media/tuner-types.h>
21#include <media/v4l2-common.h> 21#include <media/v4l2-common.h>
22#include "tuner-driver.h" 22#include <media/v4l2-i2c-drv-legacy.h>
23#include "mt20xx.h" 23#include "mt20xx.h"
24#include "tda8290.h" 24#include "tda8290.h"
25#include "tea5761.h" 25#include "tea5761.h"
26#include "tea5767.h" 26#include "tea5767.h"
27#include "tuner-xc2028.h"
27#include "tuner-simple.h" 28#include "tuner-simple.h"
29#include "tda9887.h"
30#include "xc5000.h"
28 31
29#define UNSET (-1U) 32#define UNSET (-1U)
30 33
34#define PREFIX t->i2c->driver->driver.name
35
36struct tuner {
37 /* device */
38 struct dvb_frontend fe;
39 struct i2c_client *i2c;
40 struct list_head list;
41 unsigned int using_v4l2:1;
42
43 /* keep track of the current settings */
44 v4l2_std_id std;
45 unsigned int tv_freq;
46 unsigned int radio_freq;
47 unsigned int audmode;
48
49 unsigned int mode;
50 unsigned int mode_mask; /* Combination of allowable modes */
51
52 unsigned int type; /* chip type id */
53 unsigned int config;
54 int (*tuner_callback) (void *dev, int command, int arg);
55};
56
31/* standard i2c insmod options */ 57/* standard i2c insmod options */
32static unsigned short normal_i2c[] = { 58static unsigned short normal_i2c[] = {
33#if defined(CONFIG_TUNER_TEA5761) || (defined(CONFIG_TUNER_TEA5761_MODULE) && defined(MODULE)) 59#if defined(CONFIG_TUNER_TEA5761) || (defined(CONFIG_TUNER_TEA5761_MODULE) && defined(MODULE))
@@ -47,7 +73,34 @@ static unsigned int no_autodetect = 0;
47static unsigned int show_i2c = 0; 73static unsigned int show_i2c = 0;
48 74
49/* insmod options used at runtime => read/write */ 75/* insmod options used at runtime => read/write */
50int tuner_debug = 0; 76static int tuner_debug;
77
78#define tuner_warn(fmt, arg...) do { \
79 printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \
80 i2c_adapter_id(t->i2c->adapter), \
81 t->i2c->addr, ##arg); \
82 } while (0)
83
84#define tuner_info(fmt, arg...) do { \
85 printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \
86 i2c_adapter_id(t->i2c->adapter), \
87 t->i2c->addr, ##arg); \
88 } while (0)
89
90#define tuner_err(fmt, arg...) do { \
91 printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \
92 i2c_adapter_id(t->i2c->adapter), \
93 t->i2c->addr, ##arg); \
94 } while (0)
95
96#define tuner_dbg(fmt, arg...) do { \
97 if (tuner_debug) \
98 printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \
99 i2c_adapter_id(t->i2c->adapter), \
100 t->i2c->addr, ##arg); \
101 } while (0)
102
103/* ------------------------------------------------------------------------ */
51 104
52static unsigned int tv_range[2] = { 44, 958 }; 105static unsigned int tv_range[2] = { 44, 958 };
53static unsigned int radio_range[2] = { 65, 108 }; 106static unsigned int radio_range[2] = { 65, 108 };
@@ -71,66 +124,96 @@ MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
71MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer"); 124MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
72MODULE_LICENSE("GPL"); 125MODULE_LICENSE("GPL");
73 126
74static struct i2c_driver driver;
75static struct i2c_client client_template;
76
77/* ---------------------------------------------------------------------- */ 127/* ---------------------------------------------------------------------- */
78 128
79static void fe_set_freq(struct tuner *t, unsigned int freq) 129static void fe_set_params(struct dvb_frontend *fe,
130 struct analog_parameters *params)
80{ 131{
81 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; 132 struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
82 133 struct tuner *t = fe->analog_demod_priv;
83 struct analog_parameters params = {
84 .frequency = freq,
85 .mode = t->mode,
86 .audmode = t->audmode,
87 .std = t->std
88 };
89 134
90 if (NULL == fe_tuner_ops->set_analog_params) { 135 if (NULL == fe_tuner_ops->set_analog_params) {
91 tuner_warn("Tuner frontend module has no way to set freq\n"); 136 tuner_warn("Tuner frontend module has no way to set freq\n");
92 return; 137 return;
93 } 138 }
94 fe_tuner_ops->set_analog_params(&t->fe, &params); 139 fe_tuner_ops->set_analog_params(fe, params);
95} 140}
96 141
97static void fe_release(struct tuner *t) 142static void fe_release(struct dvb_frontend *fe)
98{ 143{
99 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; 144 if (fe->ops.tuner_ops.release)
100 145 fe->ops.tuner_ops.release(fe);
101 if (fe_tuner_ops->release) 146
102 fe_tuner_ops->release(&t->fe); 147 /* DO NOT kfree(fe->analog_demod_priv)
148 *
149 * If we are in this function, analog_demod_priv contains a pointer
150 * to struct tuner *t. This will be kfree'd in tuner_detach().
151 *
152 * Otherwise, fe->ops.analog_demod_ops->release will
153 * handle the cleanup for analog demodulator modules.
154 */
155 fe->analog_demod_priv = NULL;
103} 156}
104 157
105static void fe_standby(struct tuner *t) 158static void fe_standby(struct dvb_frontend *fe)
106{ 159{
107 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; 160 struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
108 161
109 if (fe_tuner_ops->sleep) 162 if (fe_tuner_ops->sleep)
110 fe_tuner_ops->sleep(&t->fe); 163 fe_tuner_ops->sleep(fe);
111} 164}
112 165
113static int fe_has_signal(struct tuner *t) 166static int fe_has_signal(struct dvb_frontend *fe)
114{ 167{
115 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
116 u16 strength = 0; 168 u16 strength = 0;
117 169
118 if (fe_tuner_ops->get_rf_strength) 170 if (fe->ops.tuner_ops.get_rf_strength)
119 fe_tuner_ops->get_rf_strength(&t->fe, &strength); 171 fe->ops.tuner_ops.get_rf_strength(fe, &strength);
120 172
121 return strength; 173 return strength;
122} 174}
123 175
176static int fe_set_config(struct dvb_frontend *fe, void *priv_cfg)
177{
178 struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
179 struct tuner *t = fe->analog_demod_priv;
180
181 if (fe_tuner_ops->set_config)
182 return fe_tuner_ops->set_config(fe, priv_cfg);
183
184 tuner_warn("Tuner frontend module has no way to set config\n");
185
186 return 0;
187}
188
189static void tuner_status(struct dvb_frontend *fe);
190
191static struct analog_demod_ops tuner_core_ops = {
192 .set_params = fe_set_params,
193 .standby = fe_standby,
194 .release = fe_release,
195 .has_signal = fe_has_signal,
196 .set_config = fe_set_config,
197 .tuner_status = tuner_status
198};
199
124/* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */ 200/* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */
125static void set_tv_freq(struct i2c_client *c, unsigned int freq) 201static void set_tv_freq(struct i2c_client *c, unsigned int freq)
126{ 202{
127 struct tuner *t = i2c_get_clientdata(c); 203 struct tuner *t = i2c_get_clientdata(c);
204 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
205
206 struct analog_parameters params = {
207 .mode = t->mode,
208 .audmode = t->audmode,
209 .std = t->std
210 };
128 211
129 if (t->type == UNSET) { 212 if (t->type == UNSET) {
130 tuner_warn ("tuner type not set\n"); 213 tuner_warn ("tuner type not set\n");
131 return; 214 return;
132 } 215 }
133 if (NULL == t->ops.set_tv_freq) { 216 if (NULL == analog_ops->set_params) {
134 tuner_warn ("Tuner has no way to set tv freq\n"); 217 tuner_warn ("Tuner has no way to set tv freq\n");
135 return; 218 return;
136 } 219 }
@@ -145,18 +228,27 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
145 else 228 else
146 freq = tv_range[1] * 16; 229 freq = tv_range[1] * 16;
147 } 230 }
148 t->ops.set_tv_freq(t, freq); 231 params.frequency = freq;
232
233 analog_ops->set_params(&t->fe, &params);
149} 234}
150 235
151static void set_radio_freq(struct i2c_client *c, unsigned int freq) 236static void set_radio_freq(struct i2c_client *c, unsigned int freq)
152{ 237{
153 struct tuner *t = i2c_get_clientdata(c); 238 struct tuner *t = i2c_get_clientdata(c);
239 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
240
241 struct analog_parameters params = {
242 .mode = t->mode,
243 .audmode = t->audmode,
244 .std = t->std
245 };
154 246
155 if (t->type == UNSET) { 247 if (t->type == UNSET) {
156 tuner_warn ("tuner type not set\n"); 248 tuner_warn ("tuner type not set\n");
157 return; 249 return;
158 } 250 }
159 if (NULL == t->ops.set_radio_freq) { 251 if (NULL == analog_ops->set_params) {
160 tuner_warn ("tuner has no way to set radio frequency\n"); 252 tuner_warn ("tuner has no way to set radio frequency\n");
161 return; 253 return;
162 } 254 }
@@ -171,8 +263,9 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
171 else 263 else
172 freq = radio_range[1] * 16000; 264 freq = radio_range[1] * 16000;
173 } 265 }
266 params.frequency = freq;
174 267
175 t->ops.set_radio_freq(t, freq); 268 analog_ops->set_params(&t->fe, &params);
176} 269}
177 270
178static void set_freq(struct i2c_client *c, unsigned long freq) 271static void set_freq(struct i2c_client *c, unsigned long freq)
@@ -193,54 +286,65 @@ static void set_freq(struct i2c_client *c, unsigned long freq)
193 set_tv_freq(c, freq); 286 set_tv_freq(c, freq);
194 t->tv_freq = freq; 287 t->tv_freq = freq;
195 break; 288 break;
289 default:
290 tuner_dbg("freq set: unknown mode: 0x%04x!\n",t->mode);
196 } 291 }
197} 292}
198 293
199static void tuner_i2c_address_check(struct tuner *t) 294static void tuner_i2c_address_check(struct tuner *t)
200{ 295{
201 if ((t->type == UNSET || t->type == TUNER_ABSENT) || 296 if ((t->type == UNSET || t->type == TUNER_ABSENT) ||
202 ((t->i2c.addr < 0x64) || (t->i2c.addr > 0x6f))) 297 ((t->i2c->addr < 0x64) || (t->i2c->addr > 0x6f)))
298 return;
299
300 /* We already know that the XC5000 can only be located at
301 * i2c address 0x61, 0x62, 0x63 or 0x64 */
302 if ((t->type == TUNER_XC5000) &&
303 ((t->i2c->addr <= 0x64)) && (t->i2c->addr >= 0x61))
203 return; 304 return;
204 305
205 tuner_warn("====================== WARNING! ======================\n"); 306 tuner_warn("====================== WARNING! ======================\n");
206 tuner_warn("Support for tuners in i2c address range 0x64 thru 0x6f\n"); 307 tuner_warn("Support for tuners in i2c address range 0x64 thru 0x6f\n");
207 tuner_warn("will soon be dropped. This message indicates that your\n"); 308 tuner_warn("will soon be dropped. This message indicates that your\n");
208 tuner_warn("hardware has a %s tuner at i2c address 0x%02x.\n", 309 tuner_warn("hardware has a %s tuner at i2c address 0x%02x.\n",
209 t->i2c.name, t->i2c.addr); 310 t->i2c->name, t->i2c->addr);
210 tuner_warn("To ensure continued support for your device, please\n"); 311 tuner_warn("To ensure continued support for your device, please\n");
211 tuner_warn("send a copy of this message, along with full dmesg\n"); 312 tuner_warn("send a copy of this message, along with full dmesg\n");
212 tuner_warn("output to v4l-dvb-maintainer@linuxtv.org\n"); 313 tuner_warn("output to v4l-dvb-maintainer@linuxtv.org\n");
213 tuner_warn("Please use subject line: \"obsolete tuner i2c address.\"\n"); 314 tuner_warn("Please use subject line: \"obsolete tuner i2c address.\"\n");
214 tuner_warn("driver: %s, addr: 0x%02x, type: %d (%s)\n", 315 tuner_warn("driver: %s, addr: 0x%02x, type: %d (%s)\n",
215 t->i2c.adapter->name, t->i2c.addr, t->type, 316 t->i2c->adapter->name, t->i2c->addr, t->type,
216 tuners[t->type].name); 317 tuners[t->type].name);
217 tuner_warn("====================== WARNING! ======================\n"); 318 tuner_warn("====================== WARNING! ======================\n");
218} 319}
219 320
220static void attach_tda8290(struct tuner *t)
221{
222 struct tda8290_config cfg = {
223 .lna_cfg = &t->config,
224 .tuner_callback = t->tuner_callback
225 };
226 tda8290_attach(&t->fe, t->i2c.adapter, t->i2c.addr, &cfg);
227}
228
229static void attach_simple_tuner(struct tuner *t) 321static void attach_simple_tuner(struct tuner *t)
230{ 322{
231 struct simple_tuner_config cfg = { 323 struct simple_tuner_config cfg = {
232 .type = t->type, 324 .type = t->type,
233 .tun = &tuners[t->type] 325 .tun = &tuners[t->type]
234 }; 326 };
235 simple_tuner_attach(&t->fe, t->i2c.adapter, t->i2c.addr, &cfg); 327 simple_tuner_attach(&t->fe, t->i2c->adapter, t->i2c->addr, &cfg);
236} 328}
237 329
330static void attach_tda829x(struct tuner *t)
331{
332 struct tda829x_config cfg = {
333 .lna_cfg = &t->config,
334 .tuner_callback = t->tuner_callback,
335 };
336 tda829x_attach(&t->fe, t->i2c->adapter, t->i2c->addr, &cfg);
337}
338
339static struct xc5000_config xc5000_cfg;
340
238static void set_type(struct i2c_client *c, unsigned int type, 341static void set_type(struct i2c_client *c, unsigned int type,
239 unsigned int new_mode_mask, unsigned int new_config, 342 unsigned int new_mode_mask, unsigned int new_config,
240 int (*tuner_callback) (void *dev, int command,int arg)) 343 int (*tuner_callback) (void *dev, int command,int arg))
241{ 344{
242 struct tuner *t = i2c_get_clientdata(c); 345 struct tuner *t = i2c_get_clientdata(c);
243 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; 346 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
347 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
244 unsigned char buffer[4]; 348 unsigned char buffer[4];
245 349
246 if (type == UNSET || type == TUNER_ABSENT) { 350 if (type == UNSET || type == TUNER_ABSENT) {
@@ -260,32 +364,27 @@ static void set_type(struct i2c_client *c, unsigned int type,
260 t->tuner_callback = tuner_callback; 364 t->tuner_callback = tuner_callback;
261 } 365 }
262 366
263 /* This code detects calls by card attach_inform */ 367 if (t->mode == T_UNINITIALIZED) {
264 if (NULL == t->i2c.dev.driver) {
265 tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c->addr); 368 tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c->addr);
266 369
267 return; 370 return;
268 } 371 }
269 372
270 /* discard private data, in case set_type() was previously called */ 373 /* discard private data, in case set_type() was previously called */
271 if (t->ops.release) 374 if (analog_ops->release)
272 t->ops.release(t); 375 analog_ops->release(&t->fe);
273 else {
274 kfree(t->priv);
275 t->priv = NULL;
276 }
277 376
278 switch (t->type) { 377 switch (t->type) {
279 case TUNER_MT2032: 378 case TUNER_MT2032:
280 microtune_attach(&t->fe, t->i2c.adapter, t->i2c.addr); 379 microtune_attach(&t->fe, t->i2c->adapter, t->i2c->addr);
281 break; 380 break;
282 case TUNER_PHILIPS_TDA8290: 381 case TUNER_PHILIPS_TDA8290:
283 { 382 {
284 attach_tda8290(t); 383 attach_tda829x(t);
285 break; 384 break;
286 } 385 }
287 case TUNER_TEA5767: 386 case TUNER_TEA5767:
288 if (tea5767_attach(&t->fe, t->i2c.adapter, t->i2c.addr) == NULL) { 387 if (tea5767_attach(&t->fe, t->i2c->adapter, t->i2c->addr) == NULL) {
289 t->type = TUNER_ABSENT; 388 t->type = TUNER_ABSENT;
290 t->mode_mask = T_UNINITIALIZED; 389 t->mode_mask = T_UNINITIALIZED;
291 return; 390 return;
@@ -293,7 +392,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
293 t->mode_mask = T_RADIO; 392 t->mode_mask = T_RADIO;
294 break; 393 break;
295 case TUNER_TEA5761: 394 case TUNER_TEA5761:
296 if (tea5761_attach(&t->fe, t->i2c.adapter, t->i2c.addr) == NULL) { 395 if (tea5761_attach(&t->fe, t->i2c->adapter, t->i2c->addr) == NULL) {
297 t->type = TUNER_ABSENT; 396 t->type = TUNER_ABSENT;
298 t->mode_mask = T_UNINITIALIZED; 397 t->mode_mask = T_UNINITIALIZED;
299 return; 398 return;
@@ -320,25 +419,60 @@ static void set_type(struct i2c_client *c, unsigned int type,
320 i2c_master_send(c,buffer,4); 419 i2c_master_send(c,buffer,4);
321 attach_simple_tuner(t); 420 attach_simple_tuner(t);
322 break; 421 break;
422 case TUNER_XC2028:
423 {
424 struct xc2028_config cfg = {
425 .i2c_adap = t->i2c->adapter,
426 .i2c_addr = t->i2c->addr,
427 .video_dev = c->adapter->algo_data,
428 .callback = t->tuner_callback,
429 };
430 if (!xc2028_attach(&t->fe, &cfg)) {
431 t->type = TUNER_ABSENT;
432 t->mode_mask = T_UNINITIALIZED;
433 return;
434 }
435 break;
436 }
323 case TUNER_TDA9887: 437 case TUNER_TDA9887:
324 tda9887_tuner_init(t); 438 tda9887_attach(&t->fe, t->i2c->adapter, t->i2c->addr);
439 break;
440 case TUNER_XC5000:
441 xc5000_cfg.i2c_address = t->i2c->addr;
442 xc5000_cfg.if_khz = 5380;
443 xc5000_cfg.priv = c->adapter->algo_data;
444 xc5000_cfg.tuner_callback = t->tuner_callback;
445 if (!xc5000_attach(&t->fe, t->i2c->adapter, &xc5000_cfg)) {
446 t->type = TUNER_ABSENT;
447 t->mode_mask = T_UNINITIALIZED;
448 return;
449 }
450 {
451 struct dvb_tuner_ops *xc_tuner_ops;
452 xc_tuner_ops = &t->fe.ops.tuner_ops;
453 if(xc_tuner_ops->init != NULL)
454 xc_tuner_ops->init(&t->fe);
455 }
325 break; 456 break;
326 default: 457 default:
327 attach_simple_tuner(t); 458 attach_simple_tuner(t);
328 break; 459 break;
329 } 460 }
330 461
331 if (fe_tuner_ops->set_analog_params) { 462 if ((NULL == analog_ops->set_params) &&
332 strlcpy(t->i2c.name, fe_tuner_ops->info.name, sizeof(t->i2c.name)); 463 (fe_tuner_ops->set_analog_params)) {
464 strlcpy(t->i2c->name, fe_tuner_ops->info.name,
465 sizeof(t->i2c->name));
333 466
334 t->ops.set_tv_freq = fe_set_freq; 467 t->fe.analog_demod_priv = t;
335 t->ops.set_radio_freq = fe_set_freq; 468 memcpy(analog_ops, &tuner_core_ops,
336 t->ops.standby = fe_standby; 469 sizeof(struct analog_demod_ops));
337 t->ops.release = fe_release; 470 } else {
338 t->ops.has_signal = fe_has_signal; 471 strlcpy(t->i2c->name, analog_ops->info.name,
472 sizeof(t->i2c->name));
339 } 473 }
340 474
341 tuner_info("type set to %s\n", t->i2c.name); 475 tuner_dbg("type set to %s\n", t->i2c->name);
342 476
343 if (t->mode_mask == T_UNINITIALIZED) 477 if (t->mode_mask == T_UNINITIALIZED)
344 t->mode_mask = new_mode_mask; 478 t->mode_mask = new_mode_mask;
@@ -508,10 +642,12 @@ static int tuner_fixup_std(struct tuner *t)
508 return 0; 642 return 0;
509} 643}
510 644
511static void tuner_status(struct tuner *t) 645static void tuner_status(struct dvb_frontend *fe)
512{ 646{
647 struct tuner *t = fe->analog_demod_priv;
513 unsigned long freq, freq_fraction; 648 unsigned long freq, freq_fraction;
514 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; 649 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
650 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
515 const char *p; 651 const char *p;
516 652
517 switch (t->mode) { 653 switch (t->mode) {
@@ -541,172 +677,16 @@ static void tuner_status(struct tuner *t)
541 if (tuner_status & TUNER_STATUS_STEREO) 677 if (tuner_status & TUNER_STATUS_STEREO)
542 tuner_info("Stereo: yes\n"); 678 tuner_info("Stereo: yes\n");
543 } 679 }
544 if (t->ops.has_signal) { 680 if (analog_ops->has_signal)
545 tuner_info("Signal strength: %d\n", t->ops.has_signal(t)); 681 tuner_info("Signal strength: %d\n",
546 } 682 analog_ops->has_signal(fe));
547 if (t->ops.is_stereo) { 683 if (analog_ops->is_stereo)
548 tuner_info("Stereo: %s\n", t->ops.is_stereo(t) ? "yes" : "no"); 684 tuner_info("Stereo: %s\n",
549 } 685 analog_ops->is_stereo(fe) ? "yes" : "no");
550} 686}
551 687
552/* ---------------------------------------------------------------------- */ 688/* ---------------------------------------------------------------------- */
553 689
554/* static vars: used only in tuner_attach and tuner_probe */
555static unsigned default_mode_mask;
556
557/* During client attach, set_type is called by adapter's attach_inform callback.
558 set_type must then be completed by tuner_attach.
559 */
560static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
561{
562 struct tuner *t;
563
564 client_template.adapter = adap;
565 client_template.addr = addr;
566
567 t = kzalloc(sizeof(struct tuner), GFP_KERNEL);
568 if (NULL == t)
569 return -ENOMEM;
570 memcpy(&t->i2c, &client_template, sizeof(struct i2c_client));
571 i2c_set_clientdata(&t->i2c, t);
572 t->type = UNSET;
573 t->audmode = V4L2_TUNER_MODE_STEREO;
574 t->mode_mask = T_UNINITIALIZED;
575 t->ops.tuner_status = tuner_status;
576
577 if (show_i2c) {
578 unsigned char buffer[16];
579 int i,rc;
580
581 memset(buffer, 0, sizeof(buffer));
582 rc = i2c_master_recv(&t->i2c, buffer, sizeof(buffer));
583 tuner_info("I2C RECV = ");
584 for (i=0;i<rc;i++)
585 printk("%02x ",buffer[i]);
586 printk("\n");
587 }
588 /* HACK: This test were added to avoid tuner to probe tda9840 and tea6415c on the MXB card */
589 if (adap->id == I2C_HW_SAA7146 && addr < 0x4a)
590 return -ENODEV;
591
592 /* autodetection code based on the i2c addr */
593 if (!no_autodetect) {
594 switch (addr) {
595 case 0x10:
596 if (tea5761_autodetection(t->i2c.adapter, t->i2c.addr) != EINVAL) {
597 t->type = TUNER_TEA5761;
598 t->mode_mask = T_RADIO;
599 t->mode = T_STANDBY;
600 t->radio_freq = 87.5 * 16000; /* Sets freq to FM range */
601 default_mode_mask &= ~T_RADIO;
602
603 goto register_client;
604 }
605 break;
606 case 0x42:
607 case 0x43:
608 case 0x4a:
609 case 0x4b:
610 /* If chip is not tda8290, don't register.
611 since it can be tda9887*/
612 if (tda8290_probe(t->i2c.adapter, t->i2c.addr) == 0) {
613 tuner_dbg("chip at addr %x is a tda8290\n", addr);
614 } else {
615 /* Default is being tda9887 */
616 t->type = TUNER_TDA9887;
617 t->mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
618 t->mode = T_STANDBY;
619 goto register_client;
620 }
621 break;
622 case 0x60:
623 if (tea5767_autodetection(t->i2c.adapter, t->i2c.addr) != EINVAL) {
624 t->type = TUNER_TEA5767;
625 t->mode_mask = T_RADIO;
626 t->mode = T_STANDBY;
627 t->radio_freq = 87.5 * 16000; /* Sets freq to FM range */
628 default_mode_mask &= ~T_RADIO;
629
630 goto register_client;
631 }
632 break;
633 }
634 }
635
636 /* Initializes only the first adapter found */
637 if (default_mode_mask != T_UNINITIALIZED) {
638 tuner_dbg ("Setting mode_mask to 0x%02x\n", default_mode_mask);
639 t->mode_mask = default_mode_mask;
640 t->tv_freq = 400 * 16; /* Sets freq to VHF High */
641 t->radio_freq = 87.5 * 16000; /* Sets freq to FM range */
642 default_mode_mask = T_UNINITIALIZED;
643 }
644
645 /* Should be just before return */
646register_client:
647 tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name);
648 i2c_attach_client (&t->i2c);
649 set_type (&t->i2c,t->type, t->mode_mask, t->config, t->tuner_callback);
650 return 0;
651}
652
653static int tuner_probe(struct i2c_adapter *adap)
654{
655 if (0 != addr) {
656 normal_i2c[0] = addr;
657 normal_i2c[1] = I2C_CLIENT_END;
658 }
659
660 /* HACK: Ignore 0x6b and 0x6f on cx88 boards.
661 * FusionHDTV5 RT Gold has an ir receiver at 0x6b
662 * and an RTC at 0x6f which can get corrupted if probed.
663 */
664 if ((adap->id == I2C_HW_B_CX2388x) ||
665 (adap->id == I2C_HW_B_CX23885)) {
666 unsigned int i = 0;
667
668 while (i < I2C_CLIENT_MAX_OPTS && ignore[i] != I2C_CLIENT_END)
669 i += 2;
670 if (i + 4 < I2C_CLIENT_MAX_OPTS) {
671 ignore[i+0] = adap->nr;
672 ignore[i+1] = 0x6b;
673 ignore[i+2] = adap->nr;
674 ignore[i+3] = 0x6f;
675 ignore[i+4] = I2C_CLIENT_END;
676 } else
677 printk(KERN_WARNING "tuner: "
678 "too many options specified "
679 "in i2c probe ignore list!\n");
680 }
681
682 default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
683
684 if (adap->class & I2C_CLASS_TV_ANALOG)
685 return i2c_probe(adap, &addr_data, tuner_attach);
686 return 0;
687}
688
689static int tuner_detach(struct i2c_client *client)
690{
691 struct tuner *t = i2c_get_clientdata(client);
692 int err;
693
694 err = i2c_detach_client(&t->i2c);
695 if (err) {
696 tuner_warn
697 ("Client deregistration failed, client not detached.\n");
698 return err;
699 }
700
701 if (t->ops.release)
702 t->ops.release(t);
703 else {
704 kfree(t->priv);
705 }
706 kfree(t);
707 return 0;
708}
709
710/* 690/*
711 * Switch tuner to other mode. If tuner support both tv and radio, 691 * Switch tuner to other mode. If tuner support both tv and radio,
712 * set another frequency to some value (This is needed for some pal 692 * set another frequency to some value (This is needed for some pal
@@ -716,6 +696,8 @@ static int tuner_detach(struct i2c_client *client)
716 696
717static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd) 697static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd)
718{ 698{
699 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
700
719 if (mode == t->mode) 701 if (mode == t->mode)
720 return 0; 702 return 0;
721 703
@@ -723,8 +705,8 @@ static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode,
723 705
724 if (check_mode(t, cmd) == EINVAL) { 706 if (check_mode(t, cmd) == EINVAL) {
725 t->mode = T_STANDBY; 707 t->mode = T_STANDBY;
726 if (t->ops.standby) 708 if (analog_ops->standby)
727 t->ops.standby(t); 709 analog_ops->standby(&t->fe);
728 return EINVAL; 710 return EINVAL;
729 } 711 }
730 return 0; 712 return 0;
@@ -747,9 +729,10 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
747{ 729{
748 struct tuner *t = i2c_get_clientdata(client); 730 struct tuner *t = i2c_get_clientdata(client);
749 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; 731 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
732 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
750 733
751 if (tuner_debug>1) 734 if (tuner_debug>1)
752 v4l_i2c_print_ioctl(&(t->i2c),cmd); 735 v4l_i2c_print_ioctl(client,cmd);
753 736
754 switch (cmd) { 737 switch (cmd) {
755 /* --- configuration --- */ 738 /* --- configuration --- */
@@ -773,8 +756,8 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
773 if (check_mode(t, "TUNER_SET_STANDBY") == EINVAL) 756 if (check_mode(t, "TUNER_SET_STANDBY") == EINVAL)
774 return 0; 757 return 0;
775 t->mode = T_STANDBY; 758 t->mode = T_STANDBY;
776 if (t->ops.standby) 759 if (analog_ops->standby)
777 t->ops.standby(t); 760 analog_ops->standby(&t->fe);
778 break; 761 break;
779#ifdef CONFIG_VIDEO_V4L1 762#ifdef CONFIG_VIDEO_V4L1
780 case VIDIOCSAUDIO: 763 case VIDIOCSAUDIO:
@@ -842,8 +825,8 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
842 else 825 else
843 vt->flags &= ~VIDEO_TUNER_STEREO_ON; 826 vt->flags &= ~VIDEO_TUNER_STEREO_ON;
844 } else { 827 } else {
845 if (t->ops.is_stereo) { 828 if (analog_ops->is_stereo) {
846 if (t->ops.is_stereo(t)) 829 if (analog_ops->is_stereo(&t->fe))
847 vt->flags |= 830 vt->flags |=
848 VIDEO_TUNER_STEREO_ON; 831 VIDEO_TUNER_STEREO_ON;
849 else 832 else
@@ -851,8 +834,9 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
851 ~VIDEO_TUNER_STEREO_ON; 834 ~VIDEO_TUNER_STEREO_ON;
852 } 835 }
853 } 836 }
854 if (t->ops.has_signal) 837 if (analog_ops->has_signal)
855 vt->signal = t->ops.has_signal(t); 838 vt->signal =
839 analog_ops->has_signal(&t->fe);
856 840
857 vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */ 841 vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */
858 842
@@ -882,21 +866,28 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
882 fe_tuner_ops->get_status(&t->fe, &tuner_status); 866 fe_tuner_ops->get_status(&t->fe, &tuner_status);
883 va->mode = (tuner_status & TUNER_STATUS_STEREO) 867 va->mode = (tuner_status & TUNER_STATUS_STEREO)
884 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; 868 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
885 } else if (t->ops.is_stereo) 869 } else if (analog_ops->is_stereo)
886 va->mode = t->ops.is_stereo(t) 870 va->mode = analog_ops->is_stereo(&t->fe)
887 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; 871 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
888 } 872 }
889 return 0; 873 return 0;
890 } 874 }
891#endif 875#endif
892 case TDA9887_SET_CONFIG: 876 case TUNER_SET_CONFIG:
893 if (t->type == TUNER_TDA9887) { 877 {
894 int *i = arg; 878 struct v4l2_priv_tun_config *cfg = arg;
895 879
896 t->tda9887_config = *i; 880 if (t->type != cfg->tuner)
897 set_freq(client, t->tv_freq); 881 break;
882
883 if (analog_ops->set_config) {
884 analog_ops->set_config(&t->fe, cfg->priv);
885 break;
898 } 886 }
887
888 tuner_dbg("Tuner frontend module has no way to set config\n");
899 break; 889 break;
890 }
900 /* --- v4l ioctls --- */ 891 /* --- v4l ioctls --- */
901 /* take care: bttv does userspace copying, we'll get a 892 /* take care: bttv does userspace copying, we'll get a
902 kernel pointer here... */ 893 kernel pointer here... */
@@ -958,8 +949,8 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
958 switch_v4l2(); 949 switch_v4l2();
959 950
960 tuner->type = t->mode; 951 tuner->type = t->mode;
961 if (t->ops.get_afc) 952 if (analog_ops->get_afc)
962 tuner->afc=t->ops.get_afc(t); 953 tuner->afc = analog_ops->get_afc(&t->fe);
963 if (t->mode == V4L2_TUNER_ANALOG_TV) 954 if (t->mode == V4L2_TUNER_ANALOG_TV)
964 tuner->capability |= V4L2_TUNER_CAP_NORM; 955 tuner->capability |= V4L2_TUNER_CAP_NORM;
965 if (t->mode != V4L2_TUNER_RADIO) { 956 if (t->mode != V4L2_TUNER_RADIO) {
@@ -975,16 +966,20 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
975 u32 tuner_status; 966 u32 tuner_status;
976 967
977 fe_tuner_ops->get_status(&t->fe, &tuner_status); 968 fe_tuner_ops->get_status(&t->fe, &tuner_status);
978 tuner->rxsubchans = (tuner_status & TUNER_STATUS_STEREO) ? 969 tuner->rxsubchans =
979 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO; 970 (tuner_status & TUNER_STATUS_STEREO) ?
971 V4L2_TUNER_SUB_STEREO :
972 V4L2_TUNER_SUB_MONO;
980 } else { 973 } else {
981 if (t->ops.is_stereo) { 974 if (analog_ops->is_stereo) {
982 tuner->rxsubchans = t->ops.is_stereo(t) ? 975 tuner->rxsubchans =
983 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO; 976 analog_ops->is_stereo(&t->fe) ?
977 V4L2_TUNER_SUB_STEREO :
978 V4L2_TUNER_SUB_MONO;
984 } 979 }
985 } 980 }
986 if (t->ops.has_signal) 981 if (analog_ops->has_signal)
987 tuner->signal = t->ops.has_signal(t); 982 tuner->signal = analog_ops->has_signal(&t->fe);
988 tuner->capability |= 983 tuner->capability |=
989 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; 984 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
990 tuner->audmode = t->audmode; 985 tuner->audmode = t->audmode;
@@ -1009,8 +1004,8 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
1009 break; 1004 break;
1010 } 1005 }
1011 case VIDIOC_LOG_STATUS: 1006 case VIDIOC_LOG_STATUS:
1012 if (t->ops.tuner_status) 1007 if (analog_ops->tuner_status)
1013 t->ops.tuner_status(t); 1008 analog_ops->tuner_status(&t->fe);
1014 break; 1009 break;
1015 } 1010 }
1016 1011
@@ -1019,18 +1014,18 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
1019 1014
1020static int tuner_suspend(struct i2c_client *c, pm_message_t state) 1015static int tuner_suspend(struct i2c_client *c, pm_message_t state)
1021{ 1016{
1022 struct tuner *t = i2c_get_clientdata (c); 1017 struct tuner *t = i2c_get_clientdata(c);
1023 1018
1024 tuner_dbg ("suspend\n"); 1019 tuner_dbg("suspend\n");
1025 /* FIXME: power down ??? */ 1020 /* FIXME: power down ??? */
1026 return 0; 1021 return 0;
1027} 1022}
1028 1023
1029static int tuner_resume(struct i2c_client *c) 1024static int tuner_resume(struct i2c_client *c)
1030{ 1025{
1031 struct tuner *t = i2c_get_clientdata (c); 1026 struct tuner *t = i2c_get_clientdata(c);
1032 1027
1033 tuner_dbg ("resume\n"); 1028 tuner_dbg("resume\n");
1034 if (V4L2_TUNER_RADIO == t->mode) { 1029 if (V4L2_TUNER_RADIO == t->mode) {
1035 if (t->radio_freq) 1030 if (t->radio_freq)
1036 set_freq(c, t->radio_freq); 1031 set_freq(c, t->radio_freq);
@@ -1041,36 +1036,227 @@ static int tuner_resume(struct i2c_client *c)
1041 return 0; 1036 return 0;
1042} 1037}
1043 1038
1044/* ----------------------------------------------------------------------- */ 1039/* ---------------------------------------------------------------------- */
1045 1040
1046static struct i2c_driver driver = { 1041LIST_HEAD(tuner_list);
1047 .id = I2C_DRIVERID_TUNER,
1048 .attach_adapter = tuner_probe,
1049 .detach_client = tuner_detach,
1050 .command = tuner_command,
1051 .suspend = tuner_suspend,
1052 .resume = tuner_resume,
1053 .driver = {
1054 .name = "tuner",
1055 },
1056};
1057static struct i2c_client client_template = {
1058 .name = "(tuner unset)",
1059 .driver = &driver,
1060};
1061 1042
1062static int __init tuner_init_module(void) 1043/* Search for existing radio and/or TV tuners on the given I2C adapter.
1044 Note that when this function is called from tuner_probe you can be
1045 certain no other devices will be added/deleted at the same time, I2C
1046 core protects against that. */
1047static void tuner_lookup(struct i2c_adapter *adap,
1048 struct tuner **radio, struct tuner **tv)
1063{ 1049{
1064 return i2c_add_driver(&driver); 1050 struct tuner *pos;
1051
1052 *radio = NULL;
1053 *tv = NULL;
1054
1055 list_for_each_entry(pos, &tuner_list, list) {
1056 int mode_mask;
1057
1058 if (pos->i2c->adapter != adap ||
1059 pos->i2c->driver->id != I2C_DRIVERID_TUNER)
1060 continue;
1061
1062 mode_mask = pos->mode_mask & ~T_STANDBY;
1063 if (*radio == NULL && mode_mask == T_RADIO)
1064 *radio = pos;
1065 /* Note: currently TDA9887 is the only demod-only
1066 device. If other devices appear then we need to
1067 make this test more general. */
1068 else if (*tv == NULL && pos->type != TUNER_TDA9887 &&
1069 (pos->mode_mask & (T_ANALOG_TV | T_DIGITAL_TV)))
1070 *tv = pos;
1071 }
1065} 1072}
1066 1073
1067static void __exit tuner_cleanup_module(void) 1074/* During client attach, set_type is called by adapter's attach_inform callback.
1075 set_type must then be completed by tuner_probe.
1076 */
1077static int tuner_probe(struct i2c_client *client)
1068{ 1078{
1069 i2c_del_driver(&driver); 1079 struct tuner *t;
1080 struct tuner *radio;
1081 struct tuner *tv;
1082
1083 t = kzalloc(sizeof(struct tuner), GFP_KERNEL);
1084 if (NULL == t)
1085 return -ENOMEM;
1086 t->i2c = client;
1087 strlcpy(client->name, "(tuner unset)", sizeof(client->name));
1088 i2c_set_clientdata(client, t);
1089 t->type = UNSET;
1090 t->audmode = V4L2_TUNER_MODE_STEREO;
1091 t->mode_mask = T_UNINITIALIZED;
1092
1093 if (show_i2c) {
1094 unsigned char buffer[16];
1095 int i, rc;
1096
1097 memset(buffer, 0, sizeof(buffer));
1098 rc = i2c_master_recv(client, buffer, sizeof(buffer));
1099 tuner_info("I2C RECV = ");
1100 for (i = 0; i < rc; i++)
1101 printk(KERN_CONT "%02x ", buffer[i]);
1102 printk("\n");
1103 }
1104 /* HACK: This test was added to avoid tuner to probe tda9840 and
1105 tea6415c on the MXB card */
1106 if (client->adapter->id == I2C_HW_SAA7146 && client->addr < 0x4a) {
1107 kfree(t);
1108 return -ENODEV;
1109 }
1110
1111 /* autodetection code based on the i2c addr */
1112 if (!no_autodetect) {
1113 switch (client->addr) {
1114 case 0x10:
1115 if (tea5761_autodetection(t->i2c->adapter, t->i2c->addr)
1116 != EINVAL) {
1117 t->type = TUNER_TEA5761;
1118 t->mode_mask = T_RADIO;
1119 t->mode = T_STANDBY;
1120 /* Sets freq to FM range */
1121 t->radio_freq = 87.5 * 16000;
1122 tuner_lookup(t->i2c->adapter, &radio, &tv);
1123 if (tv)
1124 tv->mode_mask &= ~T_RADIO;
1125
1126 goto register_client;
1127 }
1128 break;
1129 case 0x42:
1130 case 0x43:
1131 case 0x4a:
1132 case 0x4b:
1133 /* If chip is not tda8290, don't register.
1134 since it can be tda9887*/
1135 if (tda829x_probe(t->i2c->adapter,
1136 t->i2c->addr) == 0) {
1137 tuner_dbg("tda829x detected\n");
1138 } else {
1139 /* Default is being tda9887 */
1140 t->type = TUNER_TDA9887;
1141 t->mode_mask = T_RADIO | T_ANALOG_TV |
1142 T_DIGITAL_TV;
1143 t->mode = T_STANDBY;
1144 goto register_client;
1145 }
1146 break;
1147 case 0x60:
1148 if (tea5767_autodetection(t->i2c->adapter, t->i2c->addr)
1149 != EINVAL) {
1150 t->type = TUNER_TEA5767;
1151 t->mode_mask = T_RADIO;
1152 t->mode = T_STANDBY;
1153 /* Sets freq to FM range */
1154 t->radio_freq = 87.5 * 16000;
1155 tuner_lookup(t->i2c->adapter, &radio, &tv);
1156 if (tv)
1157 tv->mode_mask &= ~T_RADIO;
1158
1159 goto register_client;
1160 }
1161 break;
1162 }
1163 }
1164
1165 /* Initializes only the first TV tuner on this adapter. Why only the
1166 first? Because there are some devices (notably the ones with TI
1167 tuners) that have more than one i2c address for the *same* device.
1168 Experience shows that, except for just one case, the first
1169 address is the right one. The exception is a Russian tuner
1170 (ACORP_Y878F). So, the desired behavior is just to enable the
1171 first found TV tuner. */
1172 tuner_lookup(t->i2c->adapter, &radio, &tv);
1173 if (tv == NULL) {
1174 t->mode_mask = T_ANALOG_TV | T_DIGITAL_TV;
1175 if (radio == NULL)
1176 t->mode_mask |= T_RADIO;
1177 tuner_dbg("Setting mode_mask to 0x%02x\n", t->mode_mask);
1178 t->tv_freq = 400 * 16; /* Sets freq to VHF High */
1179 t->radio_freq = 87.5 * 16000; /* Sets freq to FM range */
1180 }
1181
1182 /* Should be just before return */
1183register_client:
1184 tuner_info("chip found @ 0x%x (%s)\n", client->addr << 1,
1185 client->adapter->name);
1186
1187 /* Sets a default mode */
1188 if (t->mode_mask & T_ANALOG_TV) {
1189 t->mode = V4L2_TUNER_ANALOG_TV;
1190 } else if (t->mode_mask & T_RADIO) {
1191 t->mode = V4L2_TUNER_RADIO;
1192 } else {
1193 t->mode = V4L2_TUNER_DIGITAL_TV;
1194 }
1195 set_type(client, t->type, t->mode_mask, t->config, t->tuner_callback);
1196 list_add_tail(&t->list, &tuner_list);
1197 return 0;
1198}
1199
1200static int tuner_legacy_probe(struct i2c_adapter *adap)
1201{
1202 if (0 != addr) {
1203 normal_i2c[0] = addr;
1204 normal_i2c[1] = I2C_CLIENT_END;
1205 }
1206
1207 if ((adap->class & I2C_CLASS_TV_ANALOG) == 0)
1208 return 0;
1209
1210 /* HACK: Ignore 0x6b and 0x6f on cx88 boards.
1211 * FusionHDTV5 RT Gold has an ir receiver at 0x6b
1212 * and an RTC at 0x6f which can get corrupted if probed.
1213 */
1214 if ((adap->id == I2C_HW_B_CX2388x) ||
1215 (adap->id == I2C_HW_B_CX23885)) {
1216 unsigned int i = 0;
1217
1218 while (i < I2C_CLIENT_MAX_OPTS && ignore[i] != I2C_CLIENT_END)
1219 i += 2;
1220 if (i + 4 < I2C_CLIENT_MAX_OPTS) {
1221 ignore[i+0] = adap->nr;
1222 ignore[i+1] = 0x6b;
1223 ignore[i+2] = adap->nr;
1224 ignore[i+3] = 0x6f;
1225 ignore[i+4] = I2C_CLIENT_END;
1226 } else
1227 printk(KERN_WARNING "tuner: "
1228 "too many options specified "
1229 "in i2c probe ignore list!\n");
1230 }
1231 return 1;
1070} 1232}
1071 1233
1072module_init(tuner_init_module); 1234static int tuner_remove(struct i2c_client *client)
1073module_exit(tuner_cleanup_module); 1235{
1236 struct tuner *t = i2c_get_clientdata(client);
1237 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
1238
1239 if (analog_ops->release)
1240 analog_ops->release(&t->fe);
1241
1242 list_del(&t->list);
1243 kfree(t);
1244 return 0;
1245}
1246
1247/* ----------------------------------------------------------------------- */
1248
1249static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1250 .name = "tuner",
1251 .driverid = I2C_DRIVERID_TUNER,
1252 .command = tuner_command,
1253 .probe = tuner_probe,
1254 .remove = tuner_remove,
1255 .suspend = tuner_suspend,
1256 .resume = tuner_resume,
1257 .legacy_probe = tuner_legacy_probe,
1258};
1259
1074 1260
1075/* 1261/*
1076 * Overrides for Emacs so that we follow Linus's tabbing style. 1262 * Overrides for Emacs so that we follow Linus's tabbing style.
diff --git a/drivers/media/video/tuner-driver.h b/drivers/media/video/tuner-driver.h
deleted file mode 100644
index 28a10da76d12..000000000000
--- a/drivers/media/video/tuner-driver.h
+++ /dev/null
@@ -1,99 +0,0 @@
1/*
2 tuner-driver.h - interface for different tuners
3
4 Copyright (C) 1997 Markus Schroeder (schroedm@uni-duesseldorf.de)
5 minor modifications by Ralph Metzler (rjkm@thp.uni-koeln.de)
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22#ifndef __TUNER_DRIVER_H__
23#define __TUNER_DRIVER_H__
24
25#include <linux/videodev2.h>
26#include <linux/i2c.h>
27#include "tuner-i2c.h"
28#include "dvb_frontend.h"
29
30extern unsigned const int tuner_count;
31
32struct tuner;
33
34struct tuner_operations {
35 void (*set_tv_freq)(struct tuner *t, unsigned int freq);
36 void (*set_radio_freq)(struct tuner *t, unsigned int freq);
37 int (*has_signal)(struct tuner *t);
38 int (*is_stereo)(struct tuner *t);
39 int (*get_afc)(struct tuner *t);
40 void (*tuner_status)(struct tuner *t);
41 void (*standby)(struct tuner *t);
42 void (*release)(struct tuner *t);
43};
44
45struct tuner {
46 /* device */
47 struct i2c_client i2c;
48
49 unsigned int type; /* chip type */
50
51 unsigned int mode;
52 unsigned int mode_mask; /* Combination of allowable modes */
53
54 unsigned int tv_freq; /* keep track of the current settings */
55 unsigned int radio_freq;
56 unsigned int audmode;
57 v4l2_std_id std;
58
59 int using_v4l2;
60 void *priv;
61
62 struct dvb_frontend fe;
63
64 /* used by tda9887 */
65 unsigned int tda9887_config;
66
67 unsigned int config;
68 int (*tuner_callback) (void *dev, int command,int arg);
69
70 struct tuner_operations ops;
71};
72
73/* ------------------------------------------------------------------------ */
74
75extern int tda9887_tuner_init(struct tuner *t);
76
77/* ------------------------------------------------------------------------ */
78
79#define tuner_warn(fmt, arg...) do {\
80 printk(KERN_WARNING "%s %d-%04x: " fmt, t->i2c.driver->driver.name, \
81 i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
82#define tuner_info(fmt, arg...) do {\
83 printk(KERN_INFO "%s %d-%04x: " fmt, t->i2c.driver->driver.name, \
84 i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
85#define tuner_dbg(fmt, arg...) do {\
86 extern int tuner_debug; \
87 if (tuner_debug) \
88 printk(KERN_DEBUG "%s %d-%04x: " fmt, t->i2c.driver->driver.name, \
89 i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
90
91#endif /* __TUNER_DRIVER_H__ */
92
93/*
94 * Overrides for Emacs so that we follow Linus's tabbing style.
95 * ---------------------------------------------------------------------------
96 * Local variables:
97 * c-basic-offset: 8
98 * End:
99 */
diff --git a/drivers/media/video/tuner-i2c.h b/drivers/media/video/tuner-i2c.h
index 159019ec3373..de52e8ffd347 100644
--- a/drivers/media/video/tuner-i2c.h
+++ b/drivers/media/video/tuner-i2c.h
@@ -46,25 +46,42 @@ static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf,
46 return (ret == 1) ? len : ret; 46 return (ret == 1) ? len : ret;
47} 47}
48 48
49#ifndef __TUNER_DRIVER_H__ 49static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
50#define tuner_warn(fmt, arg...) do {\ 50 char *obuf, int olen,
51 printk(KERN_WARNING PREFIX "%d-%04x: " fmt, \ 51 char *ibuf, int ilen)
52 i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0) 52{
53#define tuner_info(fmt, arg...) do {\ 53 struct i2c_msg msg[2] = { { .addr = props->addr, .flags = 0,
54 printk(KERN_INFO PREFIX "%d-%04x: " fmt, \ 54 .buf = obuf, .len = olen },
55 i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0) 55 { .addr = props->addr, .flags = I2C_M_RD,
56#define tuner_dbg(fmt, arg...) do {\ 56 .buf = ibuf, .len = ilen } };
57 if ((debug)) \ 57 int ret = i2c_transfer(props->adap, msg, 2);
58 printk(KERN_DEBUG PREFIX "%d-%04x: " fmt, \
59 i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0)
60#endif /* __TUNER_DRIVER_H__ */
61 58
62#endif /* __TUNER_I2C_H__ */ 59 return (ret == 2) ? ilen : ret;
60}
63 61
64/* 62#define tuner_warn(fmt, arg...) do { \
65 * Overrides for Emacs so that we follow Linus's tabbing style. 63 printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \
66 * --------------------------------------------------------------------------- 64 i2c_adapter_id(priv->i2c_props.adap), \
67 * Local variables: 65 priv->i2c_props.addr, ##arg); \
68 * c-basic-offset: 8 66 } while (0)
69 * End: 67
70 */ 68#define tuner_info(fmt, arg...) do { \
69 printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \
70 i2c_adapter_id(priv->i2c_props.adap), \
71 priv->i2c_props.addr , ##arg); \
72 } while (0)
73
74#define tuner_err(fmt, arg...) do { \
75 printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \
76 i2c_adapter_id(priv->i2c_props.adap), \
77 priv->i2c_props.addr , ##arg); \
78 } while (0)
79
80#define tuner_dbg(fmt, arg...) do { \
81 if ((debug)) \
82 printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \
83 i2c_adapter_id(priv->i2c_props.adap), \
84 priv->i2c_props.addr , ##arg); \
85 } while (0)
86
87#endif /* __TUNER_I2C_H__ */
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index 7b93d3b1f4c6..c1db576696c6 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -17,7 +17,7 @@ static int debug = 0;
17module_param(debug, int, 0644); 17module_param(debug, int, 0644);
18MODULE_PARM_DESC(debug, "enable verbose debug messages"); 18MODULE_PARM_DESC(debug, "enable verbose debug messages");
19 19
20#define PREFIX "tuner-simple " 20#define PREFIX "tuner-simple"
21 21
22static int offset = 0; 22static int offset = 0;
23module_param(offset, int, 0664); 23module_param(offset, int, 0664);
@@ -355,10 +355,14 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
355 } 355 }
356 priv->last_div = div; 356 priv->last_div = div;
357 if (t_params->has_tda9887) { 357 if (t_params->has_tda9887) {
358 struct v4l2_priv_tun_config tda9887_cfg;
358 int config = 0; 359 int config = 0;
359 int is_secam_l = (params->std & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) && 360 int is_secam_l = (params->std & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) &&
360 !(params->std & ~(V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)); 361 !(params->std & ~(V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC));
361 362
363 tda9887_cfg.tuner = TUNER_TDA9887;
364 tda9887_cfg.priv = &config;
365
362 if (params->std == V4L2_STD_SECAM_LC) { 366 if (params->std == V4L2_STD_SECAM_LC) {
363 if (t_params->port1_active ^ t_params->port1_invert_for_secam_lc) 367 if (t_params->port1_active ^ t_params->port1_invert_for_secam_lc)
364 config |= TDA9887_PORT1_ACTIVE; 368 config |= TDA9887_PORT1_ACTIVE;
@@ -391,7 +395,8 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
391 } 395 }
392 if (t_params->default_pll_gating_18) 396 if (t_params->default_pll_gating_18)
393 config |= TDA9887_GATING_18; 397 config |= TDA9887_GATING_18;
394 i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config); 398 i2c_clients_command(priv->i2c_props.adap, TUNER_SET_CONFIG,
399 &tda9887_cfg);
395 } 400 }
396 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", 401 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
397 buffer[0],buffer[1],buffer[2],buffer[3]); 402 buffer[0],buffer[1],buffer[2],buffer[3]);
@@ -534,6 +539,11 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
534 539
535 if (t_params->has_tda9887) { 540 if (t_params->has_tda9887) {
536 int config = 0; 541 int config = 0;
542 struct v4l2_priv_tun_config tda9887_cfg;
543
544 tda9887_cfg.tuner = TUNER_TDA9887;
545 tda9887_cfg.priv = &config;
546
537 if (t_params->port1_active && !t_params->port1_fm_high_sensitivity) 547 if (t_params->port1_active && !t_params->port1_fm_high_sensitivity)
538 config |= TDA9887_PORT1_ACTIVE; 548 config |= TDA9887_PORT1_ACTIVE;
539 if (t_params->port2_active && !t_params->port2_fm_high_sensitivity) 549 if (t_params->port2_active && !t_params->port2_fm_high_sensitivity)
@@ -546,7 +556,8 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
546 config |= TDA9887_GAIN_NORMAL; 556 config |= TDA9887_GAIN_NORMAL;
547 if (t_params->radio_if == 2) 557 if (t_params->radio_if == 2)
548 config |= TDA9887_RIF_41_3; 558 config |= TDA9887_RIF_41_3;
549 i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config); 559 i2c_clients_command(priv->i2c_props.adap, TUNER_SET_CONFIG,
560 &tda9887_cfg);
550 } 561 }
551 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4))) 562 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
552 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); 563 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
diff --git a/drivers/media/video/tuner-types.c b/drivers/media/video/tuner-types.c
index c6a7934bd5a6..883047f9c28c 100644
--- a/drivers/media/video/tuner-types.c
+++ b/drivers/media/video/tuner-types.c
@@ -1366,7 +1366,7 @@ struct tunertype tuners[] = {
1366 .count = ARRAY_SIZE(tuner_philips_fq1286_params), 1366 .count = ARRAY_SIZE(tuner_philips_fq1286_params),
1367 }, 1367 },
1368 [TUNER_PHILIPS_TDA8290] = { /* Philips PAL|NTSC */ 1368 [TUNER_PHILIPS_TDA8290] = { /* Philips PAL|NTSC */
1369 .name = "tda8290+75", 1369 .name = "Philips/NXP TDA 8290/8295 + 8275/8275A/18271",
1370 /* see tda8290.c for details */ }, 1370 /* see tda8290.c for details */ },
1371 [TUNER_TCL_2002MB] = { /* TCL PAL */ 1371 [TUNER_TCL_2002MB] = { /* TCL PAL */
1372 .name = "TCL 2002MB", 1372 .name = "TCL 2002MB",
@@ -1452,9 +1452,9 @@ struct tunertype tuners[] = {
1452 .params = tuner_samsung_tcpn_2121p30a_params, 1452 .params = tuner_samsung_tcpn_2121p30a_params,
1453 .count = ARRAY_SIZE(tuner_samsung_tcpn_2121p30a_params), 1453 .count = ARRAY_SIZE(tuner_samsung_tcpn_2121p30a_params),
1454 }, 1454 },
1455 [TUNER_XCEIVE_XC3028] = { /* Xceive 3028 */ 1455 [TUNER_XC2028] = { /* Xceive 2028 */
1456 .name = "Xceive xc3028", 1456 .name = "Xceive xc2028/xc3028 tuner",
1457 /* see xc3028.c for details */ 1457 /* see tuner-xc2028.c for details */
1458 }, 1458 },
1459 [TUNER_THOMSON_FE6600] = { /* Thomson PAL / DVB-T */ 1459 [TUNER_THOMSON_FE6600] = { /* Thomson PAL / DVB-T */
1460 .name = "Thomson FE6600", 1460 .name = "Thomson FE6600",
@@ -1475,6 +1475,10 @@ struct tunertype tuners[] = {
1475 .name = "Philips TEA5761 FM Radio", 1475 .name = "Philips TEA5761 FM Radio",
1476 /* see tea5767.c for details */ 1476 /* see tea5767.c for details */
1477 }, 1477 },
1478 [TUNER_XC5000] = { /* Xceive 5000 */
1479 .name = "Xceive 5000 tuner",
1480 /* see xc5000.c for details */
1481 },
1478}; 1482};
1479 1483
1480unsigned const int tuner_count = ARRAY_SIZE(tuners); 1484unsigned const int tuner_count = ARRAY_SIZE(tuners);
diff --git a/drivers/media/video/tuner-xc2028-types.h b/drivers/media/video/tuner-xc2028-types.h
new file mode 100644
index 000000000000..d0057fbf0ec7
--- /dev/null
+++ b/drivers/media/video/tuner-xc2028-types.h
@@ -0,0 +1,128 @@
1/* tuner-xc2028_types
2 *
3 * Copyright (c) 2007 Mauro Carvalho Chehab (mchehab@infradead.org)
4 * This code is placed under the terms of the GNU General Public License v2
5 */
6
7/* xc3028 firmware types */
8
9/* BASE firmware should be loaded before any other firmware */
10#define BASE (1<<0)
11#define BASE_TYPES (BASE|F8MHZ|MTS|FM|INPUT1|INPUT2|INIT1)
12
13/* F8MHZ marks BASE firmwares for 8 MHz Bandwidth */
14#define F8MHZ (1<<1)
15
16/* Multichannel Television Sound (MTS)
17 Those firmwares are capable of using xc2038 DSP to decode audio and
18 produce a baseband audio output on some pins of the chip.
19 There are MTS firmwares for the most used video standards. It should be
20 required to use MTS firmwares, depending on the way audio is routed into
21 the bridge chip
22 */
23#define MTS (1<<2)
24
25/* FIXME: I have no idea what's the difference between
26 D2620 and D2633 firmwares
27 */
28#define D2620 (1<<3)
29#define D2633 (1<<4)
30
31/* DTV firmwares for 6, 7 and 8 MHz
32 DTV6 - 6MHz - ATSC/DVB-C/DVB-T/ISDB-T/DOCSIS
33 DTV8 - 8MHz - DVB-C/DVB-T
34 */
35#define DTV6 (1 << 5)
36#define QAM (1 << 6)
37#define DTV7 (1<<7)
38#define DTV78 (1<<8)
39#define DTV8 (1<<9)
40
41#define DTV_TYPES (D2620|D2633|DTV6|QAM|DTV7|DTV78|DTV8|ATSC)
42
43/* There's a FM | BASE firmware + FM specific firmware (std=0) */
44#define FM (1<<10)
45
46#define STD_SPECIFIC_TYPES (MTS|FM|LCD|NOGD)
47
48/* Applies only for FM firmware
49 Makes it use RF input 1 (pin #2) instead of input 2 (pin #4)
50 */
51#define INPUT1 (1<<11)
52
53
54/* LCD firmwares exist only for MTS STD/MN (PAL or NTSC/M)
55 and for non-MTS STD/MN (PAL, NTSC/M or NTSC/Kr)
56 There are variants both with and without NOGD
57 */
58#define LCD (1<<12)
59
60/* NOGD firmwares exist only for MTS STD/MN (PAL or NTSC/M)
61 and for non-MTS STD/MN (PAL, NTSC/M or NTSC/Kr)
62 */
63#define NOGD (1<<13)
64
65/* Old firmwares were broken into init0 and init1 */
66#define INIT1 (1<<14)
67
68/* SCODE firmware selects particular behaviours */
69#define MONO (1 << 15)
70#define ATSC (1 << 16)
71#define IF (1 << 17)
72#define LG60 (1 << 18)
73#define ATI638 (1 << 19)
74#define OREN538 (1 << 20)
75#define OREN36 (1 << 21)
76#define TOYOTA388 (1 << 22)
77#define TOYOTA794 (1 << 23)
78#define DIBCOM52 (1 << 24)
79#define ZARLINK456 (1 << 25)
80#define CHINA (1 << 26)
81#define F6MHZ (1 << 27)
82#define INPUT2 (1 << 28)
83#define SCODE (1 << 29)
84
85/* This flag identifies that the scode table has a new format */
86#define HAS_IF (1 << 30)
87
88#define SCODE_TYPES (MTS|DTV6|QAM|DTV7|DTV78|DTV8|LCD|NOGD|MONO|ATSC|IF| \
89 LG60|ATI638|OREN538|OREN36|TOYOTA388|TOYOTA794| \
90 DIBCOM52|ZARLINK456|CHINA|F6MHZ|SCODE)
91
92/* Newer types to be moved to videodev2.h */
93
94#define V4L2_STD_SECAM_K3 (0x04000000)
95
96/* Audio types */
97
98#define V4L2_STD_A2_A (1LL<<32)
99#define V4L2_STD_A2_B (1LL<<33)
100#define V4L2_STD_NICAM_A (1LL<<34)
101#define V4L2_STD_NICAM_B (1LL<<35)
102#define V4L2_STD_AM (1LL<<36)
103#define V4L2_STD_BTSC (1LL<<37)
104#define V4L2_STD_EIAJ (1LL<<38)
105
106#define V4L2_STD_A2 (V4L2_STD_A2_A | V4L2_STD_A2_B)
107#define V4L2_STD_NICAM (V4L2_STD_NICAM_A | V4L2_STD_NICAM_B)
108
109/* To preserve backward compatibilty,
110 (std & V4L2_STD_AUDIO) = 0 means that ALL audio stds are supported
111 */
112
113#define V4L2_STD_AUDIO (V4L2_STD_A2 | \
114 V4L2_STD_NICAM | \
115 V4L2_STD_AM | \
116 V4L2_STD_BTSC | \
117 V4L2_STD_EIAJ)
118
119/* Used standards with audio restrictions */
120
121#define V4L2_STD_PAL_BG_A2_A (V4L2_STD_PAL_BG | V4L2_STD_A2_A)
122#define V4L2_STD_PAL_BG_A2_B (V4L2_STD_PAL_BG | V4L2_STD_A2_B)
123#define V4L2_STD_PAL_BG_NICAM_A (V4L2_STD_PAL_BG | V4L2_STD_NICAM_A)
124#define V4L2_STD_PAL_BG_NICAM_B (V4L2_STD_PAL_BG | V4L2_STD_NICAM_B)
125#define V4L2_STD_PAL_DK_A2 (V4L2_STD_PAL_DK | V4L2_STD_A2)
126#define V4L2_STD_PAL_DK_NICAM (V4L2_STD_PAL_DK | V4L2_STD_NICAM)
127#define V4L2_STD_SECAM_L_NICAM (V4L2_STD_SECAM_L | V4L2_STD_NICAM)
128#define V4L2_STD_SECAM_L_AM (V4L2_STD_SECAM_L | V4L2_STD_AM)
diff --git a/drivers/media/video/tuner-xc2028.c b/drivers/media/video/tuner-xc2028.c
new file mode 100644
index 000000000000..f191f6a48070
--- /dev/null
+++ b/drivers/media/video/tuner-xc2028.c
@@ -0,0 +1,1213 @@
1/* tuner-xc2028
2 *
3 * Copyright (c) 2007 Mauro Carvalho Chehab (mchehab@infradead.org)
4 *
5 * Copyright (c) 2007 Michel Ludwig (michel.ludwig@gmail.com)
6 * - frontend interface
7 *
8 * This code is placed under the terms of the GNU General Public License v2
9 */
10
11#include <linux/i2c.h>
12#include <asm/div64.h>
13#include <linux/firmware.h>
14#include <linux/videodev2.h>
15#include <linux/delay.h>
16#include <media/tuner.h>
17#include <linux/mutex.h>
18#include "tuner-i2c.h"
19#include "tuner-xc2028.h"
20#include "tuner-xc2028-types.h"
21
22#include <linux/dvb/frontend.h>
23#include "dvb_frontend.h"
24
25
26#define PREFIX "xc2028"
27
28static int debug;
29module_param(debug, int, 0644);
30MODULE_PARM_DESC(debug, "enable verbose debug messages");
31
32static char audio_std[8];
33module_param_string(audio_std, audio_std, sizeof(audio_std), 0);
34MODULE_PARM_DESC(audio_std,
35 "Audio standard. XC3028 audio decoder explicitly "
36 "needs to know what audio\n"
37 "standard is needed for some video standards with audio A2 or NICAM.\n"
38 "The valid values are:\n"
39 "A2\n"
40 "A2/A\n"
41 "A2/B\n"
42 "NICAM\n"
43 "NICAM/A\n"
44 "NICAM/B\n");
45
46static LIST_HEAD(xc2028_list);
47static DEFINE_MUTEX(xc2028_list_mutex);
48
49/* struct for storing firmware table */
50struct firmware_description {
51 unsigned int type;
52 v4l2_std_id id;
53 __u16 int_freq;
54 unsigned char *ptr;
55 unsigned int size;
56};
57
58struct firmware_properties {
59 unsigned int type;
60 v4l2_std_id id;
61 v4l2_std_id std_req;
62 __u16 int_freq;
63 unsigned int scode_table;
64 int scode_nr;
65};
66
67struct xc2028_data {
68 struct list_head xc2028_list;
69 struct tuner_i2c_props i2c_props;
70 int (*tuner_callback) (void *dev,
71 int command, int arg);
72 void *video_dev;
73 int count;
74 __u32 frequency;
75
76 struct firmware_description *firm;
77 int firm_size;
78 __u16 firm_version;
79
80 __u16 hwmodel;
81 __u16 hwvers;
82
83 struct xc2028_ctrl ctrl;
84
85 struct firmware_properties cur_fw;
86
87 struct mutex lock;
88};
89
90#define i2c_send(priv, buf, size) ({ \
91 int _rc; \
92 _rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size); \
93 if (size != _rc) \
94 tuner_info("i2c output error: rc = %d (should be %d)\n",\
95 _rc, (int)size); \
96 _rc; \
97})
98
99#define i2c_rcv(priv, buf, size) ({ \
100 int _rc; \
101 _rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size); \
102 if (size != _rc) \
103 tuner_err("i2c input error: rc = %d (should be %d)\n", \
104 _rc, (int)size); \
105 _rc; \
106})
107
108#define i2c_send_recv(priv, obuf, osize, ibuf, isize) ({ \
109 int _rc; \
110 _rc = tuner_i2c_xfer_send_recv(&priv->i2c_props, obuf, osize, \
111 ibuf, isize); \
112 if (isize != _rc) \
113 tuner_err("i2c input error: rc = %d (should be %d)\n", \
114 _rc, (int)isize); \
115 _rc; \
116})
117
118#define send_seq(priv, data...) ({ \
119 static u8 _val[] = data; \
120 int _rc; \
121 if (sizeof(_val) != \
122 (_rc = tuner_i2c_xfer_send(&priv->i2c_props, \
123 _val, sizeof(_val)))) { \
124 tuner_err("Error on line %d: %d\n", __LINE__, _rc); \
125 } else \
126 msleep(10); \
127 _rc; \
128})
129
130static unsigned int xc2028_get_reg(struct xc2028_data *priv, u16 reg, u16 *val)
131{
132 unsigned char buf[2];
133 unsigned char ibuf[2];
134
135 tuner_dbg("%s %04x called\n", __FUNCTION__, reg);
136
137 buf[0] = reg >> 8;
138 buf[1] = (unsigned char) reg;
139
140 if (i2c_send_recv(priv, buf, 2, ibuf, 2) != 2)
141 return -EIO;
142
143 *val = (ibuf[1]) | (ibuf[0] << 8);
144 return 0;
145}
146
147#define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0)
148void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq)
149{
150 if (type & BASE)
151 printk("BASE ");
152 if (type & INIT1)
153 printk("INIT1 ");
154 if (type & F8MHZ)
155 printk("F8MHZ ");
156 if (type & MTS)
157 printk("MTS ");
158 if (type & D2620)
159 printk("D2620 ");
160 if (type & D2633)
161 printk("D2633 ");
162 if (type & DTV6)
163 printk("DTV6 ");
164 if (type & QAM)
165 printk("QAM ");
166 if (type & DTV7)
167 printk("DTV7 ");
168 if (type & DTV78)
169 printk("DTV78 ");
170 if (type & DTV8)
171 printk("DTV8 ");
172 if (type & FM)
173 printk("FM ");
174 if (type & INPUT1)
175 printk("INPUT1 ");
176 if (type & LCD)
177 printk("LCD ");
178 if (type & NOGD)
179 printk("NOGD ");
180 if (type & MONO)
181 printk("MONO ");
182 if (type & ATSC)
183 printk("ATSC ");
184 if (type & IF)
185 printk("IF ");
186 if (type & LG60)
187 printk("LG60 ");
188 if (type & ATI638)
189 printk("ATI638 ");
190 if (type & OREN538)
191 printk("OREN538 ");
192 if (type & OREN36)
193 printk("OREN36 ");
194 if (type & TOYOTA388)
195 printk("TOYOTA388 ");
196 if (type & TOYOTA794)
197 printk("TOYOTA794 ");
198 if (type & DIBCOM52)
199 printk("DIBCOM52 ");
200 if (type & ZARLINK456)
201 printk("ZARLINK456 ");
202 if (type & CHINA)
203 printk("CHINA ");
204 if (type & F6MHZ)
205 printk("F6MHZ ");
206 if (type & INPUT2)
207 printk("INPUT2 ");
208 if (type & SCODE)
209 printk("SCODE ");
210 if (type & HAS_IF)
211 printk("HAS_IF_%d ", int_freq);
212}
213
214static v4l2_std_id parse_audio_std_option(void)
215{
216 if (strcasecmp(audio_std, "A2") == 0)
217 return V4L2_STD_A2;
218 if (strcasecmp(audio_std, "A2/A") == 0)
219 return V4L2_STD_A2_A;
220 if (strcasecmp(audio_std, "A2/B") == 0)
221 return V4L2_STD_A2_B;
222 if (strcasecmp(audio_std, "NICAM") == 0)
223 return V4L2_STD_NICAM;
224 if (strcasecmp(audio_std, "NICAM/A") == 0)
225 return V4L2_STD_NICAM_A;
226 if (strcasecmp(audio_std, "NICAM/B") == 0)
227 return V4L2_STD_NICAM_B;
228
229 return 0;
230}
231
232static void free_firmware(struct xc2028_data *priv)
233{
234 int i;
235
236 if (!priv->firm)
237 return;
238
239 for (i = 0; i < priv->firm_size; i++)
240 kfree(priv->firm[i].ptr);
241
242 kfree(priv->firm);
243
244 priv->firm = NULL;
245 priv->firm_size = 0;
246
247 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
248}
249
250static int load_all_firmwares(struct dvb_frontend *fe)
251{
252 struct xc2028_data *priv = fe->tuner_priv;
253 const struct firmware *fw = NULL;
254 unsigned char *p, *endp;
255 int rc = 0;
256 int n, n_array;
257 char name[33];
258
259 tuner_dbg("%s called\n", __FUNCTION__);
260
261 tuner_dbg("Reading firmware %s\n", priv->ctrl.fname);
262 rc = request_firmware(&fw, priv->ctrl.fname,
263 &priv->i2c_props.adap->dev);
264 if (rc < 0) {
265 if (rc == -ENOENT)
266 tuner_err("Error: firmware %s not found.\n",
267 priv->ctrl.fname);
268 else
269 tuner_err("Error %d while requesting firmware %s \n",
270 rc, priv->ctrl.fname);
271
272 return rc;
273 }
274 p = fw->data;
275 endp = p + fw->size;
276
277 if (fw->size < sizeof(name) - 1 + 2 + 2) {
278 tuner_err("Error: firmware file %s has invalid size!\n",
279 priv->ctrl.fname);
280 goto corrupt;
281 }
282
283 memcpy(name, p, sizeof(name) - 1);
284 name[sizeof(name) - 1] = 0;
285 p += sizeof(name) - 1;
286
287 priv->firm_version = le16_to_cpu(*(__u16 *) p);
288 p += 2;
289
290 n_array = le16_to_cpu(*(__u16 *) p);
291 p += 2;
292
293 tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n",
294 n_array, priv->ctrl.fname, name,
295 priv->firm_version >> 8, priv->firm_version & 0xff);
296
297 priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL);
298 if (priv->firm == NULL) {
299 tuner_err("Not enough memory to load firmware file.\n");
300 rc = -ENOMEM;
301 goto err;
302 }
303 priv->firm_size = n_array;
304
305 n = -1;
306 while (p < endp) {
307 __u32 type, size;
308 v4l2_std_id id;
309 __u16 int_freq = 0;
310
311 n++;
312 if (n >= n_array) {
313 tuner_err("More firmware images in file than "
314 "were expected!\n");
315 goto corrupt;
316 }
317
318 /* Checks if there's enough bytes to read */
319 if (p + sizeof(type) + sizeof(id) + sizeof(size) > endp) {
320 tuner_err("Firmware header is incomplete!\n");
321 goto corrupt;
322 }
323
324 type = le32_to_cpu(*(__u32 *) p);
325 p += sizeof(type);
326
327 id = le64_to_cpu(*(v4l2_std_id *) p);
328 p += sizeof(id);
329
330 if (type & HAS_IF) {
331 int_freq = le16_to_cpu(*(__u16 *) p);
332 p += sizeof(int_freq);
333 }
334
335 size = le32_to_cpu(*(__u32 *) p);
336 p += sizeof(size);
337
338 if ((!size) || (size + p > endp)) {
339 tuner_err("Firmware type ");
340 dump_firm_type(type);
341 printk("(%x), id %llx is corrupted "
342 "(size=%d, expected %d)\n",
343 type, (unsigned long long)id,
344 (unsigned)(endp - p), size);
345 goto corrupt;
346 }
347
348 priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
349 if (priv->firm[n].ptr == NULL) {
350 tuner_err("Not enough memory to load firmware file.\n");
351 rc = -ENOMEM;
352 goto err;
353 }
354 tuner_dbg("Reading firmware type ");
355 if (debug) {
356 dump_firm_type_and_int_freq(type, int_freq);
357 printk("(%x), id %llx, size=%d.\n",
358 type, (unsigned long long)id, size);
359 }
360
361 memcpy(priv->firm[n].ptr, p, size);
362 priv->firm[n].type = type;
363 priv->firm[n].id = id;
364 priv->firm[n].size = size;
365 priv->firm[n].int_freq = int_freq;
366
367 p += size;
368 }
369
370 if (n + 1 != priv->firm_size) {
371 tuner_err("Firmware file is incomplete!\n");
372 goto corrupt;
373 }
374
375 goto done;
376
377corrupt:
378 rc = -EINVAL;
379 tuner_err("Error: firmware file is corrupted!\n");
380
381err:
382 tuner_info("Releasing partially loaded firmware file.\n");
383 free_firmware(priv);
384
385done:
386 release_firmware(fw);
387 if (rc == 0)
388 tuner_dbg("Firmware files loaded.\n");
389
390 return rc;
391}
392
393static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
394 v4l2_std_id *id)
395{
396 struct xc2028_data *priv = fe->tuner_priv;
397 int i, best_i = -1, best_nr_matches = 0;
398 unsigned int ign_firm_type_mask = 0;
399
400 tuner_dbg("%s called, want type=", __FUNCTION__);
401 if (debug) {
402 dump_firm_type(type);
403 printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
404 }
405
406 if (!priv->firm) {
407 tuner_err("Error! firmware not loaded\n");
408 return -EINVAL;
409 }
410
411 if (((type & ~SCODE) == 0) && (*id == 0))
412 *id = V4L2_STD_PAL;
413
414 if (type & BASE)
415 type &= BASE_TYPES;
416 else if (type & SCODE) {
417 type &= SCODE_TYPES;
418 ign_firm_type_mask = HAS_IF;
419 } else if (type & DTV_TYPES)
420 type &= DTV_TYPES;
421 else if (type & STD_SPECIFIC_TYPES)
422 type &= STD_SPECIFIC_TYPES;
423
424 /* Seek for exact match */
425 for (i = 0; i < priv->firm_size; i++) {
426 if ((type == (priv->firm[i].type & ~ign_firm_type_mask)) &&
427 (*id == priv->firm[i].id))
428 goto found;
429 }
430
431 /* Seek for generic video standard match */
432 for (i = 0; i < priv->firm_size; i++) {
433 v4l2_std_id match_mask;
434 int nr_matches;
435
436 if (type != (priv->firm[i].type & ~ign_firm_type_mask))
437 continue;
438
439 match_mask = *id & priv->firm[i].id;
440 if (!match_mask)
441 continue;
442
443 if ((*id & match_mask) == *id)
444 goto found; /* Supports all the requested standards */
445
446 nr_matches = hweight64(match_mask);
447 if (nr_matches > best_nr_matches) {
448 best_nr_matches = nr_matches;
449 best_i = i;
450 }
451 }
452
453 if (best_nr_matches > 0) {
454 tuner_dbg("Selecting best matching firmware (%d bits) for "
455 "type=", best_nr_matches);
456 dump_firm_type(type);
457 printk("(%x), id %016llx:\n", type, (unsigned long long)*id);
458 i = best_i;
459 goto found;
460 }
461
462 /*FIXME: Would make sense to seek for type "hint" match ? */
463
464 i = -ENOENT;
465 goto ret;
466
467found:
468 *id = priv->firm[i].id;
469
470ret:
471 tuner_dbg("%s firmware for type=", (i < 0) ? "Can't find" : "Found");
472 if (debug) {
473 dump_firm_type(type);
474 printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
475 }
476 return i;
477}
478
479static int load_firmware(struct dvb_frontend *fe, unsigned int type,
480 v4l2_std_id *id)
481{
482 struct xc2028_data *priv = fe->tuner_priv;
483 int pos, rc;
484 unsigned char *p, *endp, buf[priv->ctrl.max_len];
485
486 tuner_dbg("%s called\n", __FUNCTION__);
487
488 pos = seek_firmware(fe, type, id);
489 if (pos < 0)
490 return pos;
491
492 tuner_info("Loading firmware for type=");
493 dump_firm_type(priv->firm[pos].type);
494 printk("(%x), id %016llx.\n", priv->firm[pos].type,
495 (unsigned long long)*id);
496
497 p = priv->firm[pos].ptr;
498 endp = p + priv->firm[pos].size;
499
500 while (p < endp) {
501 __u16 size;
502
503 /* Checks if there's enough bytes to read */
504 if (p + sizeof(size) > endp) {
505 tuner_err("Firmware chunk size is wrong\n");
506 return -EINVAL;
507 }
508
509 size = le16_to_cpu(*(__u16 *) p);
510 p += sizeof(size);
511
512 if (size == 0xffff)
513 return 0;
514
515 if (!size) {
516 /* Special callback command received */
517 rc = priv->tuner_callback(priv->video_dev,
518 XC2028_TUNER_RESET, 0);
519 if (rc < 0) {
520 tuner_err("Error at RESET code %d\n",
521 (*p) & 0x7f);
522 return -EINVAL;
523 }
524 continue;
525 }
526 if (size >= 0xff00) {
527 switch (size) {
528 case 0xff00:
529 rc = priv->tuner_callback(priv->video_dev,
530 XC2028_RESET_CLK, 0);
531 if (rc < 0) {
532 tuner_err("Error at RESET code %d\n",
533 (*p) & 0x7f);
534 return -EINVAL;
535 }
536 break;
537 default:
538 tuner_info("Invalid RESET code %d\n",
539 size & 0x7f);
540 return -EINVAL;
541
542 }
543 continue;
544 }
545
546 /* Checks for a sleep command */
547 if (size & 0x8000) {
548 msleep(size & 0x7fff);
549 continue;
550 }
551
552 if ((size + p > endp)) {
553 tuner_err("missing bytes: need %d, have %d\n",
554 size, (int)(endp - p));
555 return -EINVAL;
556 }
557
558 buf[0] = *p;
559 p++;
560 size--;
561
562 /* Sends message chunks */
563 while (size > 0) {
564 int len = (size < priv->ctrl.max_len - 1) ?
565 size : priv->ctrl.max_len - 1;
566
567 memcpy(buf + 1, p, len);
568
569 rc = i2c_send(priv, buf, len + 1);
570 if (rc < 0) {
571 tuner_err("%d returned from send\n", rc);
572 return -EINVAL;
573 }
574
575 p += len;
576 size -= len;
577 }
578 }
579 return 0;
580}
581
582static int load_scode(struct dvb_frontend *fe, unsigned int type,
583 v4l2_std_id *id, __u16 int_freq, int scode)
584{
585 struct xc2028_data *priv = fe->tuner_priv;
586 int pos, rc;
587 unsigned char *p;
588
589 tuner_dbg("%s called\n", __FUNCTION__);
590
591 if (!int_freq) {
592 pos = seek_firmware(fe, type, id);
593 if (pos < 0)
594 return pos;
595 } else {
596 for (pos = 0; pos < priv->firm_size; pos++) {
597 if ((priv->firm[pos].int_freq == int_freq) &&
598 (priv->firm[pos].type & HAS_IF))
599 break;
600 }
601 if (pos == priv->firm_size)
602 return -ENOENT;
603 }
604
605 p = priv->firm[pos].ptr;
606
607 if (priv->firm[pos].type & HAS_IF) {
608 if (priv->firm[pos].size != 12 * 16 || scode >= 16)
609 return -EINVAL;
610 p += 12 * scode;
611 } else {
612 /* 16 SCODE entries per file; each SCODE entry is 12 bytes and
613 * has a 2-byte size header in the firmware format. */
614 if (priv->firm[pos].size != 14 * 16 || scode >= 16 ||
615 le16_to_cpu(*(__u16 *)(p + 14 * scode)) != 12)
616 return -EINVAL;
617 p += 14 * scode + 2;
618 }
619
620 tuner_info("Loading SCODE for type=");
621 dump_firm_type_and_int_freq(priv->firm[pos].type,
622 priv->firm[pos].int_freq);
623 printk("(%x), id %016llx.\n", priv->firm[pos].type,
624 (unsigned long long)*id);
625
626 if (priv->firm_version < 0x0202)
627 rc = send_seq(priv, {0x20, 0x00, 0x00, 0x00});
628 else
629 rc = send_seq(priv, {0xa0, 0x00, 0x00, 0x00});
630 if (rc < 0)
631 return -EIO;
632
633 rc = i2c_send(priv, p, 12);
634 if (rc < 0)
635 return -EIO;
636
637 rc = send_seq(priv, {0x00, 0x8c});
638 if (rc < 0)
639 return -EIO;
640
641 return 0;
642}
643
644static int check_firmware(struct dvb_frontend *fe, unsigned int type,
645 v4l2_std_id std, __u16 int_freq)
646{
647 struct xc2028_data *priv = fe->tuner_priv;
648 struct firmware_properties new_fw;
649 int rc = 0, is_retry = 0;
650 u16 version, hwmodel;
651 v4l2_std_id std0;
652
653 tuner_dbg("%s called\n", __FUNCTION__);
654
655 if (!priv->firm) {
656 if (!priv->ctrl.fname) {
657 tuner_info("xc2028/3028 firmware name not set!\n");
658 return -EINVAL;
659 }
660
661 rc = load_all_firmwares(fe);
662 if (rc < 0)
663 return rc;
664 }
665
666 if (priv->ctrl.mts && !(type & FM))
667 type |= MTS;
668
669retry:
670 new_fw.type = type;
671 new_fw.id = std;
672 new_fw.std_req = std;
673 new_fw.scode_table = SCODE | priv->ctrl.scode_table;
674 new_fw.scode_nr = 0;
675 new_fw.int_freq = int_freq;
676
677 tuner_dbg("checking firmware, user requested type=");
678 if (debug) {
679 dump_firm_type(new_fw.type);
680 printk("(%x), id %016llx, ", new_fw.type,
681 (unsigned long long)new_fw.std_req);
682 if (!int_freq) {
683 printk("scode_tbl ");
684 dump_firm_type(priv->ctrl.scode_table);
685 printk("(%x), ", priv->ctrl.scode_table);
686 } else
687 printk("int_freq %d, ", new_fw.int_freq);
688 printk("scode_nr %d\n", new_fw.scode_nr);
689 }
690
691 /* No need to reload base firmware if it matches */
692 if (((BASE | new_fw.type) & BASE_TYPES) ==
693 (priv->cur_fw.type & BASE_TYPES)) {
694 tuner_dbg("BASE firmware not changed.\n");
695 goto skip_base;
696 }
697
698 /* Updating BASE - forget about all currently loaded firmware */
699 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
700
701 /* Reset is needed before loading firmware */
702 rc = priv->tuner_callback(priv->video_dev,
703 XC2028_TUNER_RESET, 0);
704 if (rc < 0)
705 goto fail;
706
707 /* BASE firmwares are all std0 */
708 std0 = 0;
709 rc = load_firmware(fe, BASE | new_fw.type, &std0);
710 if (rc < 0) {
711 tuner_err("Error %d while loading base firmware\n",
712 rc);
713 goto fail;
714 }
715
716 /* Load INIT1, if needed */
717 tuner_dbg("Load init1 firmware, if exists\n");
718
719 rc = load_firmware(fe, BASE | INIT1 | new_fw.type, &std0);
720 if (rc == -ENOENT)
721 rc = load_firmware(fe, (BASE | INIT1 | new_fw.type) & ~F8MHZ,
722 &std0);
723 if (rc < 0 && rc != -ENOENT) {
724 tuner_err("Error %d while loading init1 firmware\n",
725 rc);
726 goto fail;
727 }
728
729skip_base:
730 /*
731 * No need to reload standard specific firmware if base firmware
732 * was not reloaded and requested video standards have not changed.
733 */
734 if (priv->cur_fw.type == (BASE | new_fw.type) &&
735 priv->cur_fw.std_req == std) {
736 tuner_dbg("Std-specific firmware already loaded.\n");
737 goto skip_std_specific;
738 }
739
740 /* Reloading std-specific firmware forces a SCODE update */
741 priv->cur_fw.scode_table = 0;
742
743 rc = load_firmware(fe, new_fw.type, &new_fw.id);
744 if (rc == -ENOENT)
745 rc = load_firmware(fe, new_fw.type & ~F8MHZ, &new_fw.id);
746
747 if (rc < 0)
748 goto fail;
749
750skip_std_specific:
751 if (priv->cur_fw.scode_table == new_fw.scode_table &&
752 priv->cur_fw.scode_nr == new_fw.scode_nr) {
753 tuner_dbg("SCODE firmware already loaded.\n");
754 goto check_device;
755 }
756
757 /* Load SCODE firmware, if exists */
758 tuner_dbg("Trying to load scode %d\n", new_fw.scode_nr);
759
760 rc = load_scode(fe, new_fw.type | new_fw.scode_table, &new_fw.id,
761 new_fw.int_freq, new_fw.scode_nr);
762
763check_device:
764 if (xc2028_get_reg(priv, 0x0004, &version) < 0 ||
765 xc2028_get_reg(priv, 0x0008, &hwmodel) < 0) {
766 tuner_err("Unable to read tuner registers.\n");
767 goto fail;
768 }
769
770 tuner_info("Device is Xceive %d version %d.%d, "
771 "firmware version %d.%d\n",
772 hwmodel, (version & 0xf000) >> 12, (version & 0xf00) >> 8,
773 (version & 0xf0) >> 4, version & 0xf);
774
775 /* Check firmware version against what we downloaded. */
776 if (priv->firm_version != ((version & 0xf0) << 4 | (version & 0x0f))) {
777 tuner_err("Incorrect readback of firmware version.\n");
778 goto fail;
779 }
780
781 /* Check that the tuner hardware model remains consistent over time. */
782 if (priv->hwmodel == 0 && (hwmodel == 2028 || hwmodel == 3028)) {
783 priv->hwmodel = hwmodel;
784 priv->hwvers = version & 0xff00;
785 } else if (priv->hwmodel == 0 || priv->hwmodel != hwmodel ||
786 priv->hwvers != (version & 0xff00)) {
787 tuner_err("Read invalid device hardware information - tuner "
788 "hung?\n");
789 goto fail;
790 }
791
792 memcpy(&priv->cur_fw, &new_fw, sizeof(priv->cur_fw));
793
794 /*
795 * By setting BASE in cur_fw.type only after successfully loading all
796 * firmwares, we can:
797 * 1. Identify that BASE firmware with type=0 has been loaded;
798 * 2. Tell whether BASE firmware was just changed the next time through.
799 */
800 priv->cur_fw.type |= BASE;
801
802 return 0;
803
804fail:
805 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
806 if (!is_retry) {
807 msleep(50);
808 is_retry = 1;
809 tuner_dbg("Retrying firmware load\n");
810 goto retry;
811 }
812
813 if (rc == -ENOENT)
814 rc = -EINVAL;
815 return rc;
816}
817
818static int xc2028_signal(struct dvb_frontend *fe, u16 *strength)
819{
820 struct xc2028_data *priv = fe->tuner_priv;
821 u16 frq_lock, signal = 0;
822 int rc;
823
824 tuner_dbg("%s called\n", __FUNCTION__);
825
826 mutex_lock(&priv->lock);
827
828 /* Sync Lock Indicator */
829 rc = xc2028_get_reg(priv, 0x0002, &frq_lock);
830 if (rc < 0 || frq_lock == 0)
831 goto ret;
832
833 /* Frequency is locked. Return signal quality */
834
835 /* Get SNR of the video signal */
836 rc = xc2028_get_reg(priv, 0x0040, &signal);
837 if (rc < 0)
838 signal = -frq_lock;
839
840ret:
841 mutex_unlock(&priv->lock);
842
843 *strength = signal;
844
845 return rc;
846}
847
848#define DIV 15625
849
850static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
851 enum tuner_mode new_mode,
852 unsigned int type,
853 v4l2_std_id std,
854 u16 int_freq)
855{
856 struct xc2028_data *priv = fe->tuner_priv;
857 int rc = -EINVAL;
858 unsigned char buf[4];
859 u32 div, offset = 0;
860
861 tuner_dbg("%s called\n", __FUNCTION__);
862
863 mutex_lock(&priv->lock);
864
865 tuner_dbg("should set frequency %d kHz\n", freq / 1000);
866
867 if (check_firmware(fe, type, std, int_freq) < 0)
868 goto ret;
869
870 /* On some cases xc2028 can disable video output, if
871 * very weak signals are received. By sending a soft
872 * reset, this is re-enabled. So, it is better to always
873 * send a soft reset before changing channels, to be sure
874 * that xc2028 will be in a safe state.
875 * Maybe this might also be needed for DTV.
876 */
877 if (new_mode == T_ANALOG_TV) {
878 rc = send_seq(priv, {0x00, 0x00});
879 } else if (priv->cur_fw.type & ATSC) {
880 offset = 1750000;
881 } else {
882 offset = 2750000;
883 /*
884 * We must adjust the offset by 500kHz in two cases in order
885 * to correctly center the IF output:
886 * 1) When the ZARLINK456 or DIBCOM52 tables were explicitly
887 * selected and a 7MHz channel is tuned;
888 * 2) When tuning a VHF channel with DTV78 firmware.
889 */
890 if (((priv->cur_fw.type & DTV7) &&
891 (priv->cur_fw.scode_table & (ZARLINK456 | DIBCOM52))) ||
892 ((priv->cur_fw.type & DTV78) && freq < 470000000))
893 offset -= 500000;
894 }
895
896 div = (freq - offset + DIV / 2) / DIV;
897
898 /* CMD= Set frequency */
899 if (priv->firm_version < 0x0202)
900 rc = send_seq(priv, {0x00, 0x02, 0x00, 0x00});
901 else
902 rc = send_seq(priv, {0x80, 0x02, 0x00, 0x00});
903 if (rc < 0)
904 goto ret;
905
906 rc = priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1);
907 if (rc < 0)
908 goto ret;
909
910 msleep(10);
911
912 buf[0] = 0xff & (div >> 24);
913 buf[1] = 0xff & (div >> 16);
914 buf[2] = 0xff & (div >> 8);
915 buf[3] = 0xff & (div);
916
917 rc = i2c_send(priv, buf, sizeof(buf));
918 if (rc < 0)
919 goto ret;
920 msleep(100);
921
922 priv->frequency = freq;
923
924 tuner_dbg("divisor= %02x %02x %02x %02x (freq=%d.%03d)\n",
925 buf[0], buf[1], buf[2], buf[3],
926 freq / 1000000, (freq % 1000000) / 1000);
927
928 rc = 0;
929
930ret:
931 mutex_unlock(&priv->lock);
932
933 return rc;
934}
935
936static int xc2028_set_analog_freq(struct dvb_frontend *fe,
937 struct analog_parameters *p)
938{
939 struct xc2028_data *priv = fe->tuner_priv;
940 unsigned int type=0;
941
942 tuner_dbg("%s called\n", __FUNCTION__);
943
944 if (p->mode == V4L2_TUNER_RADIO) {
945 type |= FM;
946 if (priv->ctrl.input1)
947 type |= INPUT1;
948 return generic_set_freq(fe, (625l * p->frequency) / 10,
949 T_ANALOG_TV, type, 0, 0);
950 }
951
952 /* if std is not defined, choose one */
953 if (!p->std)
954 p->std = V4L2_STD_MN;
955
956 /* PAL/M, PAL/N, PAL/Nc and NTSC variants should use 6MHz firmware */
957 if (!(p->std & V4L2_STD_MN))
958 type |= F8MHZ;
959
960 /* Add audio hack to std mask */
961 p->std |= parse_audio_std_option();
962
963 return generic_set_freq(fe, 62500l * p->frequency,
964 T_ANALOG_TV, type, p->std, 0);
965}
966
967static int xc2028_set_params(struct dvb_frontend *fe,
968 struct dvb_frontend_parameters *p)
969{
970 struct xc2028_data *priv = fe->tuner_priv;
971 unsigned int type=0;
972 fe_bandwidth_t bw = BANDWIDTH_8_MHZ;
973 u16 demod = 0;
974
975 tuner_dbg("%s called\n", __FUNCTION__);
976
977 if (priv->ctrl.d2633)
978 type |= D2633;
979 else
980 type |= D2620;
981
982 switch(fe->ops.info.type) {
983 case FE_OFDM:
984 bw = p->u.ofdm.bandwidth;
985 break;
986 case FE_QAM:
987 tuner_info("WARN: There are some reports that "
988 "QAM 6 MHz doesn't work.\n"
989 "If this works for you, please report by "
990 "e-mail to: v4l-dvb-maintainer@linuxtv.org\n");
991 bw = BANDWIDTH_6_MHZ;
992 type |= QAM;
993 break;
994 case FE_ATSC:
995 bw = BANDWIDTH_6_MHZ;
996 /* The only ATSC firmware (at least on v2.7) is D2633,
997 so overrides ctrl->d2633 */
998 type |= ATSC| D2633;
999 type &= ~D2620;
1000 break;
1001 /* DVB-S is not supported */
1002 default:
1003 return -EINVAL;
1004 }
1005
1006 switch (bw) {
1007 case BANDWIDTH_8_MHZ:
1008 if (p->frequency < 470000000)
1009 priv->ctrl.vhfbw7 = 0;
1010 else
1011 priv->ctrl.uhfbw8 = 1;
1012 type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV8;
1013 type |= F8MHZ;
1014 break;
1015 case BANDWIDTH_7_MHZ:
1016 if (p->frequency < 470000000)
1017 priv->ctrl.vhfbw7 = 1;
1018 else
1019 priv->ctrl.uhfbw8 = 0;
1020 type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV7;
1021 type |= F8MHZ;
1022 break;
1023 case BANDWIDTH_6_MHZ:
1024 type |= DTV6;
1025 priv->ctrl.vhfbw7 = 0;
1026 priv->ctrl.uhfbw8 = 0;
1027 break;
1028 default:
1029 tuner_err("error: bandwidth not supported.\n");
1030 };
1031
1032 /* All S-code tables need a 200kHz shift */
1033 if (priv->ctrl.demod)
1034 demod = priv->ctrl.demod + 200;
1035
1036 return generic_set_freq(fe, p->frequency,
1037 T_DIGITAL_TV, type, 0, demod);
1038}
1039
1040static int xc2028_sleep(struct dvb_frontend *fe)
1041{
1042 struct xc2028_data *priv = fe->tuner_priv;
1043 int rc = 0;
1044
1045 tuner_dbg("%s called\n", __FUNCTION__);
1046
1047 mutex_lock(&priv->lock);
1048
1049 if (priv->firm_version < 0x0202)
1050 rc = send_seq(priv, {0x00, 0x08, 0x00, 0x00});
1051 else
1052 rc = send_seq(priv, {0x80, 0x08, 0x00, 0x00});
1053
1054 priv->cur_fw.type = 0; /* need firmware reload */
1055
1056 mutex_unlock(&priv->lock);
1057
1058 return rc;
1059}
1060
1061
1062static int xc2028_dvb_release(struct dvb_frontend *fe)
1063{
1064 struct xc2028_data *priv = fe->tuner_priv;
1065
1066 tuner_dbg("%s called\n", __FUNCTION__);
1067
1068 mutex_lock(&xc2028_list_mutex);
1069
1070 priv->count--;
1071
1072 if (!priv->count) {
1073 list_del(&priv->xc2028_list);
1074
1075 kfree(priv->ctrl.fname);
1076
1077 free_firmware(priv);
1078 kfree(priv);
1079 fe->tuner_priv = NULL;
1080 }
1081
1082 mutex_unlock(&xc2028_list_mutex);
1083
1084 return 0;
1085}
1086
1087static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency)
1088{
1089 struct xc2028_data *priv = fe->tuner_priv;
1090
1091 tuner_dbg("%s called\n", __FUNCTION__);
1092
1093 *frequency = priv->frequency;
1094
1095 return 0;
1096}
1097
1098static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
1099{
1100 struct xc2028_data *priv = fe->tuner_priv;
1101 struct xc2028_ctrl *p = priv_cfg;
1102 int rc = 0;
1103
1104 tuner_dbg("%s called\n", __FUNCTION__);
1105
1106 mutex_lock(&priv->lock);
1107
1108 kfree(priv->ctrl.fname);
1109 free_firmware(priv);
1110
1111 memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
1112 priv->ctrl.fname = NULL;
1113
1114 if (p->fname) {
1115 priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
1116 if (priv->ctrl.fname == NULL)
1117 rc = -ENOMEM;
1118 }
1119
1120 if (priv->ctrl.max_len < 9)
1121 priv->ctrl.max_len = 13;
1122
1123 mutex_unlock(&priv->lock);
1124
1125 return rc;
1126}
1127
1128static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
1129 .info = {
1130 .name = "Xceive XC3028",
1131 .frequency_min = 42000000,
1132 .frequency_max = 864000000,
1133 .frequency_step = 50000,
1134 },
1135
1136 .set_config = xc2028_set_config,
1137 .set_analog_params = xc2028_set_analog_freq,
1138 .release = xc2028_dvb_release,
1139 .get_frequency = xc2028_get_frequency,
1140 .get_rf_strength = xc2028_signal,
1141 .set_params = xc2028_set_params,
1142 .sleep = xc2028_sleep,
1143
1144};
1145
1146struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
1147 struct xc2028_config *cfg)
1148{
1149 struct xc2028_data *priv;
1150 void *video_dev;
1151
1152 if (debug)
1153 printk(KERN_DEBUG PREFIX ": Xcv2028/3028 init called!\n");
1154
1155 if (NULL == cfg || NULL == cfg->video_dev)
1156 return NULL;
1157
1158 if (!fe) {
1159 printk(KERN_ERR PREFIX ": No frontend!\n");
1160 return NULL;
1161 }
1162
1163 video_dev = cfg->video_dev;
1164
1165 mutex_lock(&xc2028_list_mutex);
1166
1167 list_for_each_entry(priv, &xc2028_list, xc2028_list) {
1168 if (priv->video_dev == cfg->video_dev) {
1169 video_dev = NULL;
1170 break;
1171 }
1172 }
1173
1174 if (video_dev) {
1175 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1176 if (priv == NULL) {
1177 mutex_unlock(&xc2028_list_mutex);
1178 return NULL;
1179 }
1180
1181 priv->i2c_props.addr = cfg->i2c_addr;
1182 priv->i2c_props.adap = cfg->i2c_adap;
1183 priv->video_dev = video_dev;
1184 priv->tuner_callback = cfg->callback;
1185 priv->ctrl.max_len = 13;
1186
1187 mutex_init(&priv->lock);
1188
1189 list_add_tail(&priv->xc2028_list, &xc2028_list);
1190 }
1191
1192 fe->tuner_priv = priv;
1193 priv->count++;
1194
1195 memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops,
1196 sizeof(xc2028_dvb_tuner_ops));
1197
1198 tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
1199
1200 if (cfg->ctrl)
1201 xc2028_set_config(fe, cfg->ctrl);
1202
1203 mutex_unlock(&xc2028_list_mutex);
1204
1205 return fe;
1206}
1207
1208EXPORT_SYMBOL(xc2028_attach);
1209
1210MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
1211MODULE_AUTHOR("Michel Ludwig <michel.ludwig@gmail.com>");
1212MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
1213MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/tuner-xc2028.h b/drivers/media/video/tuner-xc2028.h
new file mode 100644
index 000000000000..3eb8420379a4
--- /dev/null
+++ b/drivers/media/video/tuner-xc2028.h
@@ -0,0 +1,63 @@
1/* tuner-xc2028
2 *
3 * Copyright (c) 2007 Mauro Carvalho Chehab (mchehab@infradead.org)
4 * This code is placed under the terms of the GNU General Public License v2
5 */
6
7#ifndef __TUNER_XC2028_H__
8#define __TUNER_XC2028_H__
9
10#include "dvb_frontend.h"
11
12#define XC2028_DEFAULT_FIRMWARE "xc3028-v27.fw"
13
14/* Dmoduler IF (kHz) */
15#define XC3028_FE_DEFAULT 0
16#define XC3028_FE_LG60 6000
17#define XC3028_FE_ATI638 6380
18#define XC3028_FE_OREN538 5380
19#define XC3028_FE_OREN36 3600
20#define XC3028_FE_TOYOTA388 3880
21#define XC3028_FE_TOYOTA794 7940
22#define XC3028_FE_DIBCOM52 5200
23#define XC3028_FE_ZARLINK456 4560
24#define XC3028_FE_CHINA 5200
25
26struct xc2028_ctrl {
27 char *fname;
28 int max_len;
29 unsigned int scode_table;
30 unsigned int mts :1;
31 unsigned int d2633 :1;
32 unsigned int input1:1;
33 unsigned int vhfbw7:1;
34 unsigned int uhfbw8:1;
35 unsigned int demod;
36};
37
38struct xc2028_config {
39 struct i2c_adapter *i2c_adap;
40 u8 i2c_addr;
41 void *video_dev;
42 struct xc2028_ctrl *ctrl;
43 int (*callback) (void *dev, int command, int arg);
44};
45
46/* xc2028 commands for callback */
47#define XC2028_TUNER_RESET 0
48#define XC2028_RESET_CLK 1
49
50#if defined(CONFIG_TUNER_XC2028) || (defined(CONFIG_TUNER_XC2028_MODULE) && defined(MODULE))
51extern struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
52 struct xc2028_config *cfg);
53#else
54static inline struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
55 struct xc2028_config *cfg)
56{
57 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
58 __FUNCTION__);
59 return NULL;
60}
61#endif
62
63#endif /* __TUNER_XC2028_H__ */
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index a19cdcc17ef7..a75560540e79 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -31,6 +31,7 @@
31#include <media/tvaudio.h> 31#include <media/tvaudio.h>
32#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33#include <media/v4l2-chip-ident.h> 33#include <media/v4l2-chip-ident.h>
34#include <media/v4l2-i2c-drv-legacy.h>
34 35
35#include <media/i2c-addr.h> 36#include <media/i2c-addr.h>
36 37
@@ -109,7 +110,7 @@ static struct CHIPDESC chiplist[];
109 110
110/* current state of the chip */ 111/* current state of the chip */
111struct CHIPSTATE { 112struct CHIPSTATE {
112 struct i2c_client c; 113 struct i2c_client *c;
113 114
114 /* index into CHIPDESC array */ 115 /* index into CHIPDESC array */
115 int type; 116 int type;
@@ -145,10 +146,6 @@ static unsigned short normal_i2c[] = {
145 I2C_CLIENT_END }; 146 I2C_CLIENT_END };
146I2C_CLIENT_INSMOD; 147I2C_CLIENT_INSMOD;
147 148
148static struct i2c_driver driver;
149static struct i2c_client client_template;
150
151
152/* ---------------------------------------------------------------------- */ 149/* ---------------------------------------------------------------------- */
153/* i2c I/O functions */ 150/* i2c I/O functions */
154 151
@@ -157,24 +154,24 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val)
157 unsigned char buffer[2]; 154 unsigned char buffer[2];
158 155
159 if (-1 == subaddr) { 156 if (-1 == subaddr) {
160 v4l_dbg(1, debug, &chip->c, "%s: chip_write: 0x%x\n", 157 v4l_dbg(1, debug, chip->c, "%s: chip_write: 0x%x\n",
161 chip->c.name, val); 158 chip->c->name, val);
162 chip->shadow.bytes[1] = val; 159 chip->shadow.bytes[1] = val;
163 buffer[0] = val; 160 buffer[0] = val;
164 if (1 != i2c_master_send(&chip->c,buffer,1)) { 161 if (1 != i2c_master_send(chip->c,buffer,1)) {
165 v4l_warn(&chip->c, "%s: I/O error (write 0x%x)\n", 162 v4l_warn(chip->c, "%s: I/O error (write 0x%x)\n",
166 chip->c.name, val); 163 chip->c->name, val);
167 return -1; 164 return -1;
168 } 165 }
169 } else { 166 } else {
170 v4l_dbg(1, debug, &chip->c, "%s: chip_write: reg%d=0x%x\n", 167 v4l_dbg(1, debug, chip->c, "%s: chip_write: reg%d=0x%x\n",
171 chip->c.name, subaddr, val); 168 chip->c->name, subaddr, val);
172 chip->shadow.bytes[subaddr+1] = val; 169 chip->shadow.bytes[subaddr+1] = val;
173 buffer[0] = subaddr; 170 buffer[0] = subaddr;
174 buffer[1] = val; 171 buffer[1] = val;
175 if (2 != i2c_master_send(&chip->c,buffer,2)) { 172 if (2 != i2c_master_send(chip->c,buffer,2)) {
176 v4l_warn(&chip->c, "%s: I/O error (write reg%d=0x%x)\n", 173 v4l_warn(chip->c, "%s: I/O error (write reg%d=0x%x)\n",
177 chip->c.name, subaddr, val); 174 chip->c->name, subaddr, val);
178 return -1; 175 return -1;
179 } 176 }
180 } 177 }
@@ -197,12 +194,12 @@ static int chip_read(struct CHIPSTATE *chip)
197{ 194{
198 unsigned char buffer; 195 unsigned char buffer;
199 196
200 if (1 != i2c_master_recv(&chip->c,&buffer,1)) { 197 if (1 != i2c_master_recv(chip->c,&buffer,1)) {
201 v4l_warn(&chip->c, "%s: I/O error (read)\n", 198 v4l_warn(chip->c, "%s: I/O error (read)\n",
202 chip->c.name); 199 chip->c->name);
203 return -1; 200 return -1;
204 } 201 }
205 v4l_dbg(1, debug, &chip->c, "%s: chip_read: 0x%x\n",chip->c.name, buffer); 202 v4l_dbg(1, debug, chip->c, "%s: chip_read: 0x%x\n",chip->c->name, buffer);
206 return buffer; 203 return buffer;
207} 204}
208 205
@@ -211,17 +208,17 @@ static int chip_read2(struct CHIPSTATE *chip, int subaddr)
211 unsigned char write[1]; 208 unsigned char write[1];
212 unsigned char read[1]; 209 unsigned char read[1];
213 struct i2c_msg msgs[2] = { 210 struct i2c_msg msgs[2] = {
214 { chip->c.addr, 0, 1, write }, 211 { chip->c->addr, 0, 1, write },
215 { chip->c.addr, I2C_M_RD, 1, read } 212 { chip->c->addr, I2C_M_RD, 1, read }
216 }; 213 };
217 write[0] = subaddr; 214 write[0] = subaddr;
218 215
219 if (2 != i2c_transfer(chip->c.adapter,msgs,2)) { 216 if (2 != i2c_transfer(chip->c->adapter,msgs,2)) {
220 v4l_warn(&chip->c, "%s: I/O error (read2)\n", chip->c.name); 217 v4l_warn(chip->c, "%s: I/O error (read2)\n", chip->c->name);
221 return -1; 218 return -1;
222 } 219 }
223 v4l_dbg(1, debug, &chip->c, "%s: chip_read2: reg%d=0x%x\n", 220 v4l_dbg(1, debug, chip->c, "%s: chip_read2: reg%d=0x%x\n",
224 chip->c.name, subaddr,read[0]); 221 chip->c->name, subaddr,read[0]);
225 return read[0]; 222 return read[0];
226} 223}
227 224
@@ -233,8 +230,8 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
233 return 0; 230 return 0;
234 231
235 /* update our shadow register set; print bytes if (debug > 0) */ 232 /* update our shadow register set; print bytes if (debug > 0) */
236 v4l_dbg(1, debug, &chip->c, "%s: chip_cmd(%s): reg=%d, data:", 233 v4l_dbg(1, debug, chip->c, "%s: chip_cmd(%s): reg=%d, data:",
237 chip->c.name, name,cmd->bytes[0]); 234 chip->c->name, name,cmd->bytes[0]);
238 for (i = 1; i < cmd->count; i++) { 235 for (i = 1; i < cmd->count; i++) {
239 if (debug) 236 if (debug)
240 printk(" 0x%x",cmd->bytes[i]); 237 printk(" 0x%x",cmd->bytes[i]);
@@ -244,8 +241,8 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
244 printk("\n"); 241 printk("\n");
245 242
246 /* send data to the chip */ 243 /* send data to the chip */
247 if (cmd->count != i2c_master_send(&chip->c,cmd->bytes,cmd->count)) { 244 if (cmd->count != i2c_master_send(chip->c,cmd->bytes,cmd->count)) {
248 v4l_warn(&chip->c, "%s: I/O error (%s)\n", chip->c.name, name); 245 v4l_warn(chip->c, "%s: I/O error (%s)\n", chip->c->name, name);
249 return -1; 246 return -1;
250 } 247 }
251 return 0; 248 return 0;
@@ -269,7 +266,7 @@ static int chip_thread(void *data)
269 struct CHIPSTATE *chip = data; 266 struct CHIPSTATE *chip = data;
270 struct CHIPDESC *desc = chiplist + chip->type; 267 struct CHIPDESC *desc = chiplist + chip->type;
271 268
272 v4l_dbg(1, debug, &chip->c, "%s: thread started\n", chip->c.name); 269 v4l_dbg(1, debug, chip->c, "%s: thread started\n", chip->c->name);
273 set_freezable(); 270 set_freezable();
274 for (;;) { 271 for (;;) {
275 set_current_state(TASK_INTERRUPTIBLE); 272 set_current_state(TASK_INTERRUPTIBLE);
@@ -279,7 +276,7 @@ static int chip_thread(void *data)
279 try_to_freeze(); 276 try_to_freeze();
280 if (kthread_should_stop()) 277 if (kthread_should_stop())
281 break; 278 break;
282 v4l_dbg(1, debug, &chip->c, "%s: thread wakeup\n", chip->c.name); 279 v4l_dbg(1, debug, chip->c, "%s: thread wakeup\n", chip->c->name);
283 280
284 /* don't do anything for radio or if mode != auto */ 281 /* don't do anything for radio or if mode != auto */
285 if (chip->radio || chip->mode != 0) 282 if (chip->radio || chip->mode != 0)
@@ -292,7 +289,7 @@ static int chip_thread(void *data)
292 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); 289 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000));
293 } 290 }
294 291
295 v4l_dbg(1, debug, &chip->c, "%s: thread exiting\n", chip->c.name); 292 v4l_dbg(1, debug, chip->c, "%s: thread exiting\n", chip->c->name);
296 return 0; 293 return 0;
297} 294}
298 295
@@ -304,17 +301,19 @@ static void generic_checkmode(struct CHIPSTATE *chip)
304 if (mode == chip->prevmode) 301 if (mode == chip->prevmode)
305 return; 302 return;
306 303
307 v4l_dbg(1, debug, &chip->c, "%s: thread checkmode\n", chip->c.name); 304 v4l_dbg(1, debug, chip->c, "%s: thread checkmode\n", chip->c->name);
308 chip->prevmode = mode; 305 chip->prevmode = mode;
309 306
310 if (mode & VIDEO_SOUND_STEREO) 307 if (mode & V4L2_TUNER_MODE_STEREO)
311 desc->setmode(chip,VIDEO_SOUND_STEREO); 308 desc->setmode(chip,V4L2_TUNER_MODE_STEREO);
312 else if (mode & VIDEO_SOUND_LANG1) 309 if (mode & V4L2_TUNER_MODE_LANG1_LANG2)
313 desc->setmode(chip,VIDEO_SOUND_LANG1); 310 desc->setmode(chip,V4L2_TUNER_MODE_STEREO);
314 else if (mode & VIDEO_SOUND_LANG2) 311 else if (mode & V4L2_TUNER_MODE_LANG1)
315 desc->setmode(chip,VIDEO_SOUND_LANG2); 312 desc->setmode(chip,V4L2_TUNER_MODE_LANG1);
313 else if (mode & V4L2_TUNER_MODE_LANG2)
314 desc->setmode(chip,V4L2_TUNER_MODE_LANG2);
316 else 315 else
317 desc->setmode(chip,VIDEO_SOUND_MONO); 316 desc->setmode(chip,V4L2_TUNER_MODE_MONO);
318} 317}
319 318
320/* ---------------------------------------------------------------------- */ 319/* ---------------------------------------------------------------------- */
@@ -345,13 +344,13 @@ static int tda9840_getmode(struct CHIPSTATE *chip)
345 int val, mode; 344 int val, mode;
346 345
347 val = chip_read(chip); 346 val = chip_read(chip);
348 mode = VIDEO_SOUND_MONO; 347 mode = V4L2_TUNER_MODE_MONO;
349 if (val & TDA9840_DS_DUAL) 348 if (val & TDA9840_DS_DUAL)
350 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 349 mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
351 if (val & TDA9840_ST_STEREO) 350 if (val & TDA9840_ST_STEREO)
352 mode |= VIDEO_SOUND_STEREO; 351 mode |= V4L2_TUNER_MODE_STEREO;
353 352
354 v4l_dbg(1, debug, &chip->c, "tda9840_getmode(): raw chip read: %d, return: %d\n", 353 v4l_dbg(1, debug, chip->c, "tda9840_getmode(): raw chip read: %d, return: %d\n",
355 val, mode); 354 val, mode);
356 return mode; 355 return mode;
357} 356}
@@ -362,16 +361,16 @@ static void tda9840_setmode(struct CHIPSTATE *chip, int mode)
362 int t = chip->shadow.bytes[TDA9840_SW + 1] & ~0x7e; 361 int t = chip->shadow.bytes[TDA9840_SW + 1] & ~0x7e;
363 362
364 switch (mode) { 363 switch (mode) {
365 case VIDEO_SOUND_MONO: 364 case V4L2_TUNER_MODE_MONO:
366 t |= TDA9840_MONO; 365 t |= TDA9840_MONO;
367 break; 366 break;
368 case VIDEO_SOUND_STEREO: 367 case V4L2_TUNER_MODE_STEREO:
369 t |= TDA9840_STEREO; 368 t |= TDA9840_STEREO;
370 break; 369 break;
371 case VIDEO_SOUND_LANG1: 370 case V4L2_TUNER_MODE_LANG1:
372 t |= TDA9840_DUALA; 371 t |= TDA9840_DUALA;
373 break; 372 break;
374 case VIDEO_SOUND_LANG2: 373 case V4L2_TUNER_MODE_LANG2:
375 t |= TDA9840_DUALB; 374 t |= TDA9840_DUALB;
376 break; 375 break;
377 default: 376 default:
@@ -502,7 +501,7 @@ static int tda985x_getmode(struct CHIPSTATE *chip)
502 chip_read(chip)) >> 4; 501 chip_read(chip)) >> 4;
503 /* Add mono mode regardless of SAP and stereo */ 502 /* Add mono mode regardless of SAP and stereo */
504 /* Allows forced mono */ 503 /* Allows forced mono */
505 return mode | VIDEO_SOUND_MONO; 504 return mode | V4L2_TUNER_MODE_MONO;
506} 505}
507 506
508static void tda985x_setmode(struct CHIPSTATE *chip, int mode) 507static void tda985x_setmode(struct CHIPSTATE *chip, int mode)
@@ -511,13 +510,13 @@ static void tda985x_setmode(struct CHIPSTATE *chip, int mode)
511 int c6 = chip->shadow.bytes[TDA985x_C6+1] & 0x3f; 510 int c6 = chip->shadow.bytes[TDA985x_C6+1] & 0x3f;
512 511
513 switch (mode) { 512 switch (mode) {
514 case VIDEO_SOUND_MONO: 513 case V4L2_TUNER_MODE_MONO:
515 c6 |= TDA985x_MONO; 514 c6 |= TDA985x_MONO;
516 break; 515 break;
517 case VIDEO_SOUND_STEREO: 516 case V4L2_TUNER_MODE_STEREO:
518 c6 |= TDA985x_STEREO; 517 c6 |= TDA985x_STEREO;
519 break; 518 break;
520 case VIDEO_SOUND_LANG1: 519 case V4L2_TUNER_MODE_LANG1:
521 c6 |= TDA985x_SAP; 520 c6 |= TDA985x_SAP;
522 break; 521 break;
523 default: 522 default:
@@ -650,12 +649,12 @@ static int tda9873_getmode(struct CHIPSTATE *chip)
650 int val,mode; 649 int val,mode;
651 650
652 val = chip_read(chip); 651 val = chip_read(chip);
653 mode = VIDEO_SOUND_MONO; 652 mode = V4L2_TUNER_MODE_MONO;
654 if (val & TDA9873_STEREO) 653 if (val & TDA9873_STEREO)
655 mode |= VIDEO_SOUND_STEREO; 654 mode |= V4L2_TUNER_MODE_STEREO;
656 if (val & TDA9873_DUAL) 655 if (val & TDA9873_DUAL)
657 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 656 mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
658 v4l_dbg(1, debug, &chip->c, "tda9873_getmode(): raw chip read: %d, return: %d\n", 657 v4l_dbg(1, debug, chip->c, "tda9873_getmode(): raw chip read: %d, return: %d\n",
659 val, mode); 658 val, mode);
660 return mode; 659 return mode;
661} 660}
@@ -666,24 +665,24 @@ static void tda9873_setmode(struct CHIPSTATE *chip, int mode)
666 /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */ 665 /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */
667 666
668 if ((sw_data & TDA9873_INP_MASK) != TDA9873_INTERNAL) { 667 if ((sw_data & TDA9873_INP_MASK) != TDA9873_INTERNAL) {
669 v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): external input\n"); 668 v4l_dbg(1, debug, chip->c, "tda9873_setmode(): external input\n");
670 return; 669 return;
671 } 670 }
672 671
673 v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]); 672 v4l_dbg(1, debug, chip->c, "tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]);
674 v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): sw_data = %d\n", sw_data); 673 v4l_dbg(1, debug, chip->c, "tda9873_setmode(): sw_data = %d\n", sw_data);
675 674
676 switch (mode) { 675 switch (mode) {
677 case VIDEO_SOUND_MONO: 676 case V4L2_TUNER_MODE_MONO:
678 sw_data |= TDA9873_TR_MONO; 677 sw_data |= TDA9873_TR_MONO;
679 break; 678 break;
680 case VIDEO_SOUND_STEREO: 679 case V4L2_TUNER_MODE_STEREO:
681 sw_data |= TDA9873_TR_STEREO; 680 sw_data |= TDA9873_TR_STEREO;
682 break; 681 break;
683 case VIDEO_SOUND_LANG1: 682 case V4L2_TUNER_MODE_LANG1:
684 sw_data |= TDA9873_TR_DUALA; 683 sw_data |= TDA9873_TR_DUALA;
685 break; 684 break;
686 case VIDEO_SOUND_LANG2: 685 case V4L2_TUNER_MODE_LANG2:
687 sw_data |= TDA9873_TR_DUALB; 686 sw_data |= TDA9873_TR_DUALB;
688 break; 687 break;
689 default: 688 default:
@@ -692,7 +691,7 @@ static void tda9873_setmode(struct CHIPSTATE *chip, int mode)
692 } 691 }
693 692
694 chip_write(chip, TDA9873_SW, sw_data); 693 chip_write(chip, TDA9873_SW, sw_data);
695 v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): req. mode %d; chip_write: %d\n", 694 v4l_dbg(1, debug, chip->c, "tda9873_setmode(): req. mode %d; chip_write: %d\n",
696 mode, sw_data); 695 mode, sw_data);
697} 696}
698 697
@@ -831,7 +830,7 @@ static int tda9874a_setup(struct CHIPSTATE *chip)
831 chip_write(chip, TDA9874A_SDACOSR, (tda9874a_mode) ? 0x81:0x80); 830 chip_write(chip, TDA9874A_SDACOSR, (tda9874a_mode) ? 0x81:0x80);
832 chip_write(chip, TDA9874A_AOSR, 0x00); /* or 0x10 */ 831 chip_write(chip, TDA9874A_AOSR, 0x00); /* or 0x10 */
833 } 832 }
834 v4l_dbg(1, debug, &chip->c, "tda9874a_setup(): %s [0x%02X].\n", 833 v4l_dbg(1, debug, chip->c, "tda9874a_setup(): %s [0x%02X].\n",
835 tda9874a_modelist[tda9874a_STD].name,tda9874a_STD); 834 tda9874a_modelist[tda9874a_STD].name,tda9874a_STD);
836 return 1; 835 return 1;
837} 836}
@@ -841,7 +840,7 @@ static int tda9874a_getmode(struct CHIPSTATE *chip)
841 int dsr,nsr,mode; 840 int dsr,nsr,mode;
842 int necr; /* just for debugging */ 841 int necr; /* just for debugging */
843 842
844 mode = VIDEO_SOUND_MONO; 843 mode = V4L2_TUNER_MODE_MONO;
845 844
846 if(-1 == (dsr = chip_read2(chip,TDA9874A_DSR))) 845 if(-1 == (dsr = chip_read2(chip,TDA9874A_DSR)))
847 return mode; 846 return mode;
@@ -860,21 +859,21 @@ static int tda9874a_getmode(struct CHIPSTATE *chip)
860 * that sound has (temporarily) switched from NICAM to 859 * that sound has (temporarily) switched from NICAM to
861 * mono FM (or AM) on 1st sound carrier due to high NICAM bit 860 * mono FM (or AM) on 1st sound carrier due to high NICAM bit
862 * error count. So in fact there is no stereo in this case :-( 861 * error count. So in fact there is no stereo in this case :-(
863 * But changing the mode to VIDEO_SOUND_MONO would switch 862 * But changing the mode to V4L2_TUNER_MODE_MONO would switch
864 * external 4052 multiplexer in audio_hook(). 863 * external 4052 multiplexer in audio_hook().
865 */ 864 */
866 if(nsr & 0x02) /* NSR.S/MB=1 */ 865 if(nsr & 0x02) /* NSR.S/MB=1 */
867 mode |= VIDEO_SOUND_STEREO; 866 mode |= V4L2_TUNER_MODE_STEREO;
868 if(nsr & 0x01) /* NSR.D/SB=1 */ 867 if(nsr & 0x01) /* NSR.D/SB=1 */
869 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 868 mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
870 } else { 869 } else {
871 if(dsr & 0x02) /* DSR.IDSTE=1 */ 870 if(dsr & 0x02) /* DSR.IDSTE=1 */
872 mode |= VIDEO_SOUND_STEREO; 871 mode |= V4L2_TUNER_MODE_STEREO;
873 if(dsr & 0x04) /* DSR.IDDUA=1 */ 872 if(dsr & 0x04) /* DSR.IDDUA=1 */
874 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 873 mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
875 } 874 }
876 875
877 v4l_dbg(1, debug, &chip->c, "tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n", 876 v4l_dbg(1, debug, chip->c, "tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n",
878 dsr, nsr, necr, mode); 877 dsr, nsr, necr, mode);
879 return mode; 878 return mode;
880} 879}
@@ -902,14 +901,14 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode)
902 int mdacosr = (tda9874a_mode) ? 0x82:0x80; 901 int mdacosr = (tda9874a_mode) ? 0x82:0x80;
903 902
904 switch(mode) { 903 switch(mode) {
905 case VIDEO_SOUND_MONO: 904 case V4L2_TUNER_MODE_MONO:
906 case VIDEO_SOUND_STEREO: 905 case V4L2_TUNER_MODE_STEREO:
907 break; 906 break;
908 case VIDEO_SOUND_LANG1: 907 case V4L2_TUNER_MODE_LANG1:
909 aosr = 0x80; /* auto-select, dual A/A */ 908 aosr = 0x80; /* auto-select, dual A/A */
910 mdacosr = (tda9874a_mode) ? 0x82:0x80; 909 mdacosr = (tda9874a_mode) ? 0x82:0x80;
911 break; 910 break;
912 case VIDEO_SOUND_LANG2: 911 case V4L2_TUNER_MODE_LANG2:
913 aosr = 0xa0; /* auto-select, dual B/B */ 912 aosr = 0xa0; /* auto-select, dual B/B */
914 mdacosr = (tda9874a_mode) ? 0x83:0x81; 913 mdacosr = (tda9874a_mode) ? 0x83:0x81;
915 break; 914 break;
@@ -920,18 +919,18 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode)
920 chip_write(chip, TDA9874A_AOSR, aosr); 919 chip_write(chip, TDA9874A_AOSR, aosr);
921 chip_write(chip, TDA9874A_MDACOSR, mdacosr); 920 chip_write(chip, TDA9874A_MDACOSR, mdacosr);
922 921
923 v4l_dbg(1, debug, &chip->c, "tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n", 922 v4l_dbg(1, debug, chip->c, "tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n",
924 mode, aosr, mdacosr); 923 mode, aosr, mdacosr);
925 924
926 } else { /* dic == 0x07 */ 925 } else { /* dic == 0x07 */
927 int fmmr,aosr; 926 int fmmr,aosr;
928 927
929 switch(mode) { 928 switch(mode) {
930 case VIDEO_SOUND_MONO: 929 case V4L2_TUNER_MODE_MONO:
931 fmmr = 0x00; /* mono */ 930 fmmr = 0x00; /* mono */
932 aosr = 0x10; /* A/A */ 931 aosr = 0x10; /* A/A */
933 break; 932 break;
934 case VIDEO_SOUND_STEREO: 933 case V4L2_TUNER_MODE_STEREO:
935 if(tda9874a_mode) { 934 if(tda9874a_mode) {
936 fmmr = 0x00; 935 fmmr = 0x00;
937 aosr = 0x00; /* handled by NICAM auto-mute */ 936 aosr = 0x00; /* handled by NICAM auto-mute */
@@ -940,11 +939,11 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode)
940 aosr = 0x00; 939 aosr = 0x00;
941 } 940 }
942 break; 941 break;
943 case VIDEO_SOUND_LANG1: 942 case V4L2_TUNER_MODE_LANG1:
944 fmmr = 0x02; /* dual */ 943 fmmr = 0x02; /* dual */
945 aosr = 0x10; /* dual A/A */ 944 aosr = 0x10; /* dual A/A */
946 break; 945 break;
947 case VIDEO_SOUND_LANG2: 946 case V4L2_TUNER_MODE_LANG2:
948 fmmr = 0x02; /* dual */ 947 fmmr = 0x02; /* dual */
949 aosr = 0x20; /* dual B/B */ 948 aosr = 0x20; /* dual B/B */
950 break; 949 break;
@@ -955,7 +954,7 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode)
955 chip_write(chip, TDA9874A_FMMR, fmmr); 954 chip_write(chip, TDA9874A_FMMR, fmmr);
956 chip_write(chip, TDA9874A_AOSR, aosr); 955 chip_write(chip, TDA9874A_AOSR, aosr);
957 956
958 v4l_dbg(1, debug, &chip->c, "tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n", 957 v4l_dbg(1, debug, chip->c, "tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n",
959 mode, fmmr, aosr); 958 mode, fmmr, aosr);
960 } 959 }
961} 960}
@@ -969,10 +968,10 @@ static int tda9874a_checkit(struct CHIPSTATE *chip)
969 if(-1 == (sic = chip_read2(chip,TDA9874A_SIC))) 968 if(-1 == (sic = chip_read2(chip,TDA9874A_SIC)))
970 return 0; 969 return 0;
971 970
972 v4l_dbg(1, debug, &chip->c, "tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic); 971 v4l_dbg(1, debug, chip->c, "tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic);
973 972
974 if((dic == 0x11)||(dic == 0x07)) { 973 if((dic == 0x11)||(dic == 0x07)) {
975 v4l_info(&chip->c, "found tda9874%s.\n", (dic == 0x11) ? "a":"h"); 974 v4l_info(chip->c, "found tda9874%s.\n", (dic == 0x11) ? "a":"h");
976 tda9874a_dic = dic; /* remember device id. */ 975 tda9874a_dic = dic; /* remember device id. */
977 return 1; 976 return 1;
978 } 977 }
@@ -1095,7 +1094,7 @@ static int tda8425_initialize(struct CHIPSTATE *chip)
1095 int inputmap[4] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1, 1094 int inputmap[4] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1,
1096 /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF}; 1095 /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF};
1097 1096
1098 if (chip->c.adapter->id == I2C_HW_B_RIVA) { 1097 if (chip->c->adapter->id == I2C_HW_B_RIVA) {
1099 memcpy (desc->inputmap, inputmap, sizeof (inputmap)); 1098 memcpy (desc->inputmap, inputmap, sizeof (inputmap));
1100 } 1099 }
1101 return 0; 1100 return 0;
@@ -1105,20 +1104,20 @@ static void tda8425_setmode(struct CHIPSTATE *chip, int mode)
1105{ 1104{
1106 int s1 = chip->shadow.bytes[TDA8425_S1+1] & 0xe1; 1105 int s1 = chip->shadow.bytes[TDA8425_S1+1] & 0xe1;
1107 1106
1108 if (mode & VIDEO_SOUND_LANG1) { 1107 if (mode & V4L2_TUNER_MODE_LANG1) {
1109 s1 |= TDA8425_S1_ML_SOUND_A; 1108 s1 |= TDA8425_S1_ML_SOUND_A;
1110 s1 |= TDA8425_S1_STEREO_PSEUDO; 1109 s1 |= TDA8425_S1_STEREO_PSEUDO;
1111 1110
1112 } else if (mode & VIDEO_SOUND_LANG2) { 1111 } else if (mode & V4L2_TUNER_MODE_LANG2) {
1113 s1 |= TDA8425_S1_ML_SOUND_B; 1112 s1 |= TDA8425_S1_ML_SOUND_B;
1114 s1 |= TDA8425_S1_STEREO_PSEUDO; 1113 s1 |= TDA8425_S1_STEREO_PSEUDO;
1115 1114
1116 } else { 1115 } else {
1117 s1 |= TDA8425_S1_ML_STEREO; 1116 s1 |= TDA8425_S1_ML_STEREO;
1118 1117
1119 if (mode & VIDEO_SOUND_MONO) 1118 if (mode & V4L2_TUNER_MODE_MONO)
1120 s1 |= TDA8425_S1_STEREO_MONO; 1119 s1 |= TDA8425_S1_STEREO_MONO;
1121 if (mode & VIDEO_SOUND_STEREO) 1120 if (mode & V4L2_TUNER_MODE_STEREO)
1122 s1 |= TDA8425_S1_STEREO_SPATIAL; 1121 s1 |= TDA8425_S1_STEREO_SPATIAL;
1123 } 1122 }
1124 chip_write(chip,TDA8425_S1,s1); 1123 chip_write(chip,TDA8425_S1,s1);
@@ -1177,13 +1176,13 @@ static int ta8874z_getmode(struct CHIPSTATE *chip)
1177 int val, mode; 1176 int val, mode;
1178 1177
1179 val = chip_read(chip); 1178 val = chip_read(chip);
1180 mode = VIDEO_SOUND_MONO; 1179 mode = V4L2_TUNER_MODE_MONO;
1181 if (val & TA8874Z_B1){ 1180 if (val & TA8874Z_B1){
1182 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 1181 mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
1183 }else if (!(val & TA8874Z_B0)){ 1182 }else if (!(val & TA8874Z_B0)){
1184 mode |= VIDEO_SOUND_STEREO; 1183 mode |= V4L2_TUNER_MODE_STEREO;
1185 } 1184 }
1186 /* v4l_dbg(1, debug, &chip->c, "ta8874z_getmode(): raw chip read: 0x%02x, return: 0x%02x\n", val, mode); */ 1185 /* v4l_dbg(1, debug, chip->c, "ta8874z_getmode(): raw chip read: 0x%02x, return: 0x%02x\n", val, mode); */
1187 return mode; 1186 return mode;
1188} 1187}
1189 1188
@@ -1196,19 +1195,19 @@ static void ta8874z_setmode(struct CHIPSTATE *chip, int mode)
1196{ 1195{
1197 int update = 1; 1196 int update = 1;
1198 audiocmd *t = NULL; 1197 audiocmd *t = NULL;
1199 v4l_dbg(1, debug, &chip->c, "ta8874z_setmode(): mode: 0x%02x\n", mode); 1198 v4l_dbg(1, debug, chip->c, "ta8874z_setmode(): mode: 0x%02x\n", mode);
1200 1199
1201 switch(mode){ 1200 switch(mode){
1202 case VIDEO_SOUND_MONO: 1201 case V4L2_TUNER_MODE_MONO:
1203 t = &ta8874z_mono; 1202 t = &ta8874z_mono;
1204 break; 1203 break;
1205 case VIDEO_SOUND_STEREO: 1204 case V4L2_TUNER_MODE_STEREO:
1206 t = &ta8874z_stereo; 1205 t = &ta8874z_stereo;
1207 break; 1206 break;
1208 case VIDEO_SOUND_LANG1: 1207 case V4L2_TUNER_MODE_LANG1:
1209 t = &ta8874z_main; 1208 t = &ta8874z_main;
1210 break; 1209 break;
1211 case VIDEO_SOUND_LANG2: 1210 case V4L2_TUNER_MODE_LANG2:
1212 t = &ta8874z_sub; 1211 t = &ta8874z_sub;
1213 break; 1212 break;
1214 default: 1213 default:
@@ -1462,51 +1461,55 @@ static struct CHIPDESC chiplist[] = {
1462/* ---------------------------------------------------------------------- */ 1461/* ---------------------------------------------------------------------- */
1463/* i2c registration */ 1462/* i2c registration */
1464 1463
1465static int chip_attach(struct i2c_adapter *adap, int addr, int kind) 1464static int chip_probe(struct i2c_client *client)
1466{ 1465{
1467 struct CHIPSTATE *chip; 1466 struct CHIPSTATE *chip;
1468 struct CHIPDESC *desc; 1467 struct CHIPDESC *desc;
1469 1468
1469 if (debug) {
1470 printk(KERN_INFO "tvaudio: TV audio decoder + audio/video mux driver\n");
1471 printk(KERN_INFO "tvaudio: known chips: ");
1472 for (desc = chiplist; desc->name != NULL; desc++)
1473 printk("%s%s", (desc == chiplist) ? "" : ", ", desc->name);
1474 printk("\n");
1475 }
1476
1470 chip = kzalloc(sizeof(*chip),GFP_KERNEL); 1477 chip = kzalloc(sizeof(*chip),GFP_KERNEL);
1471 if (!chip) 1478 if (!chip)
1472 return -ENOMEM; 1479 return -ENOMEM;
1473 memcpy(&chip->c,&client_template,sizeof(struct i2c_client)); 1480 chip->c = client;
1474 chip->c.adapter = adap; 1481 i2c_set_clientdata(client, chip);
1475 chip->c.addr = addr;
1476 i2c_set_clientdata(&chip->c, chip);
1477 1482
1478 /* find description for the chip */ 1483 /* find description for the chip */
1479 v4l_dbg(1, debug, &chip->c, "chip found @ 0x%x\n", addr<<1); 1484 v4l_dbg(1, debug, client, "chip found @ 0x%x\n", client->addr<<1);
1480 for (desc = chiplist; desc->name != NULL; desc++) { 1485 for (desc = chiplist; desc->name != NULL; desc++) {
1481 if (0 == *(desc->insmodopt)) 1486 if (0 == *(desc->insmodopt))
1482 continue; 1487 continue;
1483 if (addr < desc->addr_lo || 1488 if (client->addr < desc->addr_lo ||
1484 addr > desc->addr_hi) 1489 client->addr > desc->addr_hi)
1485 continue; 1490 continue;
1486 if (desc->checkit && !desc->checkit(chip)) 1491 if (desc->checkit && !desc->checkit(chip))
1487 continue; 1492 continue;
1488 break; 1493 break;
1489 } 1494 }
1490 if (desc->name == NULL) { 1495 if (desc->name == NULL) {
1491 v4l_dbg(1, debug, &chip->c, "no matching chip description found\n"); 1496 v4l_dbg(1, debug, client, "no matching chip description found\n");
1492 return -EIO; 1497 return -EIO;
1493 } 1498 }
1494 v4l_info(&chip->c, "%s found @ 0x%x (%s)\n", desc->name, addr<<1, adap->name); 1499 v4l_info(client, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name);
1495 if (desc->flags) { 1500 if (desc->flags) {
1496 v4l_dbg(1, debug, &chip->c, "matches:%s%s%s.\n", 1501 v4l_dbg(1, debug, client, "matches:%s%s%s.\n",
1497 (desc->flags & CHIP_HAS_VOLUME) ? " volume" : "", 1502 (desc->flags & CHIP_HAS_VOLUME) ? " volume" : "",
1498 (desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "", 1503 (desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "",
1499 (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : ""); 1504 (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : "");
1500 } 1505 }
1501 1506
1502 /* fill required data structures */ 1507 /* fill required data structures */
1503 strcpy(chip->c.name, desc->name); 1508 strcpy(client->name, desc->name);
1504 chip->type = desc-chiplist; 1509 chip->type = desc-chiplist;
1505 chip->shadow.count = desc->registers+1; 1510 chip->shadow.count = desc->registers+1;
1506 chip->prevmode = -1; 1511 chip->prevmode = -1;
1507 chip->audmode = V4L2_TUNER_MODE_LANG1; 1512 chip->audmode = V4L2_TUNER_MODE_LANG1;
1508 /* register */
1509 i2c_attach_client(&chip->c);
1510 1513
1511 /* initialization */ 1514 /* initialization */
1512 if (desc->initialize != NULL) 1515 if (desc->initialize != NULL)
@@ -1533,28 +1536,17 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind)
1533 init_timer(&chip->wt); 1536 init_timer(&chip->wt);
1534 chip->wt.function = chip_thread_wake; 1537 chip->wt.function = chip_thread_wake;
1535 chip->wt.data = (unsigned long)chip; 1538 chip->wt.data = (unsigned long)chip;
1536 chip->thread = kthread_run(chip_thread, chip, chip->c.name); 1539 chip->thread = kthread_run(chip_thread, chip, chip->c->name);
1537 if (IS_ERR(chip->thread)) { 1540 if (IS_ERR(chip->thread)) {
1538 v4l_warn(&chip->c, "%s: failed to create kthread\n", 1541 v4l_warn(chip->c, "%s: failed to create kthread\n",
1539 chip->c.name); 1542 chip->c->name);
1540 chip->thread = NULL; 1543 chip->thread = NULL;
1541 } 1544 }
1542 } 1545 }
1543 return 0; 1546 return 0;
1544} 1547}
1545 1548
1546static int chip_probe(struct i2c_adapter *adap) 1549static int chip_remove(struct i2c_client *client)
1547{
1548 /* don't attach on saa7146 based cards,
1549 because dedicated drivers are used */
1550 if ((adap->id == I2C_HW_SAA7146))
1551 return 0;
1552 if (adap->class & I2C_CLASS_TV_ANALOG)
1553 return i2c_probe(adap, &addr_data, chip_attach);
1554 return 0;
1555}
1556
1557static int chip_detach(struct i2c_client *client)
1558{ 1550{
1559 struct CHIPSTATE *chip = i2c_get_clientdata(client); 1551 struct CHIPSTATE *chip = i2c_get_clientdata(client);
1560 1552
@@ -1565,12 +1557,52 @@ static int chip_detach(struct i2c_client *client)
1565 chip->thread = NULL; 1557 chip->thread = NULL;
1566 } 1558 }
1567 1559
1568 i2c_detach_client(&chip->c);
1569 kfree(chip); 1560 kfree(chip);
1570 return 0; 1561 return 0;
1571} 1562}
1572 1563
1573static int tvaudio_set_ctrl(struct CHIPSTATE *chip, struct v4l2_control *ctrl) 1564static int tvaudio_get_ctrl(struct CHIPSTATE *chip,
1565 struct v4l2_control *ctrl)
1566{
1567 struct CHIPDESC *desc = chiplist + chip->type;
1568
1569 switch (ctrl->id) {
1570 case V4L2_CID_AUDIO_MUTE:
1571 ctrl->value=chip->muted;
1572 return 0;
1573 case V4L2_CID_AUDIO_VOLUME:
1574 if (!desc->flags & CHIP_HAS_VOLUME)
1575 break;
1576 ctrl->value = max(chip->left,chip->right);
1577 return 0;
1578 case V4L2_CID_AUDIO_BALANCE:
1579 {
1580 int volume;
1581 if (!desc->flags & CHIP_HAS_VOLUME)
1582 break;
1583 volume = max(chip->left,chip->right);
1584 if (volume)
1585 ctrl->value=(32768*min(chip->left,chip->right))/volume;
1586 else
1587 ctrl->value=32768;
1588 return 0;
1589 }
1590 case V4L2_CID_AUDIO_BASS:
1591 if (desc->flags & CHIP_HAS_BASSTREBLE)
1592 break;
1593 ctrl->value = chip->bass;
1594 return 0;
1595 case V4L2_CID_AUDIO_TREBLE:
1596 if (desc->flags & CHIP_HAS_BASSTREBLE)
1597 return -EINVAL;
1598 ctrl->value = chip->treble;
1599 return 0;
1600 }
1601 return -EINVAL;
1602}
1603
1604static int tvaudio_set_ctrl(struct CHIPSTATE *chip,
1605 struct v4l2_control *ctrl)
1574{ 1606{
1575 struct CHIPDESC *desc = chiplist + chip->type; 1607 struct CHIPDESC *desc = chiplist + chip->type;
1576 1608
@@ -1584,11 +1616,60 @@ static int tvaudio_set_ctrl(struct CHIPSTATE *chip, struct v4l2_control *ctrl)
1584 else 1616 else
1585 chip_write_masked(chip,desc->inputreg, 1617 chip_write_masked(chip,desc->inputreg,
1586 desc->inputmap[chip->input],desc->inputmask); 1618 desc->inputmap[chip->input],desc->inputmask);
1587 break; 1619 return 0;
1588 default: 1620 case V4L2_CID_AUDIO_VOLUME:
1589 return -EINVAL; 1621 {
1622 int volume,balance;
1623
1624 if (!desc->flags & CHIP_HAS_VOLUME)
1625 break;
1626
1627 volume = max(chip->left,chip->right);
1628 if (volume)
1629 balance=(32768*min(chip->left,chip->right))/volume;
1630 else
1631 balance=32768;
1632
1633 volume=ctrl->value;
1634 chip->left = (min(65536 - balance,32768) * volume) / 32768;
1635 chip->right = (min(balance,volume *(__u16)32768)) / 32768;
1636
1637 chip_write(chip,desc->leftreg,desc->volfunc(chip->left));
1638 chip_write(chip,desc->rightreg,desc->volfunc(chip->right));
1639
1640 return 0;
1590 } 1641 }
1591 return 0; 1642 case V4L2_CID_AUDIO_BALANCE:
1643 {
1644 int volume, balance;
1645 if (!desc->flags & CHIP_HAS_VOLUME)
1646 break;
1647
1648 volume = max(chip->left,chip->right);
1649 balance = ctrl->value;
1650
1651 chip_write(chip,desc->leftreg,desc->volfunc(chip->left));
1652 chip_write(chip,desc->rightreg,desc->volfunc(chip->right));
1653
1654 return 0;
1655 }
1656 case V4L2_CID_AUDIO_BASS:
1657 if (desc->flags & CHIP_HAS_BASSTREBLE)
1658 break;
1659 chip->bass = ctrl->value;
1660 chip_write(chip,desc->bassreg,desc->bassfunc(chip->bass));
1661
1662 return 0;
1663 case V4L2_CID_AUDIO_TREBLE:
1664 if (desc->flags & CHIP_HAS_BASSTREBLE)
1665 return -EINVAL;
1666
1667 chip->treble = ctrl->value;
1668 chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble));
1669
1670 return 0;
1671 }
1672 return -EINVAL;
1592} 1673}
1593 1674
1594 1675
@@ -1601,7 +1682,7 @@ static int chip_command(struct i2c_client *client,
1601 struct CHIPSTATE *chip = i2c_get_clientdata(client); 1682 struct CHIPSTATE *chip = i2c_get_clientdata(client);
1602 struct CHIPDESC *desc = chiplist + chip->type; 1683 struct CHIPDESC *desc = chiplist + chip->type;
1603 1684
1604 v4l_dbg(1, debug, &chip->c, "%s: chip_command 0x%x\n", chip->c.name, cmd); 1685 v4l_dbg(1, debug, chip->c, "%s: chip_command 0x%x\n", chip->c->name, cmd);
1605 1686
1606 switch (cmd) { 1687 switch (cmd) {
1607 case AUDC_SET_RADIO: 1688 case AUDC_SET_RADIO:
@@ -1609,67 +1690,36 @@ static int chip_command(struct i2c_client *client,
1609 chip->watch_stereo = 0; 1690 chip->watch_stereo = 0;
1610 /* del_timer(&chip->wt); */ 1691 /* del_timer(&chip->wt); */
1611 break; 1692 break;
1612
1613 /* --- v4l ioctls --- */ 1693 /* --- v4l ioctls --- */
1614 /* take care: bttv does userspace copying, we'll get a 1694 /* take care: bttv does userspace copying, we'll get a
1615 kernel pointer here... */ 1695 kernel pointer here... */
1616 case VIDIOCGAUDIO: 1696 case VIDIOC_QUERYCTRL:
1617 {
1618 struct video_audio *va = arg;
1619
1620 if (desc->flags & CHIP_HAS_VOLUME) {
1621 va->flags |= VIDEO_AUDIO_VOLUME;
1622 va->volume = max(chip->left,chip->right);
1623 if (va->volume)
1624 va->balance = (32768*min(chip->left,chip->right))/
1625 va->volume;
1626 else
1627 va->balance = 32768;
1628 }
1629 if (desc->flags & CHIP_HAS_BASSTREBLE) {
1630 va->flags |= VIDEO_AUDIO_BASS | VIDEO_AUDIO_TREBLE;
1631 va->bass = chip->bass;
1632 va->treble = chip->treble;
1633 }
1634 if (!chip->radio) {
1635 if (desc->getmode)
1636 va->mode = desc->getmode(chip);
1637 else
1638 va->mode = VIDEO_SOUND_MONO;
1639 }
1640 break;
1641 }
1642
1643 case VIDIOCSAUDIO:
1644 { 1697 {
1645 struct video_audio *va = arg; 1698 struct v4l2_queryctrl *qc = arg;
1646 1699
1647 if (desc->flags & CHIP_HAS_VOLUME) { 1700 switch (qc->id) {
1648 chip->left = (min(65536 - va->balance,32768) * 1701 case V4L2_CID_AUDIO_MUTE:
1649 va->volume) / 32768; 1702 break;
1650 chip->right = (min(va->balance,(__u16)32768) * 1703 case V4L2_CID_AUDIO_VOLUME:
1651 va->volume) / 32768; 1704 case V4L2_CID_AUDIO_BALANCE:
1652 chip_write(chip,desc->leftreg,desc->volfunc(chip->left)); 1705 if (!desc->flags & CHIP_HAS_VOLUME)
1653 chip_write(chip,desc->rightreg,desc->volfunc(chip->right)); 1706 return -EINVAL;
1654 } 1707 break;
1655 if (desc->flags & CHIP_HAS_BASSTREBLE) { 1708 case V4L2_CID_AUDIO_BASS:
1656 chip->bass = va->bass; 1709 case V4L2_CID_AUDIO_TREBLE:
1657 chip->treble = va->treble; 1710 if (desc->flags & CHIP_HAS_BASSTREBLE)
1658 chip_write(chip,desc->bassreg,desc->bassfunc(chip->bass)); 1711 return -EINVAL;
1659 chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble)); 1712 break;
1660 } 1713 default:
1661 if (desc->setmode && va->mode) { 1714 return -EINVAL;
1662 chip->watch_stereo = 0;
1663 /* del_timer(&chip->wt); */
1664 chip->mode = va->mode;
1665 desc->setmode(chip,va->mode);
1666 } 1715 }
1667 break; 1716 return v4l2_ctrl_query_fill_std(qc);
1668 } 1717 }
1669
1670 case VIDIOC_S_CTRL: 1718 case VIDIOC_S_CTRL:
1671 return tvaudio_set_ctrl(chip, arg); 1719 return tvaudio_set_ctrl(chip, arg);
1672 1720
1721 case VIDIOC_G_CTRL:
1722 return tvaudio_get_ctrl(chip, arg);
1673 case VIDIOC_INT_G_AUDIO_ROUTING: 1723 case VIDIOC_INT_G_AUDIO_ROUTING:
1674 { 1724 {
1675 struct v4l2_routing *rt = arg; 1725 struct v4l2_routing *rt = arg;
@@ -1678,7 +1728,6 @@ static int chip_command(struct i2c_client *client,
1678 rt->output = 0; 1728 rt->output = 0;
1679 break; 1729 break;
1680 } 1730 }
1681
1682 case VIDIOC_INT_S_AUDIO_ROUTING: 1731 case VIDIOC_INT_S_AUDIO_ROUTING:
1683 { 1732 {
1684 struct v4l2_routing *rt = arg; 1733 struct v4l2_routing *rt = arg;
@@ -1693,7 +1742,6 @@ static int chip_command(struct i2c_client *client,
1693 desc->inputmap[chip->input], desc->inputmask); 1742 desc->inputmap[chip->input], desc->inputmask);
1694 break; 1743 break;
1695 } 1744 }
1696
1697 case VIDIOC_S_TUNER: 1745 case VIDIOC_S_TUNER:
1698 { 1746 {
1699 struct v4l2_tuner *vt = arg; 1747 struct v4l2_tuner *vt = arg;
@@ -1703,17 +1751,13 @@ static int chip_command(struct i2c_client *client,
1703 break; 1751 break;
1704 switch (vt->audmode) { 1752 switch (vt->audmode) {
1705 case V4L2_TUNER_MODE_MONO: 1753 case V4L2_TUNER_MODE_MONO:
1706 mode = VIDEO_SOUND_MONO;
1707 break;
1708 case V4L2_TUNER_MODE_STEREO: 1754 case V4L2_TUNER_MODE_STEREO:
1709 case V4L2_TUNER_MODE_LANG1_LANG2:
1710 mode = VIDEO_SOUND_STEREO;
1711 break;
1712 case V4L2_TUNER_MODE_LANG1: 1755 case V4L2_TUNER_MODE_LANG1:
1713 mode = VIDEO_SOUND_LANG1;
1714 break;
1715 case V4L2_TUNER_MODE_LANG2: 1756 case V4L2_TUNER_MODE_LANG2:
1716 mode = VIDEO_SOUND_LANG2; 1757 mode = vt->audmode;
1758 break;
1759 case V4L2_TUNER_MODE_LANG1_LANG2:
1760 mode = V4L2_TUNER_MODE_STEREO;
1717 break; 1761 break;
1718 default: 1762 default:
1719 return -EINVAL; 1763 return -EINVAL;
@@ -1728,11 +1772,10 @@ static int chip_command(struct i2c_client *client,
1728 } 1772 }
1729 break; 1773 break;
1730 } 1774 }
1731
1732 case VIDIOC_G_TUNER: 1775 case VIDIOC_G_TUNER:
1733 { 1776 {
1734 struct v4l2_tuner *vt = arg; 1777 struct v4l2_tuner *vt = arg;
1735 int mode = VIDEO_SOUND_MONO; 1778 int mode = V4L2_TUNER_MODE_MONO;
1736 1779
1737 if (chip->radio) 1780 if (chip->radio)
1738 break; 1781 break;
@@ -1744,30 +1787,26 @@ static int chip_command(struct i2c_client *client,
1744 if (desc->getmode) 1787 if (desc->getmode)
1745 mode = desc->getmode(chip); 1788 mode = desc->getmode(chip);
1746 1789
1747 if (mode & VIDEO_SOUND_MONO) 1790 if (mode & V4L2_TUNER_MODE_MONO)
1748 vt->rxsubchans |= V4L2_TUNER_SUB_MONO; 1791 vt->rxsubchans |= V4L2_TUNER_SUB_MONO;
1749 if (mode & VIDEO_SOUND_STEREO) 1792 if (mode & V4L2_TUNER_MODE_STEREO)
1750 vt->rxsubchans |= V4L2_TUNER_SUB_STEREO; 1793 vt->rxsubchans |= V4L2_TUNER_SUB_STEREO;
1751 /* Note: for SAP it should be mono/lang2 or stereo/lang2. 1794 /* Note: for SAP it should be mono/lang2 or stereo/lang2.
1752 When this module is converted fully to v4l2, then this 1795 When this module is converted fully to v4l2, then this
1753 should change for those chips that can detect SAP. */ 1796 should change for those chips that can detect SAP. */
1754 if (mode & VIDEO_SOUND_LANG1) 1797 if (mode & V4L2_TUNER_MODE_LANG1)
1755 vt->rxsubchans = V4L2_TUNER_SUB_LANG1 | 1798 vt->rxsubchans = V4L2_TUNER_SUB_LANG1 |
1756 V4L2_TUNER_SUB_LANG2; 1799 V4L2_TUNER_SUB_LANG2;
1757 break; 1800 break;
1758 } 1801 }
1759
1760 case VIDIOCSCHAN:
1761 case VIDIOC_S_STD: 1802 case VIDIOC_S_STD:
1762 chip->radio = 0; 1803 chip->radio = 0;
1763 break; 1804 break;
1764
1765 case VIDIOCSFREQ:
1766 case VIDIOC_S_FREQUENCY: 1805 case VIDIOC_S_FREQUENCY:
1767 chip->mode = 0; /* automatic */ 1806 chip->mode = 0; /* automatic */
1768 if (desc->checkmode) { 1807 if (desc->checkmode) {
1769 desc->setmode(chip,VIDEO_SOUND_MONO); 1808 desc->setmode(chip,V4L2_TUNER_MODE_MONO);
1770 if (chip->prevmode != VIDEO_SOUND_MONO) 1809 if (chip->prevmode != V4L2_TUNER_MODE_MONO)
1771 chip->prevmode = -1; /* reset previous mode */ 1810 chip->prevmode = -1; /* reset previous mode */
1772 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); 1811 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000));
1773 /* the thread will call checkmode() later */ 1812 /* the thread will call checkmode() later */
@@ -1780,44 +1819,25 @@ static int chip_command(struct i2c_client *client,
1780 return 0; 1819 return 0;
1781} 1820}
1782 1821
1783static struct i2c_driver driver = { 1822static int chip_legacy_probe(struct i2c_adapter *adap)
1784 .driver = {
1785 .name = "tvaudio",
1786 },
1787 .id = I2C_DRIVERID_TVAUDIO,
1788 .attach_adapter = chip_probe,
1789 .detach_client = chip_detach,
1790 .command = chip_command,
1791};
1792
1793static struct i2c_client client_template =
1794{ 1823{
1795 .name = "(unset)", 1824 /* don't attach on saa7146 based cards,
1796 .driver = &driver, 1825 because dedicated drivers are used */
1797}; 1826 if ((adap->id == I2C_HW_SAA7146))
1798 1827 return 0;
1799static int __init audiochip_init_module(void) 1828 if (adap->class & I2C_CLASS_TV_ANALOG)
1800{ 1829 return 1;
1801 struct CHIPDESC *desc; 1830 return 0;
1802
1803 if (debug) {
1804 printk(KERN_INFO "tvaudio: TV audio decoder + audio/video mux driver\n");
1805 printk(KERN_INFO "tvaudio: known chips: ");
1806 for (desc = chiplist; desc->name != NULL; desc++)
1807 printk("%s%s", (desc == chiplist) ? "" : ", ", desc->name);
1808 printk("\n");
1809 }
1810
1811 return i2c_add_driver(&driver);
1812}
1813
1814static void __exit audiochip_cleanup_module(void)
1815{
1816 i2c_del_driver(&driver);
1817} 1831}
1818 1832
1819module_init(audiochip_init_module); 1833static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1820module_exit(audiochip_cleanup_module); 1834 .name = "tvaudio",
1835 .driverid = I2C_DRIVERID_TVAUDIO,
1836 .command = chip_command,
1837 .probe = chip_probe,
1838 .remove = chip_remove,
1839 .legacy_probe = chip_legacy_probe,
1840};
1821 1841
1822/* 1842/*
1823 * Local variables: 1843 * Local variables:
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 4b2c4034f5b3..0b8fbad3c721 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -46,11 +46,12 @@ MODULE_DESCRIPTION("i2c Hauppauge eeprom decoder driver");
46MODULE_AUTHOR("John Klar"); 46MODULE_AUTHOR("John Klar");
47MODULE_LICENSE("GPL"); 47MODULE_LICENSE("GPL");
48 48
49static int debug = 0; 49static int debug;
50module_param(debug, int, 0644); 50module_param(debug, int, 0644);
51MODULE_PARM_DESC(debug, "Debug level (0-1)"); 51MODULE_PARM_DESC(debug, "Debug level (0-1)");
52 52
53#define STRM(array,i) (i < sizeof(array)/sizeof(char*) ? array[i] : "unknown") 53#define STRM(array, i) \
54 (i < sizeof(array) / sizeof(char *) ? array[i] : "unknown")
54 55
55#define tveeprom_info(fmt, arg...) \ 56#define tveeprom_info(fmt, arg...) \
56 v4l_printk(KERN_INFO, "tveeprom", c->adapter, c->addr, fmt , ## arg) 57 v4l_printk(KERN_INFO, "tveeprom", c->adapter, c->addr, fmt , ## arg)
@@ -58,7 +59,8 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
58 v4l_printk(KERN_WARNING, "tveeprom", c->adapter, c->addr, fmt , ## arg) 59 v4l_printk(KERN_WARNING, "tveeprom", c->adapter, c->addr, fmt , ## arg)
59#define tveeprom_dbg(fmt, arg...) do { \ 60#define tveeprom_dbg(fmt, arg...) do { \
60 if (debug) \ 61 if (debug) \
61 v4l_printk(KERN_DEBUG, "tveeprom", c->adapter, c->addr, fmt , ## arg); \ 62 v4l_printk(KERN_DEBUG, "tveeprom", \
63 c->adapter, c->addr, fmt , ## arg); \
62 } while (0) 64 } while (0)
63 65
64/* 66/*
@@ -94,170 +96,172 @@ static struct HAUPPAUGE_TUNER
94hauppauge_tuner[] = 96hauppauge_tuner[] =
95{ 97{
96 /* 0-9 */ 98 /* 0-9 */
97 { TUNER_ABSENT, "None" }, 99 { TUNER_ABSENT, "None" },
98 { TUNER_ABSENT, "External" }, 100 { TUNER_ABSENT, "External" },
99 { TUNER_ABSENT, "Unspecified" }, 101 { TUNER_ABSENT, "Unspecified" },
100 { TUNER_PHILIPS_PAL, "Philips FI1216" }, 102 { TUNER_PHILIPS_PAL, "Philips FI1216" },
101 { TUNER_PHILIPS_SECAM, "Philips FI1216MF" }, 103 { TUNER_PHILIPS_SECAM, "Philips FI1216MF" },
102 { TUNER_PHILIPS_NTSC, "Philips FI1236" }, 104 { TUNER_PHILIPS_NTSC, "Philips FI1236" },
103 { TUNER_PHILIPS_PAL_I, "Philips FI1246" }, 105 { TUNER_PHILIPS_PAL_I, "Philips FI1246" },
104 { TUNER_PHILIPS_PAL_DK,"Philips FI1256" }, 106 { TUNER_PHILIPS_PAL_DK, "Philips FI1256" },
105 { TUNER_PHILIPS_PAL, "Philips FI1216 MK2" }, 107 { TUNER_PHILIPS_PAL, "Philips FI1216 MK2" },
106 { TUNER_PHILIPS_SECAM, "Philips FI1216MF MK2" }, 108 { TUNER_PHILIPS_SECAM, "Philips FI1216MF MK2" },
107 /* 10-19 */ 109 /* 10-19 */
108 { TUNER_PHILIPS_NTSC, "Philips FI1236 MK2" }, 110 { TUNER_PHILIPS_NTSC, "Philips FI1236 MK2" },
109 { TUNER_PHILIPS_PAL_I, "Philips FI1246 MK2" }, 111 { TUNER_PHILIPS_PAL_I, "Philips FI1246 MK2" },
110 { TUNER_PHILIPS_PAL_DK,"Philips FI1256 MK2" }, 112 { TUNER_PHILIPS_PAL_DK, "Philips FI1256 MK2" },
111 { TUNER_TEMIC_NTSC, "Temic 4032FY5" }, 113 { TUNER_TEMIC_NTSC, "Temic 4032FY5" },
112 { TUNER_TEMIC_PAL, "Temic 4002FH5" }, 114 { TUNER_TEMIC_PAL, "Temic 4002FH5" },
113 { TUNER_TEMIC_PAL_I, "Temic 4062FY5" }, 115 { TUNER_TEMIC_PAL_I, "Temic 4062FY5" },
114 { TUNER_PHILIPS_PAL, "Philips FR1216 MK2" }, 116 { TUNER_PHILIPS_PAL, "Philips FR1216 MK2" },
115 { TUNER_PHILIPS_SECAM, "Philips FR1216MF MK2" }, 117 { TUNER_PHILIPS_SECAM, "Philips FR1216MF MK2" },
116 { TUNER_PHILIPS_NTSC, "Philips FR1236 MK2" }, 118 { TUNER_PHILIPS_NTSC, "Philips FR1236 MK2" },
117 { TUNER_PHILIPS_PAL_I, "Philips FR1246 MK2" }, 119 { TUNER_PHILIPS_PAL_I, "Philips FR1246 MK2" },
118 /* 20-29 */ 120 /* 20-29 */
119 { TUNER_PHILIPS_PAL_DK,"Philips FR1256 MK2" }, 121 { TUNER_PHILIPS_PAL_DK, "Philips FR1256 MK2" },
120 { TUNER_PHILIPS_PAL, "Philips FM1216" }, 122 { TUNER_PHILIPS_PAL, "Philips FM1216" },
121 { TUNER_PHILIPS_SECAM, "Philips FM1216MF" }, 123 { TUNER_PHILIPS_SECAM, "Philips FM1216MF" },
122 { TUNER_PHILIPS_NTSC, "Philips FM1236" }, 124 { TUNER_PHILIPS_NTSC, "Philips FM1236" },
123 { TUNER_PHILIPS_PAL_I, "Philips FM1246" }, 125 { TUNER_PHILIPS_PAL_I, "Philips FM1246" },
124 { TUNER_PHILIPS_PAL_DK,"Philips FM1256" }, 126 { TUNER_PHILIPS_PAL_DK, "Philips FM1256" },
125 { TUNER_TEMIC_4036FY5_NTSC, "Temic 4036FY5" }, 127 { TUNER_TEMIC_4036FY5_NTSC, "Temic 4036FY5" },
126 { TUNER_ABSENT, "Samsung TCPN9082D" }, 128 { TUNER_ABSENT, "Samsung TCPN9082D" },
127 { TUNER_ABSENT, "Samsung TCPM9092P" }, 129 { TUNER_ABSENT, "Samsung TCPM9092P" },
128 { TUNER_TEMIC_4006FH5_PAL, "Temic 4006FH5" }, 130 { TUNER_TEMIC_4006FH5_PAL, "Temic 4006FH5" },
129 /* 30-39 */ 131 /* 30-39 */
130 { TUNER_ABSENT, "Samsung TCPN9085D" }, 132 { TUNER_ABSENT, "Samsung TCPN9085D" },
131 { TUNER_ABSENT, "Samsung TCPB9085P" }, 133 { TUNER_ABSENT, "Samsung TCPB9085P" },
132 { TUNER_ABSENT, "Samsung TCPL9091P" }, 134 { TUNER_ABSENT, "Samsung TCPL9091P" },
133 { TUNER_TEMIC_4039FR5_NTSC, "Temic 4039FR5" }, 135 { TUNER_TEMIC_4039FR5_NTSC, "Temic 4039FR5" },
134 { TUNER_PHILIPS_FQ1216ME, "Philips FQ1216 ME" }, 136 { TUNER_PHILIPS_FQ1216ME, "Philips FQ1216 ME" },
135 { TUNER_TEMIC_4066FY5_PAL_I, "Temic 4066FY5" }, 137 { TUNER_TEMIC_4066FY5_PAL_I, "Temic 4066FY5" },
136 { TUNER_PHILIPS_NTSC, "Philips TD1536" }, 138 { TUNER_PHILIPS_NTSC, "Philips TD1536" },
137 { TUNER_PHILIPS_NTSC, "Philips TD1536D" }, 139 { TUNER_PHILIPS_NTSC, "Philips TD1536D" },
138 { TUNER_PHILIPS_NTSC, "Philips FMR1236" }, /* mono radio */ 140 { TUNER_PHILIPS_NTSC, "Philips FMR1236" }, /* mono radio */
139 { TUNER_ABSENT, "Philips FI1256MP" }, 141 { TUNER_ABSENT, "Philips FI1256MP" },
140 /* 40-49 */ 142 /* 40-49 */
141 { TUNER_ABSENT, "Samsung TCPQ9091P" }, 143 { TUNER_ABSENT, "Samsung TCPQ9091P" },
142 { TUNER_TEMIC_4006FN5_MULTI_PAL, "Temic 4006FN5" }, 144 { TUNER_TEMIC_4006FN5_MULTI_PAL, "Temic 4006FN5" },
143 { TUNER_TEMIC_4009FR5_PAL, "Temic 4009FR5" }, 145 { TUNER_TEMIC_4009FR5_PAL, "Temic 4009FR5" },
144 { TUNER_TEMIC_4046FM5, "Temic 4046FM5" }, 146 { TUNER_TEMIC_4046FM5, "Temic 4046FM5" },
145 { TUNER_TEMIC_4009FN5_MULTI_PAL_FM, "Temic 4009FN5" }, 147 { TUNER_TEMIC_4009FN5_MULTI_PAL_FM, "Temic 4009FN5" },
146 { TUNER_ABSENT, "Philips TD1536D FH 44"}, 148 { TUNER_ABSENT, "Philips TD1536D FH 44"},
147 { TUNER_LG_NTSC_FM, "LG TP18NSR01F"}, 149 { TUNER_LG_NTSC_FM, "LG TP18NSR01F"},
148 { TUNER_LG_PAL_FM, "LG TP18PSB01D"}, 150 { TUNER_LG_PAL_FM, "LG TP18PSB01D"},
149 { TUNER_LG_PAL, "LG TP18PSB11D"}, 151 { TUNER_LG_PAL, "LG TP18PSB11D"},
150 { TUNER_LG_PAL_I_FM, "LG TAPC-I001D"}, 152 { TUNER_LG_PAL_I_FM, "LG TAPC-I001D"},
151 /* 50-59 */ 153 /* 50-59 */
152 { TUNER_LG_PAL_I, "LG TAPC-I701D"}, 154 { TUNER_LG_PAL_I, "LG TAPC-I701D"},
153 { TUNER_ABSENT, "Temic 4042FI5"}, 155 { TUNER_ABSENT, "Temic 4042FI5"},
154 { TUNER_MICROTUNE_4049FM5, "Microtune 4049 FM5"}, 156 { TUNER_MICROTUNE_4049FM5, "Microtune 4049 FM5"},
155 { TUNER_ABSENT, "LG TPI8NSR11F"}, 157 { TUNER_ABSENT, "LG TPI8NSR11F"},
156 { TUNER_ABSENT, "Microtune 4049 FM5 Alt I2C"}, 158 { TUNER_ABSENT, "Microtune 4049 FM5 Alt I2C"},
157 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FQ1216ME MK3"}, 159 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FQ1216ME MK3"},
158 { TUNER_ABSENT, "Philips FI1236 MK3"}, 160 { TUNER_ABSENT, "Philips FI1236 MK3"},
159 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216 ME MK3"}, 161 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216 ME MK3"},
160 { TUNER_PHILIPS_FM1236_MK3, "Philips FM1236 MK3"}, 162 { TUNER_PHILIPS_FM1236_MK3, "Philips FM1236 MK3"},
161 { TUNER_ABSENT, "Philips FM1216MP MK3"}, 163 { TUNER_ABSENT, "Philips FM1216MP MK3"},
162 /* 60-69 */ 164 /* 60-69 */
163 { TUNER_PHILIPS_FM1216ME_MK3, "LG S001D MK3"}, 165 { TUNER_PHILIPS_FM1216ME_MK3, "LG S001D MK3"},
164 { TUNER_ABSENT, "LG M001D MK3"}, 166 { TUNER_ABSENT, "LG M001D MK3"},
165 { TUNER_PHILIPS_FM1216ME_MK3, "LG S701D MK3"}, 167 { TUNER_PHILIPS_FM1216ME_MK3, "LG S701D MK3"},
166 { TUNER_ABSENT, "LG M701D MK3"}, 168 { TUNER_ABSENT, "LG M701D MK3"},
167 { TUNER_ABSENT, "Temic 4146FM5"}, 169 { TUNER_ABSENT, "Temic 4146FM5"},
168 { TUNER_ABSENT, "Temic 4136FY5"}, 170 { TUNER_ABSENT, "Temic 4136FY5"},
169 { TUNER_ABSENT, "Temic 4106FH5"}, 171 { TUNER_ABSENT, "Temic 4106FH5"},
170 { TUNER_ABSENT, "Philips FQ1216LMP MK3"}, 172 { TUNER_ABSENT, "Philips FQ1216LMP MK3"},
171 { TUNER_LG_NTSC_TAPE, "LG TAPE H001F MK3"}, 173 { TUNER_LG_NTSC_TAPE, "LG TAPE H001F MK3"},
172 { TUNER_LG_NTSC_TAPE, "LG TAPE H701F MK3"}, 174 { TUNER_LG_NTSC_TAPE, "LG TAPE H701F MK3"},
173 /* 70-79 */ 175 /* 70-79 */
174 { TUNER_ABSENT, "LG TALN H200T"}, 176 { TUNER_ABSENT, "LG TALN H200T"},
175 { TUNER_ABSENT, "LG TALN H250T"}, 177 { TUNER_ABSENT, "LG TALN H250T"},
176 { TUNER_ABSENT, "LG TALN M200T"}, 178 { TUNER_ABSENT, "LG TALN M200T"},
177 { TUNER_ABSENT, "LG TALN Z200T"}, 179 { TUNER_ABSENT, "LG TALN Z200T"},
178 { TUNER_ABSENT, "LG TALN S200T"}, 180 { TUNER_ABSENT, "LG TALN S200T"},
179 { TUNER_ABSENT, "Thompson DTT7595"}, 181 { TUNER_ABSENT, "Thompson DTT7595"},
180 { TUNER_ABSENT, "Thompson DTT7592"}, 182 { TUNER_ABSENT, "Thompson DTT7592"},
181 { TUNER_ABSENT, "Silicon TDA8275C1 8290"}, 183 { TUNER_ABSENT, "Silicon TDA8275C1 8290"},
182 { TUNER_ABSENT, "Silicon TDA8275C1 8290 FM"}, 184 { TUNER_ABSENT, "Silicon TDA8275C1 8290 FM"},
183 { TUNER_ABSENT, "Thompson DTT757"}, 185 { TUNER_ABSENT, "Thompson DTT757"},
184 /* 80-89 */ 186 /* 80-89 */
185 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FQ1216LME MK3"}, 187 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FQ1216LME MK3"},
186 { TUNER_LG_PAL_NEW_TAPC, "LG TAPC G701D"}, 188 { TUNER_LG_PAL_NEW_TAPC, "LG TAPC G701D"},
187 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"}, 189 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"},
188 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MB 3"}, 190 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MB 3"},
189 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MI 3"}, 191 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MI 3"},
190 { TUNER_TCL_2002N, "TCL 2002N 6A"}, 192 { TUNER_TCL_2002N, "TCL 2002N 6A"},
191 { TUNER_PHILIPS_FM1236_MK3, "Philips FQ1236 MK3"}, 193 { TUNER_PHILIPS_FM1236_MK3, "Philips FQ1236 MK3"},
192 { TUNER_SAMSUNG_TCPN_2121P30A, "Samsung TCPN 2121P30A"}, 194 { TUNER_SAMSUNG_TCPN_2121P30A, "Samsung TCPN 2121P30A"},
193 { TUNER_ABSENT, "Samsung TCPE 4121P30A"}, 195 { TUNER_ABSENT, "Samsung TCPE 4121P30A"},
194 { TUNER_PHILIPS_FM1216ME_MK3, "TCL MFPE05 2"}, 196 { TUNER_PHILIPS_FM1216ME_MK3, "TCL MFPE05 2"},
195 /* 90-99 */ 197 /* 90-99 */
196 { TUNER_ABSENT, "LG TALN H202T"}, 198 { TUNER_ABSENT, "LG TALN H202T"},
197 { TUNER_PHILIPS_FQ1216AME_MK4, "Philips FQ1216AME MK4"}, 199 { TUNER_PHILIPS_FQ1216AME_MK4, "Philips FQ1216AME MK4"},
198 { TUNER_PHILIPS_FQ1236A_MK4, "Philips FQ1236A MK4"}, 200 { TUNER_PHILIPS_FQ1236A_MK4, "Philips FQ1236A MK4"},
199 { TUNER_ABSENT, "Philips FQ1286A MK4"}, 201 { TUNER_ABSENT, "Philips FQ1286A MK4"},
200 { TUNER_ABSENT, "Philips FQ1216ME MK5"}, 202 { TUNER_ABSENT, "Philips FQ1216ME MK5"},
201 { TUNER_ABSENT, "Philips FQ1236 MK5"}, 203 { TUNER_ABSENT, "Philips FQ1236 MK5"},
202 { TUNER_SAMSUNG_TCPG_6121P30A, "Samsung TCPG 6121P30A"}, 204 { TUNER_SAMSUNG_TCPG_6121P30A, "Samsung TCPG 6121P30A"},
203 { TUNER_TCL_2002MB, "TCL 2002MB_3H"}, 205 { TUNER_TCL_2002MB, "TCL 2002MB_3H"},
204 { TUNER_ABSENT, "TCL 2002MI_3H"}, 206 { TUNER_ABSENT, "TCL 2002MI_3H"},
205 { TUNER_TCL_2002N, "TCL 2002N 5H"}, 207 { TUNER_TCL_2002N, "TCL 2002N 5H"},
206 /* 100-109 */ 208 /* 100-109 */
207 { TUNER_PHILIPS_FMD1216ME_MK3, "Philips FMD1216ME"}, 209 { TUNER_PHILIPS_FMD1216ME_MK3, "Philips FMD1216ME"},
208 { TUNER_TEA5767, "Philips TEA5768HL FM Radio"}, 210 { TUNER_TEA5767, "Philips TEA5768HL FM Radio"},
209 { TUNER_ABSENT, "Panasonic ENV57H12D5"}, 211 { TUNER_ABSENT, "Panasonic ENV57H12D5"},
210 { TUNER_PHILIPS_FM1236_MK3, "TCL MFNM05-4"}, 212 { TUNER_PHILIPS_FM1236_MK3, "TCL MFNM05-4"},
211 { TUNER_ABSENT, "TCL MNM05-4"}, 213 { TUNER_ABSENT, "TCL MNM05-4"},
212 { TUNER_PHILIPS_FM1216ME_MK3, "TCL MPE05-2"}, 214 { TUNER_PHILIPS_FM1216ME_MK3, "TCL MPE05-2"},
213 { TUNER_ABSENT, "TCL MQNM05-4"}, 215 { TUNER_ABSENT, "TCL MQNM05-4"},
214 { TUNER_ABSENT, "LG TAPC-W701D"}, 216 { TUNER_ABSENT, "LG TAPC-W701D"},
215 { TUNER_ABSENT, "TCL 9886P-WM"}, 217 { TUNER_ABSENT, "TCL 9886P-WM"},
216 { TUNER_ABSENT, "TCL 1676NM-WM"}, 218 { TUNER_ABSENT, "TCL 1676NM-WM"},
217 /* 110-119 */ 219 /* 110-119 */
218 { TUNER_ABSENT, "Thompson DTT75105"}, 220 { TUNER_ABSENT, "Thompson DTT75105"},
219 { TUNER_ABSENT, "Conexant_CX24109"}, 221 { TUNER_ABSENT, "Conexant_CX24109"},
220 { TUNER_TCL_2002N, "TCL M2523_5N_E"}, 222 { TUNER_TCL_2002N, "TCL M2523_5N_E"},
221 { TUNER_TCL_2002MB, "TCL M2523_3DB_E"}, 223 { TUNER_TCL_2002MB, "TCL M2523_3DB_E"},
222 { TUNER_ABSENT, "Philips 8275A"}, 224 { TUNER_ABSENT, "Philips 8275A"},
223 { TUNER_ABSENT, "Microtune MT2060"}, 225 { TUNER_ABSENT, "Microtune MT2060"},
224 { TUNER_PHILIPS_FM1236_MK3, "Philips FM1236 MK5"}, 226 { TUNER_PHILIPS_FM1236_MK3, "Philips FM1236 MK5"},
225 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216ME MK5"}, 227 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216ME MK5"},
226 { TUNER_ABSENT, "TCL M2523_3DI_E"}, 228 { TUNER_ABSENT, "TCL M2523_3DI_E"},
227 { TUNER_ABSENT, "Samsung THPD5222FG30A"}, 229 { TUNER_ABSENT, "Samsung THPD5222FG30A"},
228 /* 120-129 */ 230 /* 120-129 */
229 { TUNER_ABSENT, "Xceive XC3028"}, 231 { TUNER_XC2028, "Xceive XC3028"},
230 { TUNER_ABSENT, "Philips FQ1216LME MK5"}, 232 { TUNER_ABSENT, "Philips FQ1216LME MK5"},
231 { TUNER_ABSENT, "Philips FQD1216LME"}, 233 { TUNER_ABSENT, "Philips FQD1216LME"},
232 { TUNER_ABSENT, "Conexant CX24118A"}, 234 { TUNER_ABSENT, "Conexant CX24118A"},
233 { TUNER_ABSENT, "TCL DMF11WIP"}, 235 { TUNER_ABSENT, "TCL DMF11WIP"},
234 { TUNER_ABSENT, "TCL MFNM05_4H_E"}, 236 { TUNER_ABSENT, "TCL MFNM05_4H_E"},
235 { TUNER_ABSENT, "TCL MNM05_4H_E"}, 237 { TUNER_ABSENT, "TCL MNM05_4H_E"},
236 { TUNER_ABSENT, "TCL MPE05_2H_E"}, 238 { TUNER_ABSENT, "TCL MPE05_2H_E"},
237 { TUNER_ABSENT, "TCL MQNM05_4_U"}, 239 { TUNER_ABSENT, "TCL MQNM05_4_U"},
238 { TUNER_ABSENT, "TCL M2523_5NH_E"}, 240 { TUNER_ABSENT, "TCL M2523_5NH_E"},
239 /* 130-139 */ 241 /* 130-139 */
240 { TUNER_ABSENT, "TCL M2523_3DBH_E"}, 242 { TUNER_ABSENT, "TCL M2523_3DBH_E"},
241 { TUNER_ABSENT, "TCL M2523_3DIH_E"}, 243 { TUNER_ABSENT, "TCL M2523_3DIH_E"},
242 { TUNER_ABSENT, "TCL MFPE05_2_U"}, 244 { TUNER_ABSENT, "TCL MFPE05_2_U"},
243 { TUNER_ABSENT, "Philips FMD1216MEX"}, 245 { TUNER_ABSENT, "Philips FMD1216MEX"},
244 { TUNER_ABSENT, "Philips FRH2036B"}, 246 { TUNER_ABSENT, "Philips FRH2036B"},
245 { TUNER_ABSENT, "Panasonic ENGF75_01GF"}, 247 { TUNER_ABSENT, "Panasonic ENGF75_01GF"},
246 { TUNER_ABSENT, "MaxLinear MXL5005"}, 248 { TUNER_ABSENT, "MaxLinear MXL5005"},
247 { TUNER_ABSENT, "MaxLinear MXL5003"}, 249 { TUNER_ABSENT, "MaxLinear MXL5003"},
248 { TUNER_ABSENT, "Xceive XC2028"}, 250 { TUNER_ABSENT, "Xceive XC2028"},
249 { TUNER_ABSENT, "Microtune MT2131"}, 251 { TUNER_ABSENT, "Microtune MT2131"},
250 /* 140-149 */ 252 /* 140-149 */
251 { TUNER_ABSENT, "Philips 8275A_8295"}, 253 { TUNER_ABSENT, "Philips 8275A_8295"},
252 { TUNER_ABSENT, "TCL MF02GIP_5N_E"}, 254 { TUNER_ABSENT, "TCL MF02GIP_5N_E"},
253 { TUNER_ABSENT, "TCL MF02GIP_3DB_E"}, 255 { TUNER_ABSENT, "TCL MF02GIP_3DB_E"},
254 { TUNER_ABSENT, "TCL MF02GIP_3DI_E"}, 256 { TUNER_ABSENT, "TCL MF02GIP_3DI_E"},
255 { TUNER_ABSENT, "Microtune MT2266"}, 257 { TUNER_ABSENT, "Microtune MT2266"},
256 { TUNER_ABSENT, "TCL MF10WPP_4N_E"}, 258 { TUNER_ABSENT, "TCL MF10WPP_4N_E"},
257 { TUNER_ABSENT, "LG TAPQ_H702F"}, 259 { TUNER_ABSENT, "LG TAPQ_H702F"},
258 { TUNER_ABSENT, "TCL M09WPP_4N_E"}, 260 { TUNER_ABSENT, "TCL M09WPP_4N_E"},
259 { TUNER_ABSENT, "MaxLinear MXL5005_v2"}, 261 { TUNER_ABSENT, "MaxLinear MXL5005_v2"},
260 { TUNER_ABSENT, "Philips 18271_8295"}, 262 { TUNER_PHILIPS_TDA8290, "Philips 18271_8295"},
263 /* 150-159 */
264 { TUNER_ABSENT, "Xceive XC5000"},
261}; 265};
262 266
263static struct HAUPPAUGE_AUDIOIC 267static struct HAUPPAUGE_AUDIOIC
@@ -344,37 +348,37 @@ static const char *decoderIC[] = {
344static int hasRadioTuner(int tunerType) 348static int hasRadioTuner(int tunerType)
345{ 349{
346 switch (tunerType) { 350 switch (tunerType) {
347 case 18: //PNPEnv_TUNER_FR1236_MK2: 351 case 18: /* PNPEnv_TUNER_FR1236_MK2 */
348 case 23: //PNPEnv_TUNER_FM1236: 352 case 23: /* PNPEnv_TUNER_FM1236 */
349 case 38: //PNPEnv_TUNER_FMR1236: 353 case 38: /* PNPEnv_TUNER_FMR1236 */
350 case 16: //PNPEnv_TUNER_FR1216_MK2: 354 case 16: /* PNPEnv_TUNER_FR1216_MK2 */
351 case 19: //PNPEnv_TUNER_FR1246_MK2: 355 case 19: /* PNPEnv_TUNER_FR1246_MK2 */
352 case 21: //PNPEnv_TUNER_FM1216: 356 case 21: /* PNPEnv_TUNER_FM1216 */
353 case 24: //PNPEnv_TUNER_FM1246: 357 case 24: /* PNPEnv_TUNER_FM1246 */
354 case 17: //PNPEnv_TUNER_FR1216MF_MK2: 358 case 17: /* PNPEnv_TUNER_FR1216MF_MK2 */
355 case 22: //PNPEnv_TUNER_FM1216MF: 359 case 22: /* PNPEnv_TUNER_FM1216MF */
356 case 20: //PNPEnv_TUNER_FR1256_MK2: 360 case 20: /* PNPEnv_TUNER_FR1256_MK2 */
357 case 25: //PNPEnv_TUNER_FM1256: 361 case 25: /* PNPEnv_TUNER_FM1256 */
358 case 33: //PNPEnv_TUNER_4039FR5: 362 case 33: /* PNPEnv_TUNER_4039FR5 */
359 case 42: //PNPEnv_TUNER_4009FR5: 363 case 42: /* PNPEnv_TUNER_4009FR5 */
360 case 52: //PNPEnv_TUNER_4049FM5: 364 case 52: /* PNPEnv_TUNER_4049FM5 */
361 case 54: //PNPEnv_TUNER_4049FM5_AltI2C: 365 case 54: /* PNPEnv_TUNER_4049FM5_AltI2C */
362 case 44: //PNPEnv_TUNER_4009FN5: 366 case 44: /* PNPEnv_TUNER_4009FN5 */
363 case 31: //PNPEnv_TUNER_TCPB9085P: 367 case 31: /* PNPEnv_TUNER_TCPB9085P */
364 case 30: //PNPEnv_TUNER_TCPN9085D: 368 case 30: /* PNPEnv_TUNER_TCPN9085D */
365 case 46: //PNPEnv_TUNER_TP18NSR01F: 369 case 46: /* PNPEnv_TUNER_TP18NSR01F */
366 case 47: //PNPEnv_TUNER_TP18PSB01D: 370 case 47: /* PNPEnv_TUNER_TP18PSB01D */
367 case 49: //PNPEnv_TUNER_TAPC_I001D: 371 case 49: /* PNPEnv_TUNER_TAPC_I001D */
368 case 60: //PNPEnv_TUNER_TAPE_S001D_MK3: 372 case 60: /* PNPEnv_TUNER_TAPE_S001D_MK3 */
369 case 57: //PNPEnv_TUNER_FM1216ME_MK3: 373 case 57: /* PNPEnv_TUNER_FM1216ME_MK3 */
370 case 59: //PNPEnv_TUNER_FM1216MP_MK3: 374 case 59: /* PNPEnv_TUNER_FM1216MP_MK3 */
371 case 58: //PNPEnv_TUNER_FM1236_MK3: 375 case 58: /* PNPEnv_TUNER_FM1236_MK3 */
372 case 68: //PNPEnv_TUNER_TAPE_H001F_MK3: 376 case 68: /* PNPEnv_TUNER_TAPE_H001F_MK3 */
373 case 61: //PNPEnv_TUNER_TAPE_M001D_MK3: 377 case 61: /* PNPEnv_TUNER_TAPE_M001D_MK3 */
374 case 78: //PNPEnv_TUNER_TDA8275C1_8290_FM: 378 case 78: /* PNPEnv_TUNER_TDA8275C1_8290_FM */
375 case 89: //PNPEnv_TUNER_TCL_MFPE05_2: 379 case 89: /* PNPEnv_TUNER_TCL_MFPE05_2 */
376 case 92: //PNPEnv_TUNER_PHILIPS_FQ1236A_MK4: 380 case 92: /* PNPEnv_TUNER_PHILIPS_FQ1236A_MK4 */
377 case 105: 381 case 105:
378 return 1; 382 return 1;
379 } 383 }
380 return 0; 384 return 0;
@@ -392,7 +396,8 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
392 ** 396 **
393 ** In our (ivtv) case we're interested in the following: 397 ** In our (ivtv) case we're interested in the following:
394 ** tuner type: tag [00].05 or [0a].01 (index into hauppauge_tuner) 398 ** tuner type: tag [00].05 or [0a].01 (index into hauppauge_tuner)
395 ** tuner fmts: tag [00].04 or [0a].00 (bitmask index into hauppauge_tuner_fmt) 399 ** tuner fmts: tag [00].04 or [0a].00 (bitmask index into
400 ** hauppauge_tuner_fmt)
396 ** radio: tag [00].{last} or [0e].00 (bitmask. bit2=FM) 401 ** radio: tag [00].{last} or [0e].00 (bitmask. bit2=FM)
397 ** audio proc: tag [02].01 or [05].00 (mask with 0x7f) 402 ** audio proc: tag [02].01 or [05].00 (mask with 0x7f)
398 ** decoder proc: tag [09].01) 403 ** decoder proc: tag [09].01)
@@ -405,9 +410,9 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
405 ** # of inputs/outputs ??? 410 ** # of inputs/outputs ???
406 */ 411 */
407 412
408 int i, j, len, done, beenhere, tag,start; 413 int i, j, len, done, beenhere, tag, start;
409 414
410 int tuner1 = 0, t_format1 = 0, audioic=-1; 415 int tuner1 = 0, t_format1 = 0, audioic = -1;
411 char *t_name1 = NULL; 416 char *t_name1 = NULL;
412 const char *t_fmt_name1[8] = { " none", "", "", "", "", "", "", "" }; 417 const char *t_fmt_name1[8] = { " none", "", "", "", "", "", "", "" };
413 418
@@ -418,17 +423,24 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
418 memset(tvee, 0, sizeof(*tvee)); 423 memset(tvee, 0, sizeof(*tvee));
419 done = len = beenhere = 0; 424 done = len = beenhere = 0;
420 425
421 /* Hack for processing eeprom for em28xx and cx 2388x*/ 426 /* Different eeprom start offsets for em28xx, cx2388x and cx23418 */
422 if ((eeprom_data[0] == 0x1a) && (eeprom_data[1] == 0xeb) && 427 if (eeprom_data[0] == 0x1a &&
423 (eeprom_data[2] == 0x67) && (eeprom_data[3] == 0x95)) 428 eeprom_data[1] == 0xeb &&
424 start=0xa0; /* Generic em28xx offset */ 429 eeprom_data[2] == 0x67 &&
425 else if (((eeprom_data[0] & 0xe1) == 0x01) && 430 eeprom_data[3] == 0x95)
426 (eeprom_data[1] == 0x00) && 431 start = 0xa0; /* Generic em28xx offset */
427 (eeprom_data[2] == 0x00) && 432 else if ((eeprom_data[0] & 0xe1) == 0x01 &&
428 (eeprom_data[8] == 0x84)) 433 eeprom_data[1] == 0x00 &&
429 start=8; /* Generic cx2388x offset */ 434 eeprom_data[2] == 0x00 &&
435 eeprom_data[8] == 0x84)
436 start = 8; /* Generic cx2388x offset */
437 else if (eeprom_data[1] == 0x70 &&
438 eeprom_data[2] == 0x00 &&
439 eeprom_data[4] == 0x74 &&
440 eeprom_data[8] == 0x84)
441 start = 8; /* Generic cx23418 offset (models 74xxx) */
430 else 442 else
431 start=0; 443 start = 0;
432 444
433 for (i = start; !done && i < 256; i += len) { 445 for (i = start; !done && i < 256; i += len) {
434 if (eeprom_data[i] == 0x84) { 446 if (eeprom_data[i] == 0x84) {
@@ -444,16 +456,17 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
444 ++i; 456 ++i;
445 } else { 457 } else {
446 tveeprom_warn("Encountered bad packet header [%02x]. " 458 tveeprom_warn("Encountered bad packet header [%02x]. "
447 "Corrupt or not a Hauppauge eeprom.\n", eeprom_data[i]); 459 "Corrupt or not a Hauppauge eeprom.\n",
460 eeprom_data[i]);
448 return; 461 return;
449 } 462 }
450 463
451 if (debug) { 464 if (debug) {
452 tveeprom_info("Tag [%02x] + %d bytes:", eeprom_data[i], len - 1); 465 tveeprom_info("Tag [%02x] + %d bytes:",
453 for(j = 1; j < len; j++) { 466 eeprom_data[i], len - 1);
454 printk(" %02x", eeprom_data[i + j]); 467 for (j = 1; j < len; j++)
455 } 468 printk(KERN_CONT " %02x", eeprom_data[i + j]);
456 printk("\n"); 469 printk(KERN_CONT "\n");
457 } 470 }
458 471
459 /* process by tag */ 472 /* process by tag */
@@ -504,16 +517,16 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
504 (eeprom_data[i+6] << 8) + 517 (eeprom_data[i+6] << 8) +
505 (eeprom_data[i+7] << 16); 518 (eeprom_data[i+7] << 16);
506 519
507 if ( (eeprom_data[i + 8] & 0xf0) && 520 if ((eeprom_data[i + 8] & 0xf0) &&
508 (tvee->serial_number < 0xffffff) ) { 521 (tvee->serial_number < 0xffffff)) {
509 tvee->MAC_address[0] = 0x00; 522 tvee->MAC_address[0] = 0x00;
510 tvee->MAC_address[1] = 0x0D; 523 tvee->MAC_address[1] = 0x0D;
511 tvee->MAC_address[2] = 0xFE; 524 tvee->MAC_address[2] = 0xFE;
512 tvee->MAC_address[3] = eeprom_data[i + 7]; 525 tvee->MAC_address[3] = eeprom_data[i + 7];
513 tvee->MAC_address[4] = eeprom_data[i + 6]; 526 tvee->MAC_address[4] = eeprom_data[i + 6];
514 tvee->MAC_address[5] = eeprom_data[i + 5]; 527 tvee->MAC_address[5] = eeprom_data[i + 5];
515 tvee->has_MAC_address = 1; 528 tvee->has_MAC_address = 1;
516 } 529 }
517 break; 530 break;
518 531
519 case 0x05: 532 case 0x05:
@@ -537,7 +550,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
537 (eeprom_data[i + 3] << 16) + 550 (eeprom_data[i + 3] << 16) +
538 (eeprom_data[i + 4] << 24); 551 (eeprom_data[i + 4] << 24);
539 tvee->revision = 552 tvee->revision =
540 eeprom_data[i +5 ] + 553 eeprom_data[i + 5] +
541 (eeprom_data[i + 6] << 8) + 554 (eeprom_data[i + 6] << 8) +
542 (eeprom_data[i + 7] << 16); 555 (eeprom_data[i + 7] << 16);
543 break; 556 break;
@@ -557,16 +570,16 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
557 case 0x0a: 570 case 0x0a:
558 /* tag 'Tuner' */ 571 /* tag 'Tuner' */
559 if (beenhere == 0) { 572 if (beenhere == 0) {
560 tuner1 = eeprom_data[i+2]; 573 tuner1 = eeprom_data[i + 2];
561 t_format1 = eeprom_data[i+1]; 574 t_format1 = eeprom_data[i + 1];
562 beenhere = 1; 575 beenhere = 1;
563 } else { 576 } else {
564 /* a second (radio) tuner may be present */ 577 /* a second (radio) tuner may be present */
565 tuner2 = eeprom_data[i+2]; 578 tuner2 = eeprom_data[i + 2];
566 t_format2 = eeprom_data[i+1]; 579 t_format2 = eeprom_data[i + 1];
567 if (t_format2 == 0) { /* not a TV tuner? */ 580 /* not a TV tuner? */
581 if (t_format2 == 0)
568 tvee->has_radio = 1; /* must be radio */ 582 tvee->has_radio = 1; /* must be radio */
569 }
570 } 583 }
571 break; 584 break;
572 585
@@ -594,7 +607,8 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
594 /* case 0x12: tag 'InfoBits' */ 607 /* case 0x12: tag 'InfoBits' */
595 608
596 default: 609 default:
597 tveeprom_dbg("Not sure what to do with tag [%02x]\n", tag); 610 tveeprom_dbg("Not sure what to do with tag [%02x]\n",
611 tag);
598 /* dump the rest of the packet? */ 612 /* dump the rest of the packet? */
599 } 613 }
600 } 614 }
@@ -608,7 +622,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
608 tvee->rev_str[0] = 32 + ((tvee->revision >> 18) & 0x3f); 622 tvee->rev_str[0] = 32 + ((tvee->revision >> 18) & 0x3f);
609 tvee->rev_str[1] = 32 + ((tvee->revision >> 12) & 0x3f); 623 tvee->rev_str[1] = 32 + ((tvee->revision >> 12) & 0x3f);
610 tvee->rev_str[2] = 32 + ((tvee->revision >> 6) & 0x3f); 624 tvee->rev_str[2] = 32 + ((tvee->revision >> 6) & 0x3f);
611 tvee->rev_str[3] = 32 + ( tvee->revision & 0x3f); 625 tvee->rev_str[3] = 32 + (tvee->revision & 0x3f);
612 tvee->rev_str[4] = 0; 626 tvee->rev_str[4] = 0;
613 } 627 }
614 628
@@ -651,44 +665,40 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
651 665
652 tveeprom_info("Hauppauge model %d, rev %s, serial# %d\n", 666 tveeprom_info("Hauppauge model %d, rev %s, serial# %d\n",
653 tvee->model, tvee->rev_str, tvee->serial_number); 667 tvee->model, tvee->rev_str, tvee->serial_number);
654 if (tvee->has_MAC_address == 1) { 668 if (tvee->has_MAC_address == 1)
655 tveeprom_info("MAC address is %02X-%02X-%02X-%02X-%02X-%02X\n", 669 tveeprom_info("MAC address is %02X-%02X-%02X-%02X-%02X-%02X\n",
656 tvee->MAC_address[0], tvee->MAC_address[1], 670 tvee->MAC_address[0], tvee->MAC_address[1],
657 tvee->MAC_address[2], tvee->MAC_address[3], 671 tvee->MAC_address[2], tvee->MAC_address[3],
658 tvee->MAC_address[4], tvee->MAC_address[5]); 672 tvee->MAC_address[4], tvee->MAC_address[5]);
659 }
660 tveeprom_info("tuner model is %s (idx %d, type %d)\n", 673 tveeprom_info("tuner model is %s (idx %d, type %d)\n",
661 t_name1, tuner1, tvee->tuner_type); 674 t_name1, tuner1, tvee->tuner_type);
662 tveeprom_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n", 675 tveeprom_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n",
663 t_fmt_name1[0], t_fmt_name1[1], t_fmt_name1[2], t_fmt_name1[3], 676 t_fmt_name1[0], t_fmt_name1[1], t_fmt_name1[2],
664 t_fmt_name1[4], t_fmt_name1[5], t_fmt_name1[6], t_fmt_name1[7], 677 t_fmt_name1[3], t_fmt_name1[4], t_fmt_name1[5],
665 t_format1); 678 t_fmt_name1[6], t_fmt_name1[7], t_format1);
666 if (tuner2) { 679 if (tuner2)
667 tveeprom_info("second tuner model is %s (idx %d, type %d)\n", 680 tveeprom_info("second tuner model is %s (idx %d, type %d)\n",
668 t_name2, tuner2, tvee->tuner2_type); 681 t_name2, tuner2, tvee->tuner2_type);
669 } 682 if (t_format2)
670 if (t_format2) {
671 tveeprom_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n", 683 tveeprom_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n",
672 t_fmt_name2[0], t_fmt_name2[1], t_fmt_name2[2], t_fmt_name2[3], 684 t_fmt_name2[0], t_fmt_name2[1], t_fmt_name2[2],
673 t_fmt_name2[4], t_fmt_name2[5], t_fmt_name2[6], t_fmt_name2[7], 685 t_fmt_name2[3], t_fmt_name2[4], t_fmt_name2[5],
674 t_format2); 686 t_fmt_name2[6], t_fmt_name2[7], t_format2);
675 } 687 if (audioic < 0) {
676 if (audioic<0) {
677 tveeprom_info("audio processor is unknown (no idx)\n"); 688 tveeprom_info("audio processor is unknown (no idx)\n");
678 tvee->audio_processor=AUDIO_CHIP_UNKNOWN; 689 tvee->audio_processor = AUDIO_CHIP_UNKNOWN;
679 } else { 690 } else {
680 if (audioic < ARRAY_SIZE(audioIC)) 691 if (audioic < ARRAY_SIZE(audioIC))
681 tveeprom_info("audio processor is %s (idx %d)\n", 692 tveeprom_info("audio processor is %s (idx %d)\n",
682 audioIC[audioic].name,audioic); 693 audioIC[audioic].name, audioic);
683 else 694 else
684 tveeprom_info("audio processor is unknown (idx %d)\n", 695 tveeprom_info("audio processor is unknown (idx %d)\n",
685 audioic); 696 audioic);
686 } 697 }
687 if (tvee->decoder_processor) { 698 if (tvee->decoder_processor)
688 tveeprom_info("decoder processor is %s (idx %d)\n", 699 tveeprom_info("decoder processor is %s (idx %d)\n",
689 STRM(decoderIC, tvee->decoder_processor), 700 STRM(decoderIC, tvee->decoder_processor),
690 tvee->decoder_processor); 701 tvee->decoder_processor);
691 }
692 if (tvee->has_ir == -1) 702 if (tvee->has_ir == -1)
693 tveeprom_info("has %sradio\n", 703 tveeprom_info("has %sradio\n",
694 tvee->has_radio ? "" : "no "); 704 tvee->has_radio ? "" : "no ");
@@ -709,11 +719,13 @@ int tveeprom_read(struct i2c_client *c, unsigned char *eedata, int len)
709 int err; 719 int err;
710 720
711 buf = 0; 721 buf = 0;
712 if (1 != (err = i2c_master_send(c, &buf, 1))) { 722 err = i2c_master_send(c, &buf, 1);
723 if (err != 1) {
713 tveeprom_info("Huh, no eeprom present (err=%d)?\n", err); 724 tveeprom_info("Huh, no eeprom present (err=%d)?\n", err);
714 return -1; 725 return -1;
715 } 726 }
716 if (len != (err = i2c_master_recv(c, eedata, len))) { 727 err = i2c_master_recv(c, eedata, len);
728 if (err != len) {
717 tveeprom_warn("i2c eeprom read error (err=%d)\n", err); 729 tveeprom_warn("i2c eeprom read error (err=%d)\n", err);
718 return -1; 730 return -1;
719 } 731 }
@@ -724,9 +736,9 @@ int tveeprom_read(struct i2c_client *c, unsigned char *eedata, int len)
724 for (i = 0; i < len; i++) { 736 for (i = 0; i < len; i++) {
725 if (0 == (i % 16)) 737 if (0 == (i % 16))
726 tveeprom_info("%02x:", i); 738 tveeprom_info("%02x:", i);
727 printk(" %02x", eedata[i]); 739 printk(KERN_CONT " %02x", eedata[i]);
728 if (15 == (i % 16)) 740 if (15 == (i % 16))
729 printk("\n"); 741 printk(KERN_CONT "\n");
730 } 742 }
731 } 743 }
732 return 0; 744 return 0;
@@ -758,9 +770,9 @@ tveeprom_command(struct i2c_client *client,
758 770
759 switch (cmd) { 771 switch (cmd) {
760 case 0: 772 case 0:
761 buf = kzalloc(256,GFP_KERNEL); 773 buf = kzalloc(256, GFP_KERNEL);
762 tveeprom_read(client,buf,256); 774 tveeprom_read(client, buf, 256);
763 tveeprom_hauppauge_analog(client, &eeprom,buf); 775 tveeprom_hauppauge_analog(client, &eeprom, buf);
764 kfree(buf); 776 kfree(buf);
765 eeprom_props[0] = eeprom.tuner_type; 777 eeprom_props[0] = eeprom.tuner_type;
766 eeprom_props[1] = eeprom.tuner_formats; 778 eeprom_props[1] = eeprom.tuner_formats;
@@ -794,7 +806,7 @@ tveeprom_detect_client(struct i2c_adapter *adapter,
794} 806}
795 807
796static int 808static int
797tveeprom_attach_adapter (struct i2c_adapter *adapter) 809tveeprom_attach_adapter(struct i2c_adapter *adapter)
798{ 810{
799 if (adapter->class & I2C_CLASS_TV_ANALOG) 811 if (adapter->class & I2C_CLASS_TV_ANALOG)
800 return i2c_probe(adapter, &addr_data, tveeprom_detect_client); 812 return i2c_probe(adapter, &addr_data, tveeprom_detect_client);
@@ -802,7 +814,7 @@ tveeprom_attach_adapter (struct i2c_adapter *adapter)
802} 814}
803 815
804static int 816static int
805tveeprom_detach_client (struct i2c_client *client) 817tveeprom_detach_client(struct i2c_client *client)
806{ 818{
807 int err; 819 int err;
808 820
diff --git a/drivers/media/video/upd64031a.c b/drivers/media/video/upd64031a.c
index 0b2a961efd22..bd201397a2ac 100644
--- a/drivers/media/video/upd64031a.c
+++ b/drivers/media/video/upd64031a.c
@@ -28,30 +28,27 @@
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
30#include <media/v4l2-chip-ident.h> 30#include <media/v4l2-chip-ident.h>
31#include <media/v4l2-i2c-drv.h>
31#include <media/upd64031a.h> 32#include <media/upd64031a.h>
32 33
33// --------------------- read registers functions define ----------------------- 34/* --------------------- read registers functions define -------------------- */
34 35
35/* bit masks */ 36/* bit masks */
36#define GR_MODE_MASK 0xc0 37#define GR_MODE_MASK 0xc0
37#define DIRECT_3DYCS_CONNECT_MASK 0xc0 38#define DIRECT_3DYCS_CONNECT_MASK 0xc0
38#define SYNC_CIRCUIT_MASK 0xa0 39#define SYNC_CIRCUIT_MASK 0xa0
39 40
40// ----------------------------------------------------------------------------- 41/* -------------------------------------------------------------------------- */
41 42
42MODULE_DESCRIPTION("uPD64031A driver"); 43MODULE_DESCRIPTION("uPD64031A driver");
43MODULE_AUTHOR("T. Adachi, Takeru KOMORIYA, Hans Verkuil"); 44MODULE_AUTHOR("T. Adachi, Takeru KOMORIYA, Hans Verkuil");
44MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
45 46
46static int debug = 0; 47static int debug;
47module_param(debug, int, 0644); 48module_param(debug, int, 0644);
48 49
49MODULE_PARM_DESC(debug, "Debug level (0-1)"); 50MODULE_PARM_DESC(debug, "Debug level (0-1)");
50 51
51static unsigned short normal_i2c[] = { 0x24 >> 1, 0x26 >> 1, I2C_CLIENT_END };
52
53
54I2C_CLIENT_INSMOD;
55 52
56enum { 53enum {
57 R00 = 0, R01, R02, R03, R04, 54 R00 = 0, R01, R02, R03, R04,
@@ -99,7 +96,7 @@ static void upd64031a_write(struct i2c_client *client, u8 reg, u8 val)
99 96
100 buf[0] = reg; 97 buf[0] = reg;
101 buf[1] = val; 98 buf[1] = val;
102 v4l_dbg(1, debug, client, "writing reg addr: %02X val: %02X\n", reg, val); 99 v4l_dbg(1, debug, client, "write reg: %02X val: %02X\n", reg, val);
103 if (i2c_master_send(client, buf, 2) != 2) 100 if (i2c_master_send(client, buf, 2) != 2)
104 v4l_err(client, "I/O error write 0x%02x/0x%02x\n", reg, val); 101 v4l_err(client, "I/O error write 0x%02x/0x%02x\n", reg, val);
105} 102}
@@ -119,7 +116,7 @@ static void upd64031a_change(struct i2c_client *client)
119 116
120/* ------------------------------------------------------------------------ */ 117/* ------------------------------------------------------------------------ */
121 118
122static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *arg) 119static int upd64031a_command(struct i2c_client *client, unsigned cmd, void *arg)
123{ 120{
124 struct upd64031a_state *state = i2c_get_clientdata(client); 121 struct upd64031a_state *state = i2c_get_clientdata(client);
125 struct v4l2_routing *route = arg; 122 struct v4l2_routing *route = arg;
@@ -143,8 +140,10 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
143 140
144 state->gr_mode = (route->input & 3) << 6; 141 state->gr_mode = (route->input & 3) << 6;
145 state->direct_3dycs_connect = (route->input & 0xc) << 4; 142 state->direct_3dycs_connect = (route->input & 0xc) << 4;
146 state->ext_comp_sync = (route->input & UPD64031A_COMPOSITE_EXTERNAL) << 1; 143 state->ext_comp_sync =
147 state->ext_vert_sync = (route->input & UPD64031A_VERTICAL_EXTERNAL) << 2; 144 (route->input & UPD64031A_COMPOSITE_EXTERNAL) << 1;
145 state->ext_vert_sync =
146 (route->input & UPD64031A_VERTICAL_EXTERNAL) << 2;
148 r00 = (state->regs[R00] & ~GR_MODE_MASK) | state->gr_mode; 147 r00 = (state->regs[R00] & ~GR_MODE_MASK) | state->gr_mode;
149 r05 = (state->regs[R00] & ~SYNC_CIRCUIT_MASK) | 148 r05 = (state->regs[R00] & ~SYNC_CIRCUIT_MASK) |
150 state->ext_comp_sync | state->ext_vert_sync; 149 state->ext_comp_sync | state->ext_vert_sync;
@@ -168,20 +167,23 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
168 { 167 {
169 struct v4l2_register *reg = arg; 168 struct v4l2_register *reg = arg;
170 169
171 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip)) 170 if (!v4l2_chip_match_i2c_client(client,
171 reg->match_type, reg->match_chip))
172 return -EINVAL; 172 return -EINVAL;
173 if (!capable(CAP_SYS_ADMIN)) 173 if (!capable(CAP_SYS_ADMIN))
174 return -EPERM; 174 return -EPERM;
175 if (cmd == VIDIOC_DBG_G_REGISTER) 175 if (cmd == VIDIOC_DBG_G_REGISTER) {
176 reg->val = upd64031a_read(client, reg->reg & 0xff); 176 reg->val = upd64031a_read(client, reg->reg & 0xff);
177 else 177 break;
178 upd64031a_write(client, reg->reg & 0xff, reg->val & 0xff); 178 }
179 upd64031a_write(client, reg->reg & 0xff, reg->val & 0xff);
179 break; 180 break;
180 } 181 }
181#endif 182#endif
182 183
183 case VIDIOC_G_CHIP_IDENT: 184 case VIDIOC_G_CHIP_IDENT:
184 return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_UPD64031A, 0); 185 return v4l2_chip_ident_i2c_client(client, arg,
186 V4L2_IDENT_UPD64031A, 0);
185 187
186 default: 188 default:
187 break; 189 break;
@@ -193,90 +195,43 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
193 195
194/* i2c implementation */ 196/* i2c implementation */
195 197
196static struct i2c_driver i2c_driver; 198static int upd64031a_probe(struct i2c_client *client)
197
198static int upd64031a_attach(struct i2c_adapter *adapter, int address, int kind)
199{ 199{
200 struct i2c_client *client;
201 struct upd64031a_state *state; 200 struct upd64031a_state *state;
202 int i; 201 int i;
203 202
204 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 203 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
205 return 0; 204 return -EIO;
206
207 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
208 if (client == NULL) {
209 return -ENOMEM;
210 }
211
212 client->addr = address;
213 client->adapter = adapter;
214 client->driver = &i2c_driver;
215 snprintf(client->name, sizeof(client->name) - 1, "uPD64031A");
216 205
217 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name); 206 v4l_info(client, "chip found @ 0x%x (%s)\n",
207 client->addr << 1, client->adapter->name);
218 208
219 state = kmalloc(sizeof(struct upd64031a_state), GFP_KERNEL); 209 state = kmalloc(sizeof(struct upd64031a_state), GFP_KERNEL);
220 if (state == NULL) { 210 if (state == NULL)
221 kfree(client);
222 return -ENOMEM; 211 return -ENOMEM;
223 }
224 i2c_set_clientdata(client, state); 212 i2c_set_clientdata(client, state);
225 memcpy(state->regs, upd64031a_init, sizeof(state->regs)); 213 memcpy(state->regs, upd64031a_init, sizeof(state->regs));
226 state->gr_mode = UPD64031A_GR_ON << 6; 214 state->gr_mode = UPD64031A_GR_ON << 6;
227 state->direct_3dycs_connect = UPD64031A_3DYCS_COMPOSITE << 4; 215 state->direct_3dycs_connect = UPD64031A_3DYCS_COMPOSITE << 4;
228 state->ext_comp_sync = state->ext_vert_sync = 0; 216 state->ext_comp_sync = state->ext_vert_sync = 0;
229 for (i = 0; i < TOT_REGS; i++) { 217 for (i = 0; i < TOT_REGS; i++)
230 upd64031a_write(client, i, state->regs[i]); 218 upd64031a_write(client, i, state->regs[i]);
231 }
232
233 i2c_attach_client(client);
234
235 return 0; 219 return 0;
236} 220}
237 221
238static int upd64031a_probe(struct i2c_adapter *adapter) 222static int upd64031a_remove(struct i2c_client *client)
239{ 223{
240 if (adapter->class & I2C_CLASS_TV_ANALOG) 224 kfree(i2c_get_clientdata(client));
241 return i2c_probe(adapter, &addr_data, upd64031a_attach);
242 return 0;
243}
244
245static int upd64031a_detach(struct i2c_client *client)
246{
247 int err;
248
249 err = i2c_detach_client(client);
250 if (err)
251 return err;
252
253 kfree(client);
254 return 0; 225 return 0;
255} 226}
256 227
257/* ----------------------------------------------------------------------- */ 228/* ----------------------------------------------------------------------- */
258 229
259/* i2c implementation */ 230
260static struct i2c_driver i2c_driver = { 231static struct v4l2_i2c_driver_data v4l2_i2c_data = {
261 .driver = { 232 .name = "upd64031a",
262 .name = "upd64031a", 233 .driverid = I2C_DRIVERID_UPD64031A,
263 },
264 .id = I2C_DRIVERID_UPD64031A,
265 .attach_adapter = upd64031a_probe,
266 .detach_client = upd64031a_detach,
267 .command = upd64031a_command, 234 .command = upd64031a_command,
235 .probe = upd64031a_probe,
236 .remove = upd64031a_remove,
268}; 237};
269
270
271static int __init upd64031a_init_module(void)
272{
273 return i2c_add_driver(&i2c_driver);
274}
275
276static void __exit upd64031a_exit_module(void)
277{
278 i2c_del_driver(&i2c_driver);
279}
280
281module_init(upd64031a_init_module);
282module_exit(upd64031a_exit_module);
diff --git a/drivers/media/video/upd64083.c b/drivers/media/video/upd64083.c
index 401bd21f46eb..2d9a88f70c85 100644
--- a/drivers/media/video/upd64083.c
+++ b/drivers/media/video/upd64083.c
@@ -17,7 +17,8 @@
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
21 */ 22 */
22 23
23#include <linux/version.h> 24#include <linux/version.h>
@@ -27,21 +28,18 @@
27#include <linux/videodev2.h> 28#include <linux/videodev2.h>
28#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
29#include <media/v4l2-chip-ident.h> 30#include <media/v4l2-chip-ident.h>
31#include <media/v4l2-i2c-drv.h>
30#include <media/upd64083.h> 32#include <media/upd64083.h>
31 33
32MODULE_DESCRIPTION("uPD64083 driver"); 34MODULE_DESCRIPTION("uPD64083 driver");
33MODULE_AUTHOR("T. Adachi, Takeru KOMORIYA, Hans Verkuil"); 35MODULE_AUTHOR("T. Adachi, Takeru KOMORIYA, Hans Verkuil");
34MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
35 37
36static int debug = 0; 38static int debug;
37module_param(debug, bool, 0644); 39module_param(debug, bool, 0644);
38 40
39MODULE_PARM_DESC(debug, "Debug level (0-1)"); 41MODULE_PARM_DESC(debug, "Debug level (0-1)");
40 42
41static unsigned short normal_i2c[] = { 0xb8 >> 1, 0xba >> 1, I2C_CLIENT_END };
42
43
44I2C_CLIENT_INSMOD;
45 43
46enum { 44enum {
47 R00 = 0, R01, R02, R03, R04, 45 R00 = 0, R01, R02, R03, R04,
@@ -88,7 +86,7 @@ static void upd64083_write(struct i2c_client *client, u8 reg, u8 val)
88 86
89 buf[0] = reg; 87 buf[0] = reg;
90 buf[1] = val; 88 buf[1] = val;
91 v4l_dbg(1, debug, client, "writing reg addr: %02x val: %02x\n", reg, val); 89 v4l_dbg(1, debug, client, "write reg: %02x val: %02x\n", reg, val);
92 if (i2c_master_send(client, buf, 2) != 2) 90 if (i2c_master_send(client, buf, 2) != 2)
93 v4l_err(client, "I/O error write 0x%02x/0x%02x\n", reg, val); 91 v4l_err(client, "I/O error write 0x%02x/0x%02x\n", reg, val);
94} 92}
@@ -109,7 +107,7 @@ static u8 upd64083_read(struct i2c_client *client, u8 reg)
109 107
110/* ------------------------------------------------------------------------ */ 108/* ------------------------------------------------------------------------ */
111 109
112static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *arg) 110static int upd64083_command(struct i2c_client *client, unsigned cmd, void *arg)
113{ 111{
114 struct upd64083_state *state = i2c_get_clientdata(client); 112 struct upd64083_state *state = i2c_get_clientdata(client);
115 struct v4l2_routing *route = arg; 113 struct v4l2_routing *route = arg;
@@ -145,20 +143,23 @@ static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *a
145 { 143 {
146 struct v4l2_register *reg = arg; 144 struct v4l2_register *reg = arg;
147 145
148 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip)) 146 if (!v4l2_chip_match_i2c_client(client,
147 reg->match_type, reg->match_chip))
149 return -EINVAL; 148 return -EINVAL;
150 if (!capable(CAP_SYS_ADMIN)) 149 if (!capable(CAP_SYS_ADMIN))
151 return -EPERM; 150 return -EPERM;
152 if (cmd == VIDIOC_DBG_G_REGISTER) 151 if (cmd == VIDIOC_DBG_G_REGISTER) {
153 reg->val = upd64083_read(client, reg->reg & 0xff); 152 reg->val = upd64083_read(client, reg->reg & 0xff);
154 else 153 break;
155 upd64083_write(client, reg->reg & 0xff, reg->val & 0xff); 154 }
155 upd64083_write(client, reg->reg & 0xff, reg->val & 0xff);
156 break; 156 break;
157 } 157 }
158#endif 158#endif
159 159
160 case VIDIOC_G_CHIP_IDENT: 160 case VIDIOC_G_CHIP_IDENT:
161 return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_UPD64083, 0); 161 return v4l2_chip_ident_i2c_client(client, arg,
162 V4L2_IDENT_UPD64083, 0);
162 163
163 default: 164 default:
164 break; 165 break;
@@ -171,89 +172,43 @@ static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *a
171 172
172/* i2c implementation */ 173/* i2c implementation */
173 174
174static struct i2c_driver i2c_driver; 175static int upd64083_probe(struct i2c_client *client)
175
176static int upd64083_attach(struct i2c_adapter *adapter, int address, int kind)
177{ 176{
178 struct i2c_client *client;
179 struct upd64083_state *state; 177 struct upd64083_state *state;
180 int i; 178 int i;
181 179
182 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 180 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
183 return 0; 181 return -EIO;
184
185 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
186 if (client == NULL) {
187 return -ENOMEM;
188 }
189
190 client->addr = address;
191 client->adapter = adapter;
192 client->driver = &i2c_driver;
193 snprintf(client->name, sizeof(client->name) - 1, "uPD64083");
194 182
195 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name); 183 v4l_info(client, "chip found @ 0x%x (%s)\n",
184 client->addr << 1, client->adapter->name);
196 185
197 state = kmalloc(sizeof(struct upd64083_state), GFP_KERNEL); 186 state = kmalloc(sizeof(struct upd64083_state), GFP_KERNEL);
198 if (state == NULL) { 187 if (state == NULL)
199 kfree(client);
200 return -ENOMEM; 188 return -ENOMEM;
201 }
202 i2c_set_clientdata(client, state); 189 i2c_set_clientdata(client, state);
203 /* Initially assume that a ghost reduction chip is present */ 190 /* Initially assume that a ghost reduction chip is present */
204 state->mode = 0; /* YCS mode */ 191 state->mode = 0; /* YCS mode */
205 state->ext_y_adc = (1 << 5); 192 state->ext_y_adc = (1 << 5);
206 memcpy(state->regs, upd64083_init, TOT_REGS); 193 memcpy(state->regs, upd64083_init, TOT_REGS);
207 for (i = 0; i < TOT_REGS; i++) { 194 for (i = 0; i < TOT_REGS; i++)
208 upd64083_write(client, i, state->regs[i]); 195 upd64083_write(client, i, state->regs[i]);
209 }
210 i2c_attach_client(client);
211
212 return 0;
213}
214
215static int upd64083_probe(struct i2c_adapter *adapter)
216{
217 if (adapter->class & I2C_CLASS_TV_ANALOG)
218 return i2c_probe(adapter, &addr_data, upd64083_attach);
219 return 0; 196 return 0;
220} 197}
221 198
222static int upd64083_detach(struct i2c_client *client) 199static int upd64083_remove(struct i2c_client *client)
223{ 200{
224 int err; 201 kfree(i2c_get_clientdata(client));
225
226 err = i2c_detach_client(client);
227 if (err)
228 return err;
229
230 kfree(client);
231 return 0; 202 return 0;
232} 203}
233 204
234/* ----------------------------------------------------------------------- */ 205/* ----------------------------------------------------------------------- */
235 206
236/* i2c implementation */ 207
237static struct i2c_driver i2c_driver = { 208static struct v4l2_i2c_driver_data v4l2_i2c_data = {
238 .driver = { 209 .name = "upd64083",
239 .name = "upd64083", 210 .driverid = I2C_DRIVERID_UPD64083,
240 },
241 .id = I2C_DRIVERID_UPD64083,
242 .attach_adapter = upd64083_probe,
243 .detach_client = upd64083_detach,
244 .command = upd64083_command, 211 .command = upd64083_command,
212 .probe = upd64083_probe,
213 .remove = upd64083_remove,
245}; 214};
246
247
248static int __init upd64083_init_module(void)
249{
250 return i2c_add_driver(&i2c_driver);
251}
252
253static void __exit upd64083_exit_module(void)
254{
255 i2c_del_driver(&i2c_driver);
256}
257
258module_init(upd64083_init_module);
259module_exit(upd64083_exit_module);
diff --git a/drivers/media/video/usbvision/usbvision-cards.c b/drivers/media/video/usbvision/usbvision-cards.c
index f09eb102731b..503b13beb922 100644
--- a/drivers/media/video/usbvision/usbvision-cards.c
+++ b/drivers/media/video/usbvision/usbvision-cards.c
@@ -901,6 +901,20 @@ struct usbvision_device_data_st usbvision_device_data[] = {
901 .Y_Offset = -1, 901 .Y_Offset = -1,
902 .ModelString = "Pinnacle Studio PCTV USB (NTSC) FM", 902 .ModelString = "Pinnacle Studio PCTV USB (NTSC) FM",
903 }, 903 },
904 [PINNA_PCTV_USB_NTSC_FM_V3] = {
905 .Interface = -1,
906 .Codec = CODEC_SAA7111,
907 .VideoChannels = 3,
908 .VideoNorm = V4L2_STD_NTSC,
909 .AudioChannels = 1,
910 .Radio = 1,
911 .vbi = 1,
912 .Tuner = 1,
913 .TunerType = TUNER_PHILIPS_NTSC_M,
914 .X_Offset = -1,
915 .Y_Offset = -1,
916 .ModelString = "Pinnacle Studio PCTV USB (NTSC) FM V3",
917 },
904 [PINNA_PCTV_USB_PAL_FM_V2] = { 918 [PINNA_PCTV_USB_PAL_FM_V2] = {
905 .Interface = -1, 919 .Interface = -1,
906 .Codec = CODEC_SAA7113, 920 .Codec = CODEC_SAA7113,
@@ -1044,7 +1058,7 @@ struct usb_device_id usbvision_table [] = {
1044 { USB_DEVICE(0x0573, 0x4d2a), .driver_info=HPG_WINTV_PRO_NTSC_MN }, 1058 { USB_DEVICE(0x0573, 0x4d2a), .driver_info=HPG_WINTV_PRO_NTSC_MN },
1045 { USB_DEVICE(0x0573, 0x4d2b), .driver_info=HPG_WINTV_PRO_NTSC_MN_V2 }, 1059 { USB_DEVICE(0x0573, 0x4d2b), .driver_info=HPG_WINTV_PRO_NTSC_MN_V2 },
1046 { USB_DEVICE(0x0573, 0x4d2c), .driver_info=HPG_WINTV_PRO_PAL }, 1060 { USB_DEVICE(0x0573, 0x4d2c), .driver_info=HPG_WINTV_PRO_PAL },
1047 { USB_DEVICE(0x0573, 0x4d20), .driver_info=HPG_WINTV_PRO_NTSC_MN_V3 }, 1061 { USB_DEVICE(0x0573, 0x4d20), .driver_info = HPG_WINTV_PRO_NTSC_MN_V3 },
1048 { USB_DEVICE(0x0573, 0x4d21), .driver_info=HPG_WINTV_PRO_PAL_BG }, 1062 { USB_DEVICE(0x0573, 0x4d21), .driver_info=HPG_WINTV_PRO_PAL_BG },
1049 { USB_DEVICE(0x0573, 0x4d22), .driver_info=HPG_WINTV_PRO_PAL_I }, 1063 { USB_DEVICE(0x0573, 0x4d22), .driver_info=HPG_WINTV_PRO_PAL_I },
1050 { USB_DEVICE(0x0573, 0x4d23), .driver_info=HPG_WINTV_PRO_PAL_SECAM_L }, 1064 { USB_DEVICE(0x0573, 0x4d23), .driver_info=HPG_WINTV_PRO_PAL_SECAM_L },
@@ -1074,6 +1088,8 @@ struct usb_device_id usbvision_table [] = {
1074 { USB_DEVICE(0x2304, 0x0110), .driver_info=PINNA_PCTV_USB_PAL_FM }, 1088 { USB_DEVICE(0x2304, 0x0110), .driver_info=PINNA_PCTV_USB_PAL_FM },
1075 { USB_DEVICE(0x2304, 0x0111), .driver_info=MIRO_PCTV_USB }, 1089 { USB_DEVICE(0x2304, 0x0111), .driver_info=MIRO_PCTV_USB },
1076 { USB_DEVICE(0x2304, 0x0112), .driver_info=PINNA_PCTV_USB_NTSC_FM }, 1090 { USB_DEVICE(0x2304, 0x0112), .driver_info=PINNA_PCTV_USB_NTSC_FM },
1091 { USB_DEVICE(0x2304, 0x0113),
1092 .driver_info = PINNA_PCTV_USB_NTSC_FM_V3 },
1077 { USB_DEVICE(0x2304, 0x0210), .driver_info=PINNA_PCTV_USB_PAL_FM_V2 }, 1093 { USB_DEVICE(0x2304, 0x0210), .driver_info=PINNA_PCTV_USB_PAL_FM_V2 },
1078 { USB_DEVICE(0x2304, 0x0212), .driver_info=PINNA_PCTV_USB_NTSC_FM_V2 }, 1094 { USB_DEVICE(0x2304, 0x0212), .driver_info=PINNA_PCTV_USB_NTSC_FM_V2 },
1079 { USB_DEVICE(0x2304, 0x0214), .driver_info=PINNA_PCTV_USB_PAL_FM_V3 }, 1095 { USB_DEVICE(0x2304, 0x0214), .driver_info=PINNA_PCTV_USB_PAL_FM_V3 },
diff --git a/drivers/media/video/usbvision/usbvision-cards.h b/drivers/media/video/usbvision/usbvision-cards.h
index 512c5cee4145..9c6ad22960d8 100644
--- a/drivers/media/video/usbvision/usbvision-cards.h
+++ b/drivers/media/video/usbvision/usbvision-cards.h
@@ -62,5 +62,6 @@
62#define PINNA_LINX_VD_IN_CAB_PAL 61 62#define PINNA_LINX_VD_IN_CAB_PAL 61
63#define PINNA_PCTV_BUNGEE_PAL_FM 62 63#define PINNA_PCTV_BUNGEE_PAL_FM 62
64#define HPG_WINTV 63 64#define HPG_WINTV 63
65#define PINNA_PCTV_USB_NTSC_FM_V3 64
65 66
66extern const int usbvision_device_data_size; 67extern const int usbvision_device_data_size;
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index c7d5f9ed22d7..56775ab8b75d 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -69,6 +69,15 @@ static int SwitchSVideoInput = 0; // To help people with Black and White outpu
69module_param(SwitchSVideoInput, int, 0444); 69module_param(SwitchSVideoInput, int, 0444);
70MODULE_PARM_DESC(SwitchSVideoInput, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)"); 70MODULE_PARM_DESC(SwitchSVideoInput, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)");
71 71
72static unsigned int adjust_X_Offset = -1;
73module_param(adjust_X_Offset, int, 0644);
74MODULE_PARM_DESC(adjust_X_Offset, "adjust X offset display [core]");
75
76static unsigned int adjust_Y_Offset = -1;
77module_param(adjust_Y_Offset, int, 0644);
78MODULE_PARM_DESC(adjust_Y_Offset, "adjust Y offset display [core]");
79
80
72#define ENABLE_HEXDUMP 0 /* Enable if you need it */ 81#define ENABLE_HEXDUMP 0 /* Enable if you need it */
73 82
74 83
@@ -624,25 +633,29 @@ static enum ParseState usbvision_parse_lines_422(struct usb_usbvision *usbvision
624 633
625 YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv); 634 YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv);
626 switch (frame->v4l2_format.format) { 635 switch (frame->v4l2_format.format) {
627 case V4L2_PIX_FMT_RGB565: 636 case V4L2_PIX_FMT_RGB565:
628 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 3)); 637 *f++ = (0x1F & rv) |
629 *f++ = (0x07 & (gv >> 5)) | (0xF8 & rv); 638 (0xE0 & (gv << 5));
630 break; 639 *f++ = (0x07 & (gv >> 3)) |
631 case V4L2_PIX_FMT_RGB24: 640 (0xF8 & bv);
632 *f++ = bv; 641 break;
633 *f++ = gv; 642 case V4L2_PIX_FMT_RGB24:
634 *f++ = rv; 643 *f++ = rv;
635 break; 644 *f++ = gv;
636 case V4L2_PIX_FMT_RGB32: 645 *f++ = bv;
637 *f++ = bv; 646 break;
638 *f++ = gv; 647 case V4L2_PIX_FMT_RGB32:
639 *f++ = rv; 648 *f++ = rv;
640 f++; 649 *f++ = gv;
641 break; 650 *f++ = bv;
642 case V4L2_PIX_FMT_RGB555: 651 f++;
643 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 2)); 652 break;
644 *f++ = (0x03 & (gv >> 6)) | (0x7C & (rv >> 1)); 653 case V4L2_PIX_FMT_RGB555:
645 break; 654 *f++ = (0x1F & rv) |
655 (0xE0 & (gv << 5));
656 *f++ = (0x03 & (gv >> 3)) |
657 (0x7C & (bv << 2));
658 break;
646 } 659 }
647 } 660 }
648 clipmask_index += clipmask_add; 661 clipmask_index += clipmask_add;
@@ -656,25 +669,29 @@ static enum ParseState usbvision_parse_lines_422(struct usb_usbvision *usbvision
656 669
657 YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv); 670 YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv);
658 switch (frame->v4l2_format.format) { 671 switch (frame->v4l2_format.format) {
659 case V4L2_PIX_FMT_RGB565: 672 case V4L2_PIX_FMT_RGB565:
660 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 3)); 673 *f++ = (0x1F & rv) |
661 *f++ = (0x07 & (gv >> 5)) | (0xF8 & rv); 674 (0xE0 & (gv << 5));
662 break; 675 *f++ = (0x07 & (gv >> 3)) |
663 case V4L2_PIX_FMT_RGB24: 676 (0xF8 & bv);
664 *f++ = bv; 677 break;
665 *f++ = gv; 678 case V4L2_PIX_FMT_RGB24:
666 *f++ = rv; 679 *f++ = rv;
667 break; 680 *f++ = gv;
668 case V4L2_PIX_FMT_RGB32: 681 *f++ = bv;
669 *f++ = bv; 682 break;
670 *f++ = gv; 683 case V4L2_PIX_FMT_RGB32:
671 *f++ = rv; 684 *f++ = rv;
672 f++; 685 *f++ = gv;
673 break; 686 *f++ = bv;
674 case V4L2_PIX_FMT_RGB555: 687 f++;
675 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 2)); 688 break;
676 *f++ = (0x03 & (gv >> 6)) | (0x7C & (rv >> 1)); 689 case V4L2_PIX_FMT_RGB555:
677 break; 690 *f++ = (0x1F & rv) |
691 (0xE0 & (gv << 5));
692 *f++ = (0x03 & (gv >> 3)) |
693 (0x7C & (bv << 2));
694 break;
678 } 695 }
679 } 696 }
680 clipmask_index += clipmask_add; 697 clipmask_index += clipmask_add;
@@ -942,22 +959,26 @@ static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
942 *f++ = Y[Idx]; 959 *f++ = Y[Idx];
943 break; 960 break;
944 case V4L2_PIX_FMT_RGB555: 961 case V4L2_PIX_FMT_RGB555:
945 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 2)); 962 *f++ = (0x1F & rv) |
946 *f++ = (0x03 & (gv >> 6)) | (0x7C & (rv >> 1)); 963 (0xE0 & (gv << 5));
964 *f++ = (0x03 & (gv >> 3)) |
965 (0x7C & (bv << 2));
947 break; 966 break;
948 case V4L2_PIX_FMT_RGB565: 967 case V4L2_PIX_FMT_RGB565:
949 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 3)); 968 *f++ = (0x1F & rv) |
950 *f++ = (0x07 & (gv >> 5)) | (0xF8 & rv); 969 (0xE0 & (gv << 5));
970 *f++ = (0x07 & (gv >> 3)) |
971 (0xF8 & bv);
951 break; 972 break;
952 case V4L2_PIX_FMT_RGB24: 973 case V4L2_PIX_FMT_RGB24:
953 *f++ = bv;
954 *f++ = gv;
955 *f++ = rv; 974 *f++ = rv;
975 *f++ = gv;
976 *f++ = bv;
956 break; 977 break;
957 case V4L2_PIX_FMT_RGB32: 978 case V4L2_PIX_FMT_RGB32:
958 *f++ = bv;
959 *f++ = gv;
960 *f++ = rv; 979 *f++ = rv;
980 *f++ = gv;
981 *f++ = bv;
961 f++; 982 f++;
962 break; 983 break;
963 } 984 }
@@ -1071,28 +1092,33 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1071 r_ = (y_ + ur) >> 16; 1092 r_ = (y_ + ur) >> 16;
1072 1093
1073 switch (frame->v4l2_format.format) { 1094 switch (frame->v4l2_format.format) {
1074 case V4L2_PIX_FMT_RGB565: 1095 case V4L2_PIX_FMT_RGB565:
1075 g = LIMIT_RGB(g_); 1096 g = LIMIT_RGB(g_);
1076 *f_even++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 3)); 1097 *f_even++ =
1077 *f_even++ = (0x07 & ( g >> 5)) | (0xF8 & LIMIT_RGB(r_)); 1098 (0x1F & LIMIT_RGB(r_)) |
1078 break; 1099 (0xE0 & (g << 5));
1079 case V4L2_PIX_FMT_RGB24: 1100 *f_even++ =
1080 *f_even++ = LIMIT_RGB(b_); 1101 (0x07 & (g >> 3)) |
1081 *f_even++ = LIMIT_RGB(g_); 1102 (0xF8 & LIMIT_RGB(b_));
1082 *f_even++ = LIMIT_RGB(r_); 1103 break;
1083 break; 1104 case V4L2_PIX_FMT_RGB24:
1084 case V4L2_PIX_FMT_RGB32: 1105 *f_even++ = LIMIT_RGB(r_);
1085 *f_even++ = LIMIT_RGB(b_); 1106 *f_even++ = LIMIT_RGB(g_);
1086 *f_even++ = LIMIT_RGB(g_); 1107 *f_even++ = LIMIT_RGB(b_);
1087 *f_even++ = LIMIT_RGB(r_); 1108 break;
1088 f_even++; 1109 case V4L2_PIX_FMT_RGB32:
1089 break; 1110 *f_even++ = LIMIT_RGB(r_);
1090 case V4L2_PIX_FMT_RGB555: 1111 *f_even++ = LIMIT_RGB(g_);
1091 g = LIMIT_RGB(g_); 1112 *f_even++ = LIMIT_RGB(b_);
1092 *f_even++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 2)); 1113 f_even++;
1093 *f_even++ = (0x03 & ( g >> 6)) | 1114 break;
1094 (0x7C & (LIMIT_RGB(r_) >> 1)); 1115 case V4L2_PIX_FMT_RGB555:
1095 break; 1116 g = LIMIT_RGB(g_);
1117 *f_even++ = (0x1F & LIMIT_RGB(r_)) |
1118 (0xE0 & (g << 5));
1119 *f_even++ = (0x03 & (g >> 3)) |
1120 (0x7C & (LIMIT_RGB(b_) << 2));
1121 break;
1096 } 1122 }
1097 } 1123 }
1098 clipmask_even_index += clipmask_add; 1124 clipmask_even_index += clipmask_add;
@@ -1110,28 +1136,33 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1110 r_ = (y_ + ur) >> 16; 1136 r_ = (y_ + ur) >> 16;
1111 1137
1112 switch (frame->v4l2_format.format) { 1138 switch (frame->v4l2_format.format) {
1113 case V4L2_PIX_FMT_RGB565: 1139 case V4L2_PIX_FMT_RGB565:
1114 g = LIMIT_RGB(g_); 1140 g = LIMIT_RGB(g_);
1115 *f_even++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 3)); 1141 *f_even++ =
1116 *f_even++ = (0x07 & ( g >> 5)) | (0xF8 & LIMIT_RGB(r_)); 1142 (0x1F & LIMIT_RGB(r_)) |
1117 break; 1143 (0xE0 & (g << 5));
1118 case V4L2_PIX_FMT_RGB24: 1144 *f_even++ =
1119 *f_even++ = LIMIT_RGB(b_); 1145 (0x07 & (g >> 3)) |
1120 *f_even++ = LIMIT_RGB(g_); 1146 (0xF8 & LIMIT_RGB(b_));
1121 *f_even++ = LIMIT_RGB(r_); 1147 break;
1122 break; 1148 case V4L2_PIX_FMT_RGB24:
1123 case V4L2_PIX_FMT_RGB32: 1149 *f_even++ = LIMIT_RGB(r_);
1124 *f_even++ = LIMIT_RGB(b_); 1150 *f_even++ = LIMIT_RGB(g_);
1125 *f_even++ = LIMIT_RGB(g_); 1151 *f_even++ = LIMIT_RGB(b_);
1126 *f_even++ = LIMIT_RGB(r_); 1152 break;
1127 f_even++; 1153 case V4L2_PIX_FMT_RGB32:
1128 break; 1154 *f_even++ = LIMIT_RGB(r_);
1129 case V4L2_PIX_FMT_RGB555: 1155 *f_even++ = LIMIT_RGB(g_);
1130 g = LIMIT_RGB(g_); 1156 *f_even++ = LIMIT_RGB(b_);
1131 *f_even++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 2)); 1157 f_even++;
1132 *f_even++ = (0x03 & ( g >> 6)) | 1158 break;
1133 (0x7C & (LIMIT_RGB(r_) >> 1)); 1159 case V4L2_PIX_FMT_RGB555:
1134 break; 1160 g = LIMIT_RGB(g_);
1161 *f_even++ = (0x1F & LIMIT_RGB(r_)) |
1162 (0xE0 & (g << 5));
1163 *f_even++ = (0x03 & (g >> 3)) |
1164 (0x7C & (LIMIT_RGB(b_) << 2));
1165 break;
1135 } 1166 }
1136 } 1167 }
1137 clipmask_even_index += clipmask_add; 1168 clipmask_even_index += clipmask_add;
@@ -1151,28 +1182,33 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1151 r_ = (y_ + ur) >> 16; 1182 r_ = (y_ + ur) >> 16;
1152 1183
1153 switch (frame->v4l2_format.format) { 1184 switch (frame->v4l2_format.format) {
1154 case V4L2_PIX_FMT_RGB565: 1185 case V4L2_PIX_FMT_RGB565:
1155 g = LIMIT_RGB(g_); 1186 g = LIMIT_RGB(g_);
1156 *f_odd++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 3)); 1187 *f_odd++ =
1157 *f_odd++ = (0x07 & ( g >> 5)) | (0xF8 & LIMIT_RGB(r_)); 1188 (0x1F & LIMIT_RGB(r_)) |
1158 break; 1189 (0xE0 & (g << 5));
1159 case V4L2_PIX_FMT_RGB24: 1190 *f_odd++ =
1160 *f_odd++ = LIMIT_RGB(b_); 1191 (0x07 & (g >> 3)) |
1161 *f_odd++ = LIMIT_RGB(g_); 1192 (0xF8 & LIMIT_RGB(b_));
1162 *f_odd++ = LIMIT_RGB(r_); 1193 break;
1163 break; 1194 case V4L2_PIX_FMT_RGB24:
1164 case V4L2_PIX_FMT_RGB32: 1195 *f_odd++ = LIMIT_RGB(r_);
1165 *f_odd++ = LIMIT_RGB(b_); 1196 *f_odd++ = LIMIT_RGB(g_);
1166 *f_odd++ = LIMIT_RGB(g_); 1197 *f_odd++ = LIMIT_RGB(b_);
1167 *f_odd++ = LIMIT_RGB(r_); 1198 break;
1168 f_odd++; 1199 case V4L2_PIX_FMT_RGB32:
1169 break; 1200 *f_odd++ = LIMIT_RGB(r_);
1170 case V4L2_PIX_FMT_RGB555: 1201 *f_odd++ = LIMIT_RGB(g_);
1171 g = LIMIT_RGB(g_); 1202 *f_odd++ = LIMIT_RGB(b_);
1172 *f_odd++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 2)); 1203 f_odd++;
1173 *f_odd++ = (0x03 & ( g >> 6)) | 1204 break;
1174 (0x7C & (LIMIT_RGB(r_) >> 1)); 1205 case V4L2_PIX_FMT_RGB555:
1175 break; 1206 g = LIMIT_RGB(g_);
1207 *f_odd++ = (0x1F & LIMIT_RGB(r_)) |
1208 (0xE0 & (g << 5));
1209 *f_odd++ = (0x03 & (g >> 3)) |
1210 (0x7C & (LIMIT_RGB(b_) << 2));
1211 break;
1176 } 1212 }
1177 } 1213 }
1178 clipmask_odd_index += clipmask_add; 1214 clipmask_odd_index += clipmask_add;
@@ -1190,28 +1226,33 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1190 r_ = (y_ + ur) >> 16; 1226 r_ = (y_ + ur) >> 16;
1191 1227
1192 switch (frame->v4l2_format.format) { 1228 switch (frame->v4l2_format.format) {
1193 case V4L2_PIX_FMT_RGB565: 1229 case V4L2_PIX_FMT_RGB565:
1194 g = LIMIT_RGB(g_); 1230 g = LIMIT_RGB(g_);
1195 *f_odd++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 3)); 1231 *f_odd++ =
1196 *f_odd++ = (0x07 & ( g >> 5)) | (0xF8 & LIMIT_RGB(r_)); 1232 (0x1F & LIMIT_RGB(r_)) |
1197 break; 1233 (0xE0 & (g << 5));
1198 case V4L2_PIX_FMT_RGB24: 1234 *f_odd++ =
1199 *f_odd++ = LIMIT_RGB(b_); 1235 (0x07 & (g >> 3)) |
1200 *f_odd++ = LIMIT_RGB(g_); 1236 (0xF8 & LIMIT_RGB(b_));
1201 *f_odd++ = LIMIT_RGB(r_); 1237 break;
1202 break; 1238 case V4L2_PIX_FMT_RGB24:
1203 case V4L2_PIX_FMT_RGB32: 1239 *f_odd++ = LIMIT_RGB(r_);
1204 *f_odd++ = LIMIT_RGB(b_); 1240 *f_odd++ = LIMIT_RGB(g_);
1205 *f_odd++ = LIMIT_RGB(g_); 1241 *f_odd++ = LIMIT_RGB(b_);
1206 *f_odd++ = LIMIT_RGB(r_); 1242 break;
1207 f_odd++; 1243 case V4L2_PIX_FMT_RGB32:
1208 break; 1244 *f_odd++ = LIMIT_RGB(r_);
1209 case V4L2_PIX_FMT_RGB555: 1245 *f_odd++ = LIMIT_RGB(g_);
1210 g = LIMIT_RGB(g_); 1246 *f_odd++ = LIMIT_RGB(b_);
1211 *f_odd++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 2)); 1247 f_odd++;
1212 *f_odd++ = (0x03 & ( g >> 6)) | 1248 break;
1213 (0x7C & (LIMIT_RGB(r_) >> 1)); 1249 case V4L2_PIX_FMT_RGB555:
1214 break; 1250 g = LIMIT_RGB(g_);
1251 *f_odd++ = (0x1F & LIMIT_RGB(r_)) |
1252 (0xE0 & (g << 5));
1253 *f_odd++ = (0x03 & (g >> 3)) |
1254 (0x7C & (LIMIT_RGB(b_) << 2));
1255 break;
1215 } 1256 }
1216 } 1257 }
1217 clipmask_odd_index += clipmask_add; 1258 clipmask_odd_index += clipmask_add;
@@ -1561,13 +1602,10 @@ static int usbvision_write_reg_irq(struct usb_usbvision *usbvision,int address,
1561 if (len > 8) { 1602 if (len > 8) {
1562 return -EFAULT; 1603 return -EFAULT;
1563 } 1604 }
1564// down(&usbvision->ctrlUrbLock);
1565 if (usbvision->ctrlUrbBusy) { 1605 if (usbvision->ctrlUrbBusy) {
1566// up(&usbvision->ctrlUrbLock);
1567 return -EBUSY; 1606 return -EBUSY;
1568 } 1607 }
1569 usbvision->ctrlUrbBusy = 1; 1608 usbvision->ctrlUrbBusy = 1;
1570// up(&usbvision->ctrlUrbLock);
1571 1609
1572 usbvision->ctrlUrbSetup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT; 1610 usbvision->ctrlUrbSetup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
1573 usbvision->ctrlUrbSetup.bRequest = USBVISION_OP_CODE; 1611 usbvision->ctrlUrbSetup.bRequest = USBVISION_OP_CODE;
@@ -2100,11 +2138,21 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
2100 value[5]=(usbvision_device_data[usbvision->DevModel].X_Offset & 0x0300) >> 8; 2138 value[5]=(usbvision_device_data[usbvision->DevModel].X_Offset & 0x0300) >> 8;
2101 } 2139 }
2102 2140
2141 if (adjust_X_Offset != -1) {
2142 value[4] = adjust_X_Offset & 0xff;
2143 value[5] = (adjust_X_Offset & 0x0300) >> 8;
2144 }
2145
2103 if (usbvision_device_data[usbvision->DevModel].Y_Offset >= 0) { 2146 if (usbvision_device_data[usbvision->DevModel].Y_Offset >= 0) {
2104 value[6]=usbvision_device_data[usbvision->DevModel].Y_Offset & 0xff; 2147 value[6]=usbvision_device_data[usbvision->DevModel].Y_Offset & 0xff;
2105 value[7]=(usbvision_device_data[usbvision->DevModel].Y_Offset & 0x0300) >> 8; 2148 value[7]=(usbvision_device_data[usbvision->DevModel].Y_Offset & 0x0300) >> 8;
2106 } 2149 }
2107 2150
2151 if (adjust_Y_Offset != -1) {
2152 value[6] = adjust_Y_Offset & 0xff;
2153 value[7] = (adjust_Y_Offset & 0x0300) >> 8;
2154 }
2155
2108 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 2156 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
2109 USBVISION_OP_CODE, /* USBVISION specific code */ 2157 USBVISION_OP_CODE, /* USBVISION specific code */
2110 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0, 2158 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0,
@@ -2242,14 +2290,18 @@ static void call_usbvision_power_off(struct work_struct *work)
2242 struct usb_usbvision *usbvision = container_of(work, struct usb_usbvision, powerOffWork); 2290 struct usb_usbvision *usbvision = container_of(work, struct usb_usbvision, powerOffWork);
2243 2291
2244 PDEBUG(DBG_FUNC, ""); 2292 PDEBUG(DBG_FUNC, "");
2245 down_interruptible(&usbvision->lock); 2293 if(mutex_lock_interruptible(&usbvision->lock)) {
2294 return;
2295 }
2296
2297
2246 if(usbvision->user == 0) { 2298 if(usbvision->user == 0) {
2247 usbvision_i2c_unregister(usbvision); 2299 usbvision_i2c_unregister(usbvision);
2248 2300
2249 usbvision_power_off(usbvision); 2301 usbvision_power_off(usbvision);
2250 usbvision->initialized = 0; 2302 usbvision->initialized = 0;
2251 } 2303 }
2252 up(&usbvision->lock); 2304 mutex_unlock(&usbvision->lock);
2253} 2305}
2254 2306
2255static void usbvision_powerOffTimer(unsigned long data) 2307static void usbvision_powerOffTimer(unsigned long data)
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 36e689fa16c0..b52b826a30be 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -410,7 +410,7 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
410 410
411 /* If so far no errors then we shall start the camera */ 411 /* If so far no errors then we shall start the camera */
412 if (!errCode) { 412 if (!errCode) {
413 down(&usbvision->lock); 413 mutex_lock(&usbvision->lock);
414 if (usbvision->power == 0) { 414 if (usbvision->power == 0) {
415 usbvision_power_on(usbvision); 415 usbvision_power_on(usbvision);
416 usbvision_i2c_register(usbvision); 416 usbvision_i2c_register(usbvision);
@@ -439,7 +439,7 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
439 usbvision->initialized = 0; 439 usbvision->initialized = 0;
440 } 440 }
441 } 441 }
442 up(&usbvision->lock); 442 mutex_unlock(&usbvision->lock);
443 } 443 }
444 444
445 if (errCode) { 445 if (errCode) {
@@ -467,7 +467,7 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
467 (struct usb_usbvision *) video_get_drvdata(dev); 467 (struct usb_usbvision *) video_get_drvdata(dev);
468 468
469 PDEBUG(DBG_IO, "close"); 469 PDEBUG(DBG_IO, "close");
470 down(&usbvision->lock); 470 mutex_lock(&usbvision->lock);
471 471
472 usbvision_audio_off(usbvision); 472 usbvision_audio_off(usbvision);
473 usbvision_restart_isoc(usbvision); 473 usbvision_restart_isoc(usbvision);
@@ -487,7 +487,7 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
487 usbvision->initialized = 0; 487 usbvision->initialized = 0;
488 } 488 }
489 489
490 up(&usbvision->lock); 490 mutex_unlock(&usbvision->lock);
491 491
492 if (usbvision->remove_pending) { 492 if (usbvision->remove_pending) {
493 printk(KERN_INFO "%s: Final disconnect\n", __FUNCTION__); 493 printk(KERN_INFO "%s: Final disconnect\n", __FUNCTION__);
@@ -647,13 +647,13 @@ static int vidioc_s_input (struct file *file, void *priv, unsigned int input)
647 if ((input >= usbvision->video_inputs) || (input < 0) ) 647 if ((input >= usbvision->video_inputs) || (input < 0) )
648 return -EINVAL; 648 return -EINVAL;
649 649
650 down(&usbvision->lock); 650 mutex_lock(&usbvision->lock);
651 usbvision_muxsel(usbvision, input); 651 usbvision_muxsel(usbvision, input);
652 usbvision_set_input(usbvision); 652 usbvision_set_input(usbvision);
653 usbvision_set_output(usbvision, 653 usbvision_set_output(usbvision,
654 usbvision->curwidth, 654 usbvision->curwidth,
655 usbvision->curheight); 655 usbvision->curheight);
656 up(&usbvision->lock); 656 mutex_unlock(&usbvision->lock);
657 return 0; 657 return 0;
658} 658}
659 659
@@ -664,10 +664,10 @@ static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id)
664 (struct usb_usbvision *) video_get_drvdata(dev); 664 (struct usb_usbvision *) video_get_drvdata(dev);
665 usbvision->tvnormId=*id; 665 usbvision->tvnormId=*id;
666 666
667 down(&usbvision->lock); 667 mutex_lock(&usbvision->lock);
668 call_i2c_clients(usbvision, VIDIOC_S_STD, 668 call_i2c_clients(usbvision, VIDIOC_S_STD,
669 &usbvision->tvnormId); 669 &usbvision->tvnormId);
670 up(&usbvision->lock); 670 mutex_unlock(&usbvision->lock);
671 /* propagate the change to the decoder */ 671 /* propagate the change to the decoder */
672 usbvision_muxsel(usbvision, usbvision->ctl_input); 672 usbvision_muxsel(usbvision, usbvision->ctl_input);
673 673
@@ -1083,9 +1083,9 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv,
1083 usbvision->curFrame = NULL; 1083 usbvision->curFrame = NULL;
1084 1084
1085 /* by now we are committed to the new data... */ 1085 /* by now we are committed to the new data... */
1086 down(&usbvision->lock); 1086 mutex_lock(&usbvision->lock);
1087 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height); 1087 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
1088 up(&usbvision->lock); 1088 mutex_unlock(&usbvision->lock);
1089 1089
1090 return 0; 1090 return 0;
1091} 1091}
@@ -1211,16 +1211,16 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1211 1211
1212 PDEBUG(DBG_MMAP, "mmap"); 1212 PDEBUG(DBG_MMAP, "mmap");
1213 1213
1214 down(&usbvision->lock); 1214 mutex_lock(&usbvision->lock);
1215 1215
1216 if (!USBVISION_IS_OPERATIONAL(usbvision)) { 1216 if (!USBVISION_IS_OPERATIONAL(usbvision)) {
1217 up(&usbvision->lock); 1217 mutex_unlock(&usbvision->lock);
1218 return -EFAULT; 1218 return -EFAULT;
1219 } 1219 }
1220 1220
1221 if (!(vma->vm_flags & VM_WRITE) || 1221 if (!(vma->vm_flags & VM_WRITE) ||
1222 size != PAGE_ALIGN(usbvision->max_frame_size)) { 1222 size != PAGE_ALIGN(usbvision->max_frame_size)) {
1223 up(&usbvision->lock); 1223 mutex_unlock(&usbvision->lock);
1224 return -EINVAL; 1224 return -EINVAL;
1225 } 1225 }
1226 1226
@@ -1232,7 +1232,7 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1232 if (i == usbvision->num_frames) { 1232 if (i == usbvision->num_frames) {
1233 PDEBUG(DBG_MMAP, 1233 PDEBUG(DBG_MMAP,
1234 "mmap: user supplied mapping address is out of range"); 1234 "mmap: user supplied mapping address is out of range");
1235 up(&usbvision->lock); 1235 mutex_unlock(&usbvision->lock);
1236 return -EINVAL; 1236 return -EINVAL;
1237 } 1237 }
1238 1238
@@ -1245,7 +1245,7 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1245 1245
1246 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { 1246 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
1247 PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed"); 1247 PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed");
1248 up(&usbvision->lock); 1248 mutex_unlock(&usbvision->lock);
1249 return -EAGAIN; 1249 return -EAGAIN;
1250 } 1250 }
1251 start += PAGE_SIZE; 1251 start += PAGE_SIZE;
@@ -1253,7 +1253,7 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1253 size -= PAGE_SIZE; 1253 size -= PAGE_SIZE;
1254 } 1254 }
1255 1255
1256 up(&usbvision->lock); 1256 mutex_unlock(&usbvision->lock);
1257 return 0; 1257 return 0;
1258} 1258}
1259 1259
@@ -1271,7 +1271,7 @@ static int usbvision_radio_open(struct inode *inode, struct file *file)
1271 1271
1272 PDEBUG(DBG_IO, "%s:", __FUNCTION__); 1272 PDEBUG(DBG_IO, "%s:", __FUNCTION__);
1273 1273
1274 down(&usbvision->lock); 1274 mutex_lock(&usbvision->lock);
1275 1275
1276 if (usbvision->user) { 1276 if (usbvision->user) {
1277 err("%s: Someone tried to open an already opened USBVision Radio!", __FUNCTION__); 1277 err("%s: Someone tried to open an already opened USBVision Radio!", __FUNCTION__);
@@ -1290,7 +1290,8 @@ static int usbvision_radio_open(struct inode *inode, struct file *file)
1290 errCode = usbvision_set_alternate(usbvision); 1290 errCode = usbvision_set_alternate(usbvision);
1291 if (errCode < 0) { 1291 if (errCode < 0) {
1292 usbvision->last_error = errCode; 1292 usbvision->last_error = errCode;
1293 return -EBUSY; 1293 errCode = -EBUSY;
1294 goto out;
1294 } 1295 }
1295 1296
1296 // If so far no errors then we shall start the radio 1297 // If so far no errors then we shall start the radio
@@ -1307,7 +1308,8 @@ static int usbvision_radio_open(struct inode *inode, struct file *file)
1307 usbvision->initialized = 0; 1308 usbvision->initialized = 0;
1308 } 1309 }
1309 } 1310 }
1310 up(&usbvision->lock); 1311out:
1312 mutex_unlock(&usbvision->lock);
1311 return errCode; 1313 return errCode;
1312} 1314}
1313 1315
@@ -1321,7 +1323,7 @@ static int usbvision_radio_close(struct inode *inode, struct file *file)
1321 1323
1322 PDEBUG(DBG_IO, ""); 1324 PDEBUG(DBG_IO, "");
1323 1325
1324 down(&usbvision->lock); 1326 mutex_lock(&usbvision->lock);
1325 1327
1326 /* Set packet size to 0 */ 1328 /* Set packet size to 0 */
1327 usbvision->ifaceAlt=0; 1329 usbvision->ifaceAlt=0;
@@ -1337,7 +1339,7 @@ static int usbvision_radio_close(struct inode *inode, struct file *file)
1337 usbvision->initialized = 0; 1339 usbvision->initialized = 0;
1338 } 1340 }
1339 1341
1340 up(&usbvision->lock); 1342 mutex_unlock(&usbvision->lock);
1341 1343
1342 if (usbvision->remove_pending) { 1344 if (usbvision->remove_pending) {
1343 printk(KERN_INFO "%s: Final disconnect\n", __FUNCTION__); 1345 printk(KERN_INFO "%s: Final disconnect\n", __FUNCTION__);
@@ -1641,7 +1643,7 @@ static struct usb_usbvision *usbvision_alloc(struct usb_device *dev)
1641 1643
1642 usbvision->dev = dev; 1644 usbvision->dev = dev;
1643 1645
1644 init_MUTEX(&usbvision->lock); /* to 1 == available */ 1646 mutex_init(&usbvision->lock); /* available */
1645 1647
1646 // prepare control urb for control messages during interrupts 1648 // prepare control urb for control messages during interrupts
1647 usbvision->ctrlUrb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); 1649 usbvision->ctrlUrb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
@@ -1649,7 +1651,6 @@ static struct usb_usbvision *usbvision_alloc(struct usb_device *dev)
1649 goto err_exit; 1651 goto err_exit;
1650 } 1652 }
1651 init_waitqueue_head(&usbvision->ctrlUrb_wq); 1653 init_waitqueue_head(&usbvision->ctrlUrb_wq);
1652 init_MUTEX(&usbvision->ctrlUrbLock); /* to 1 == available */
1653 1654
1654 usbvision_init_powerOffTimer(usbvision); 1655 usbvision_init_powerOffTimer(usbvision);
1655 1656
@@ -1676,13 +1677,13 @@ static void usbvision_release(struct usb_usbvision *usbvision)
1676{ 1677{
1677 PDEBUG(DBG_PROBE, ""); 1678 PDEBUG(DBG_PROBE, "");
1678 1679
1679 down(&usbvision->lock); 1680 mutex_lock(&usbvision->lock);
1680 1681
1681 usbvision_reset_powerOffTimer(usbvision); 1682 usbvision_reset_powerOffTimer(usbvision);
1682 1683
1683 usbvision->initialized = 0; 1684 usbvision->initialized = 0;
1684 1685
1685 up(&usbvision->lock); 1686 mutex_unlock(&usbvision->lock);
1686 1687
1687 usbvision_remove_sysfs(usbvision->vdev); 1688 usbvision_remove_sysfs(usbvision->vdev);
1688 usbvision_unregister_video(usbvision); 1689 usbvision_unregister_video(usbvision);
@@ -1796,7 +1797,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1796 } 1797 }
1797 PDEBUG(DBG_PROBE, "bridgeType %d", usbvision->bridgeType); 1798 PDEBUG(DBG_PROBE, "bridgeType %d", usbvision->bridgeType);
1798 1799
1799 down(&usbvision->lock); 1800 mutex_lock(&usbvision->lock);
1800 1801
1801 /* compute alternate max packet sizes */ 1802 /* compute alternate max packet sizes */
1802 uif = dev->actconfig->interface[0]; 1803 uif = dev->actconfig->interface[0];
@@ -1807,6 +1808,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1807 usbvision->num_alt,GFP_KERNEL); 1808 usbvision->num_alt,GFP_KERNEL);
1808 if (usbvision->alt_max_pkt_size == NULL) { 1809 if (usbvision->alt_max_pkt_size == NULL) {
1809 err("usbvision: out of memory!\n"); 1810 err("usbvision: out of memory!\n");
1811 mutex_unlock(&usbvision->lock);
1810 return -ENOMEM; 1812 return -ENOMEM;
1811 } 1813 }
1812 1814
@@ -1840,7 +1842,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1840 usbvision->streaming = Stream_Off; 1842 usbvision->streaming = Stream_Off;
1841 usbvision_register_video(usbvision); 1843 usbvision_register_video(usbvision);
1842 usbvision_configure_video(usbvision); 1844 usbvision_configure_video(usbvision);
1843 up(&usbvision->lock); 1845 mutex_unlock(&usbvision->lock);
1844 1846
1845 1847
1846 usb_set_intfdata (intf, usbvision); 1848 usb_set_intfdata (intf, usbvision);
@@ -1871,7 +1873,7 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1871 } 1873 }
1872 usb_set_intfdata (intf, NULL); 1874 usb_set_intfdata (intf, NULL);
1873 1875
1874 down(&usbvision->lock); 1876 mutex_lock(&usbvision->lock);
1875 1877
1876 // At this time we ask to cancel outstanding URBs 1878 // At this time we ask to cancel outstanding URBs
1877 usbvision_stop_isoc(usbvision); 1879 usbvision_stop_isoc(usbvision);
@@ -1885,7 +1887,7 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1885 usb_put_dev(usbvision->dev); 1887 usb_put_dev(usbvision->dev);
1886 usbvision->dev = NULL; // USB device is no more 1888 usbvision->dev = NULL; // USB device is no more
1887 1889
1888 up(&usbvision->lock); 1890 mutex_unlock(&usbvision->lock);
1889 1891
1890 if (usbvision->user) { 1892 if (usbvision->user) {
1891 printk(KERN_INFO "%s: In use, disconnect pending\n", 1893 printk(KERN_INFO "%s: In use, disconnect pending\n",
diff --git a/drivers/media/video/usbvision/usbvision.h b/drivers/media/video/usbvision/usbvision.h
index c5b6c501c869..20d7ec624999 100644
--- a/drivers/media/video/usbvision/usbvision.h
+++ b/drivers/media/video/usbvision/usbvision.h
@@ -34,16 +34,13 @@
34#include <linux/list.h> 34#include <linux/list.h>
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/mutex.h>
37#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
38#include <media/tuner.h> 39#include <media/tuner.h>
39#include <linux/videodev2.h> 40#include <linux/videodev2.h>
40 41
41#define USBVISION_DEBUG /* Turn on debug messages */ 42#define USBVISION_DEBUG /* Turn on debug messages */
42 43
43#ifndef VID_HARDWARE_USBVISION
44 #define VID_HARDWARE_USBVISION 34 /* USBVision Video Grabber */
45#endif
46
47#define USBVISION_PWR_REG 0x00 44#define USBVISION_PWR_REG 0x00
48 #define USBVISION_SSPND_EN (1 << 1) 45 #define USBVISION_SSPND_EN (1 << 1)
49 #define USBVISION_RES2 (1 << 2) 46 #define USBVISION_RES2 (1 << 2)
@@ -373,7 +370,6 @@ struct usb_usbvision {
373 int ctrlUrbBusy; 370 int ctrlUrbBusy;
374 struct usb_ctrlrequest ctrlUrbSetup; 371 struct usb_ctrlrequest ctrlUrbSetup;
375 wait_queue_head_t ctrlUrb_wq; // Processes waiting 372 wait_queue_head_t ctrlUrb_wq; // Processes waiting
376 struct semaphore ctrlUrbLock;
377 373
378 /* configuration part */ 374 /* configuration part */
379 int have_tuner; 375 int have_tuner;
@@ -396,7 +392,7 @@ struct usb_usbvision {
396 unsigned char iface; /* Video interface number */ 392 unsigned char iface; /* Video interface number */
397 unsigned char ifaceAlt; /* Alt settings */ 393 unsigned char ifaceAlt; /* Alt settings */
398 unsigned char Vin_Reg2_Preset; 394 unsigned char Vin_Reg2_Preset;
399 struct semaphore lock; 395 struct mutex lock;
400 struct timer_list powerOffTimer; 396 struct timer_list powerOffTimer;
401 struct work_struct powerOffWork; 397 struct work_struct powerOffWork;
402 int power; /* is the device powered on? */ 398 int power; /* is the device powered on? */
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 1141b4bf41ce..c056ff6d810c 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -400,7 +400,7 @@ static const char *v4l2_int_ioctls[] = {
400 400
401 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR", 401 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
402 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY", 402 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
403 [_IOC_NR(TDA9887_SET_CONFIG)] = "TDA9887_SET_CONFIG", 403 [_IOC_NR(TUNER_SET_CONFIG)] = "TUNER_SET_CONFIG",
404 404
405 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE", 405 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
406 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET", 406 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
@@ -1013,6 +1013,34 @@ int v4l2_chip_match_host(u32 match_type, u32 match_chip)
1013 1013
1014/* ----------------------------------------------------------------- */ 1014/* ----------------------------------------------------------------- */
1015 1015
1016/* Helper function for I2C legacy drivers */
1017
1018int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver,
1019 const char *name, int (*probe)(struct i2c_client *))
1020{
1021 struct i2c_client *client;
1022 int err;
1023
1024 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
1025 if (client == 0)
1026 return -ENOMEM;
1027
1028 client->addr = address;
1029 client->adapter = adapter;
1030 client->driver = driver;
1031 strlcpy(client->name, name, sizeof(client->name));
1032
1033 err = probe(client);
1034 if (err == 0) {
1035 i2c_attach_client(client);
1036 } else {
1037 kfree(client);
1038 }
1039 return err != -ENOMEM ? 0 : err;
1040}
1041
1042/* ----------------------------------------------------------------- */
1043
1016EXPORT_SYMBOL(v4l2_norm_to_name); 1044EXPORT_SYMBOL(v4l2_norm_to_name);
1017EXPORT_SYMBOL(v4l2_video_std_construct); 1045EXPORT_SYMBOL(v4l2_video_std_construct);
1018 1046
@@ -1038,6 +1066,8 @@ EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
1038EXPORT_SYMBOL(v4l2_chip_ident_i2c_client); 1066EXPORT_SYMBOL(v4l2_chip_ident_i2c_client);
1039EXPORT_SYMBOL(v4l2_chip_match_host); 1067EXPORT_SYMBOL(v4l2_chip_match_host);
1040 1068
1069EXPORT_SYMBOL(v4l2_i2c_attach);
1070
1041/* 1071/*
1042 * Local variables: 1072 * Local variables:
1043 * c-basic-offset: 8 1073 * c-basic-offset: 8
diff --git a/drivers/media/video/v4l2-int-device.c b/drivers/media/video/v4l2-int-device.c
index 8b4ef530a3a8..a545dcaf857f 100644
--- a/drivers/media/video/v4l2-int-device.c
+++ b/drivers/media/video/v4l2-int-device.c
@@ -57,12 +57,12 @@ static void v4l2_int_device_try_attach_all(void)
57 if (!try_module_get(m->module)) 57 if (!try_module_get(m->module))
58 continue; 58 continue;
59 59
60 if (m->u.master->attach(m, s)) { 60 s->u.slave->master = m;
61 if (m->u.master->attach(s)) {
62 s->u.slave->master = NULL;
61 module_put(m->module); 63 module_put(m->module);
62 continue; 64 continue;
63 } 65 }
64
65 s->u.slave->master = m;
66 } 66 }
67 } 67 }
68} 68}
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
index c8a5cb57963b..80a14da9acef 100644
--- a/drivers/media/video/videobuf-core.c
+++ b/drivers/media/video/videobuf-core.c
@@ -22,29 +22,32 @@
22#include <media/videobuf-core.h> 22#include <media/videobuf-core.h>
23 23
24#define MAGIC_BUFFER 0x20070728 24#define MAGIC_BUFFER 0x20070728
25#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \ 25#define MAGIC_CHECK(is, should) do { \
26 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); } 26 if (unlikely((is) != (should))) { \
27 printk(KERN_ERR "magic mismatch: %x (expected %x)\n", is, should); \
28 BUG(); } } while (0)
27 29
28static int debug = 0; 30static int debug;
29module_param(debug, int, 0644); 31module_param(debug, int, 0644);
30 32
31MODULE_DESCRIPTION("helper module to manage video4linux buffers"); 33MODULE_DESCRIPTION("helper module to manage video4linux buffers");
32MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 34MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
33MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
34 36
35#define dprintk(level, fmt, arg...) if (debug >= level) \ 37#define dprintk(level, fmt, arg...) do { \
36 printk(KERN_DEBUG "vbuf: " fmt , ## arg) 38 if (debug >= level) \
39 printk(KERN_DEBUG "vbuf: " fmt , ## arg); } while (0)
37 40
38/* --------------------------------------------------------------------- */ 41/* --------------------------------------------------------------------- */
39 42
40#define CALL(q, f, arg...) \ 43#define CALL(q, f, arg...) \
41 ( (q->int_ops->f)? q->int_ops->f(arg) : 0) 44 ((q->int_ops->f) ? q->int_ops->f(arg) : 0)
42 45
43void* videobuf_alloc(struct videobuf_queue* q) 46void *videobuf_alloc(struct videobuf_queue *q)
44{ 47{
45 struct videobuf_buffer *vb; 48 struct videobuf_buffer *vb;
46 49
47 BUG_ON (q->msize<sizeof(*vb)); 50 BUG_ON(q->msize < sizeof(*vb));
48 51
49 if (!q->int_ops || !q->int_ops->alloc) { 52 if (!q->int_ops || !q->int_ops->alloc) {
50 printk(KERN_ERR "No specific ops defined!\n"); 53 printk(KERN_ERR "No specific ops defined!\n");
@@ -66,20 +69,21 @@ int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
66 int retval = 0; 69 int retval = 0;
67 DECLARE_WAITQUEUE(wait, current); 70 DECLARE_WAITQUEUE(wait, current);
68 71
69 MAGIC_CHECK(vb->magic,MAGIC_BUFFER); 72 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
70 add_wait_queue(&vb->done, &wait); 73 add_wait_queue(&vb->done, &wait);
71 while (vb->state == STATE_ACTIVE || vb->state == STATE_QUEUED) { 74 while (vb->state == VIDEOBUF_ACTIVE || vb->state == VIDEOBUF_QUEUED) {
72 if (non_blocking) { 75 if (non_blocking) {
73 retval = -EAGAIN; 76 retval = -EAGAIN;
74 break; 77 break;
75 } 78 }
76 set_current_state(intr ? TASK_INTERRUPTIBLE 79 set_current_state(intr ? TASK_INTERRUPTIBLE
77 : TASK_UNINTERRUPTIBLE); 80 : TASK_UNINTERRUPTIBLE);
78 if (vb->state == STATE_ACTIVE || vb->state == STATE_QUEUED) 81 if (vb->state == VIDEOBUF_ACTIVE ||
82 vb->state == VIDEOBUF_QUEUED)
79 schedule(); 83 schedule();
80 set_current_state(TASK_RUNNING); 84 set_current_state(TASK_RUNNING);
81 if (intr && signal_pending(current)) { 85 if (intr && signal_pending(current)) {
82 dprintk(1,"buffer waiton: -EINTR\n"); 86 dprintk(1, "buffer waiton: -EINTR\n");
83 retval = -EINTR; 87 retval = -EINTR;
84 break; 88 break;
85 } 89 }
@@ -88,27 +92,33 @@ int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
88 return retval; 92 return retval;
89} 93}
90 94
91int videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb, 95int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
92 struct v4l2_framebuffer *fbuf) 96 struct v4l2_framebuffer *fbuf)
93{ 97{
94 MAGIC_CHECK(vb->magic,MAGIC_BUFFER); 98 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
95 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 99 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
96 100
97 /* FIXME: This is required to avoid OOPS on some cases, since mmap_mapper() 101 /* This is required to avoid OOPS on some cases,
98 method should be called before _iolock. 102 since mmap_mapper() method should be called before _iolock.
99 On some cases, the mmap_mapper() is called only after scheduling. 103 On some cases, the mmap_mapper() is called only after scheduling.
100
101 However, this way is just too dirty! Better to wait for some event.
102 */ 104 */
103 schedule_timeout(HZ); 105 if (vb->memory == V4L2_MEMORY_MMAP) {
106 wait_event_timeout(vb->done, q->is_mmapped,
107 msecs_to_jiffies(100));
108 if (!q->is_mmapped) {
109 printk(KERN_ERR
110 "Error: mmap_mapper() never called!\n");
111 return -EINVAL;
112 }
113 }
104 114
105 return CALL(q,iolock,q,vb,fbuf); 115 return CALL(q, iolock, q, vb, fbuf);
106} 116}
107 117
108/* --------------------------------------------------------------------- */ 118/* --------------------------------------------------------------------- */
109 119
110 120
111void videobuf_queue_core_init(struct videobuf_queue* q, 121void videobuf_queue_core_init(struct videobuf_queue *q,
112 struct videobuf_queue_ops *ops, 122 struct videobuf_queue_ops *ops,
113 void *dev, 123 void *dev,
114 spinlock_t *irqlock, 124 spinlock_t *irqlock,
@@ -118,7 +128,7 @@ void videobuf_queue_core_init(struct videobuf_queue* q,
118 void *priv, 128 void *priv,
119 struct videobuf_qtype_ops *int_ops) 129 struct videobuf_qtype_ops *int_ops)
120{ 130{
121 memset(q,0,sizeof(*q)); 131 memset(q, 0, sizeof(*q));
122 q->irqlock = irqlock; 132 q->irqlock = irqlock;
123 q->dev = dev; 133 q->dev = dev;
124 q->type = type; 134 q->type = type;
@@ -129,13 +139,13 @@ void videobuf_queue_core_init(struct videobuf_queue* q,
129 q->int_ops = int_ops; 139 q->int_ops = int_ops;
130 140
131 /* All buffer operations are mandatory */ 141 /* All buffer operations are mandatory */
132 BUG_ON (!q->ops->buf_setup); 142 BUG_ON(!q->ops->buf_setup);
133 BUG_ON (!q->ops->buf_prepare); 143 BUG_ON(!q->ops->buf_prepare);
134 BUG_ON (!q->ops->buf_queue); 144 BUG_ON(!q->ops->buf_queue);
135 BUG_ON (!q->ops->buf_release); 145 BUG_ON(!q->ops->buf_release);
136 146
137 /* Having implementations for abstract methods are mandatory */ 147 /* Having implementations for abstract methods are mandatory */
138 BUG_ON (!q->int_ops); 148 BUG_ON(!q->int_ops);
139 149
140 mutex_init(&q->lock); 150 mutex_init(&q->lock);
141 INIT_LIST_HEAD(&q->stream); 151 INIT_LIST_HEAD(&q->stream);
@@ -146,33 +156,33 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
146{ 156{
147 int i; 157 int i;
148 158
149 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 159 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
150 160
151 if (q->streaming) { 161 if (q->streaming) {
152 dprintk(1,"busy: streaming active\n"); 162 dprintk(1, "busy: streaming active\n");
153 return 1; 163 return 1;
154 } 164 }
155 if (q->reading) { 165 if (q->reading) {
156 dprintk(1,"busy: pending read #1\n"); 166 dprintk(1, "busy: pending read #1\n");
157 return 1; 167 return 1;
158 } 168 }
159 if (q->read_buf) { 169 if (q->read_buf) {
160 dprintk(1,"busy: pending read #2\n"); 170 dprintk(1, "busy: pending read #2\n");
161 return 1; 171 return 1;
162 } 172 }
163 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 173 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
164 if (NULL == q->bufs[i]) 174 if (NULL == q->bufs[i])
165 continue; 175 continue;
166 if (q->bufs[i]->map) { 176 if (q->bufs[i]->map) {
167 dprintk(1,"busy: buffer #%d mapped\n",i); 177 dprintk(1, "busy: buffer #%d mapped\n", i);
168 return 1; 178 return 1;
169 } 179 }
170 if (q->bufs[i]->state == STATE_QUEUED) { 180 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
171 dprintk(1,"busy: buffer #%d queued\n",i); 181 dprintk(1, "busy: buffer #%d queued\n", i);
172 return 1; 182 return 1;
173 } 183 }
174 if (q->bufs[i]->state == STATE_ACTIVE) { 184 if (q->bufs[i]->state == VIDEOBUF_ACTIVE) {
175 dprintk(1,"busy: buffer #%d avtive\n",i); 185 dprintk(1, "busy: buffer #%d avtive\n", i);
176 return 1; 186 return 1;
177 } 187 }
178 } 188 }
@@ -182,28 +192,28 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
182/* Locking: Caller holds q->lock */ 192/* Locking: Caller holds q->lock */
183void videobuf_queue_cancel(struct videobuf_queue *q) 193void videobuf_queue_cancel(struct videobuf_queue *q)
184{ 194{
185 unsigned long flags=0; 195 unsigned long flags = 0;
186 int i; 196 int i;
187 197
188 /* remove queued buffers from list */ 198 /* remove queued buffers from list */
189 if (q->irqlock) 199 if (q->irqlock)
190 spin_lock_irqsave(q->irqlock,flags); 200 spin_lock_irqsave(q->irqlock, flags);
191 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 201 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
192 if (NULL == q->bufs[i]) 202 if (NULL == q->bufs[i])
193 continue; 203 continue;
194 if (q->bufs[i]->state == STATE_QUEUED) { 204 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
195 list_del(&q->bufs[i]->queue); 205 list_del(&q->bufs[i]->queue);
196 q->bufs[i]->state = STATE_ERROR; 206 q->bufs[i]->state = VIDEOBUF_ERROR;
197 } 207 }
198 } 208 }
199 if (q->irqlock) 209 if (q->irqlock)
200 spin_unlock_irqrestore(q->irqlock,flags); 210 spin_unlock_irqrestore(q->irqlock, flags);
201 211
202 /* free all buffers + clear queue */ 212 /* free all buffers + clear queue */
203 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 213 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
204 if (NULL == q->bufs[i]) 214 if (NULL == q->bufs[i])
205 continue; 215 continue;
206 q->ops->buf_release(q,q->bufs[i]); 216 q->ops->buf_release(q, q->bufs[i]);
207 } 217 }
208 INIT_LIST_HEAD(&q->stream); 218 INIT_LIST_HEAD(&q->stream);
209} 219}
@@ -233,8 +243,8 @@ enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
233static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b, 243static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
234 struct videobuf_buffer *vb, enum v4l2_buf_type type) 244 struct videobuf_buffer *vb, enum v4l2_buf_type type)
235{ 245{
236 MAGIC_CHECK(vb->magic,MAGIC_BUFFER); 246 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
237 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 247 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
238 248
239 b->index = vb->i; 249 b->index = vb->i;
240 b->type = type; 250 b->type = type;
@@ -259,17 +269,17 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
259 b->flags |= V4L2_BUF_FLAG_MAPPED; 269 b->flags |= V4L2_BUF_FLAG_MAPPED;
260 270
261 switch (vb->state) { 271 switch (vb->state) {
262 case STATE_PREPARED: 272 case VIDEOBUF_PREPARED:
263 case STATE_QUEUED: 273 case VIDEOBUF_QUEUED:
264 case STATE_ACTIVE: 274 case VIDEOBUF_ACTIVE:
265 b->flags |= V4L2_BUF_FLAG_QUEUED; 275 b->flags |= V4L2_BUF_FLAG_QUEUED;
266 break; 276 break;
267 case STATE_DONE: 277 case VIDEOBUF_DONE:
268 case STATE_ERROR: 278 case VIDEOBUF_ERROR:
269 b->flags |= V4L2_BUF_FLAG_DONE; 279 b->flags |= V4L2_BUF_FLAG_DONE;
270 break; 280 break;
271 case STATE_NEEDS_INIT: 281 case VIDEOBUF_NEEDS_INIT:
272 case STATE_IDLE: 282 case VIDEOBUF_IDLE:
273 /* nothing */ 283 /* nothing */
274 break; 284 break;
275 } 285 }
@@ -294,16 +304,20 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
294 if (!q) 304 if (!q)
295 return 0; 305 return 0;
296 306
297 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 307 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
308
309
310 rc = CALL(q, mmap_free, q);
311
312 q->is_mmapped = 0;
298 313
299 rc = CALL(q,mmap_free,q); 314 if (rc < 0)
300 if (rc<0)
301 return rc; 315 return rc;
302 316
303 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 317 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
304 if (NULL == q->bufs[i]) 318 if (NULL == q->bufs[i])
305 continue; 319 continue;
306 q->ops->buf_release(q,q->bufs[i]); 320 q->ops->buf_release(q, q->bufs[i]);
307 kfree(q->bufs[i]); 321 kfree(q->bufs[i]);
308 q->bufs[i] = NULL; 322 q->bufs[i] = NULL;
309 } 323 }
@@ -328,7 +342,7 @@ static int __videobuf_mmap_setup(struct videobuf_queue *q,
328 unsigned int i; 342 unsigned int i;
329 int err; 343 int err;
330 344
331 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 345 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
332 346
333 err = __videobuf_mmap_free(q); 347 err = __videobuf_mmap_free(q);
334 if (0 != err) 348 if (0 != err)
@@ -359,7 +373,7 @@ static int __videobuf_mmap_setup(struct videobuf_queue *q,
359 if (!i) 373 if (!i)
360 return -ENOMEM; 374 return -ENOMEM;
361 375
362 dprintk(1,"mmap setup: %d buffers, %d bytes each\n", 376 dprintk(1, "mmap setup: %d buffers, %d bytes each\n",
363 i, bsize); 377 i, bsize);
364 378
365 return i; 379 return i;
@@ -379,35 +393,35 @@ int videobuf_mmap_setup(struct videobuf_queue *q,
379int videobuf_reqbufs(struct videobuf_queue *q, 393int videobuf_reqbufs(struct videobuf_queue *q,
380 struct v4l2_requestbuffers *req) 394 struct v4l2_requestbuffers *req)
381{ 395{
382 unsigned int size,count; 396 unsigned int size, count;
383 int retval; 397 int retval;
384 398
385 if (req->count < 1) { 399 if (req->count < 1) {
386 dprintk(1,"reqbufs: count invalid (%d)\n",req->count); 400 dprintk(1, "reqbufs: count invalid (%d)\n", req->count);
387 return -EINVAL; 401 return -EINVAL;
388 } 402 }
389 403
390 if (req->memory != V4L2_MEMORY_MMAP && 404 if (req->memory != V4L2_MEMORY_MMAP &&
391 req->memory != V4L2_MEMORY_USERPTR && 405 req->memory != V4L2_MEMORY_USERPTR &&
392 req->memory != V4L2_MEMORY_OVERLAY) { 406 req->memory != V4L2_MEMORY_OVERLAY) {
393 dprintk(1,"reqbufs: memory type invalid\n"); 407 dprintk(1, "reqbufs: memory type invalid\n");
394 return -EINVAL; 408 return -EINVAL;
395 } 409 }
396 410
397 mutex_lock(&q->lock); 411 mutex_lock(&q->lock);
398 if (req->type != q->type) { 412 if (req->type != q->type) {
399 dprintk(1,"reqbufs: queue type invalid\n"); 413 dprintk(1, "reqbufs: queue type invalid\n");
400 retval = -EINVAL; 414 retval = -EINVAL;
401 goto done; 415 goto done;
402 } 416 }
403 417
404 if (q->streaming) { 418 if (q->streaming) {
405 dprintk(1,"reqbufs: streaming already exists\n"); 419 dprintk(1, "reqbufs: streaming already exists\n");
406 retval = -EBUSY; 420 retval = -EBUSY;
407 goto done; 421 goto done;
408 } 422 }
409 if (!list_empty(&q->stream)) { 423 if (!list_empty(&q->stream)) {
410 dprintk(1,"reqbufs: stream running\n"); 424 dprintk(1, "reqbufs: stream running\n");
411 retval = -EBUSY; 425 retval = -EBUSY;
412 goto done; 426 goto done;
413 } 427 }
@@ -416,14 +430,14 @@ int videobuf_reqbufs(struct videobuf_queue *q,
416 if (count > VIDEO_MAX_FRAME) 430 if (count > VIDEO_MAX_FRAME)
417 count = VIDEO_MAX_FRAME; 431 count = VIDEO_MAX_FRAME;
418 size = 0; 432 size = 0;
419 q->ops->buf_setup(q,&count,&size); 433 q->ops->buf_setup(q, &count, &size);
420 size = PAGE_ALIGN(size); 434 size = PAGE_ALIGN(size);
421 dprintk(1,"reqbufs: bufs=%d, size=0x%x [%d pages total]\n", 435 dprintk(1, "reqbufs: bufs=%d, size=0x%x [%d pages total]\n",
422 count, size, (count*size)>>PAGE_SHIFT); 436 count, size, (count*size)>>PAGE_SHIFT);
423 437
424 retval = __videobuf_mmap_setup(q,count,size,req->memory); 438 retval = __videobuf_mmap_setup(q, count, size, req->memory);
425 if (retval < 0) { 439 if (retval < 0) {
426 dprintk(1,"reqbufs: mmap setup returned %d\n",retval); 440 dprintk(1, "reqbufs: mmap setup returned %d\n", retval);
427 goto done; 441 goto done;
428 } 442 }
429 443
@@ -440,19 +454,19 @@ int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
440 454
441 mutex_lock(&q->lock); 455 mutex_lock(&q->lock);
442 if (unlikely(b->type != q->type)) { 456 if (unlikely(b->type != q->type)) {
443 dprintk(1,"querybuf: Wrong type.\n"); 457 dprintk(1, "querybuf: Wrong type.\n");
444 goto done; 458 goto done;
445 } 459 }
446 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) { 460 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) {
447 dprintk(1,"querybuf: index out of range.\n"); 461 dprintk(1, "querybuf: index out of range.\n");
448 goto done; 462 goto done;
449 } 463 }
450 if (unlikely(NULL == q->bufs[b->index])) { 464 if (unlikely(NULL == q->bufs[b->index])) {
451 dprintk(1,"querybuf: buffer is null.\n"); 465 dprintk(1, "querybuf: buffer is null.\n");
452 goto done; 466 goto done;
453 } 467 }
454 468
455 videobuf_status(q,b,q->bufs[b->index],q->type); 469 videobuf_status(q, b, q->bufs[b->index], q->type);
456 470
457 ret = 0; 471 ret = 0;
458done: 472done:
@@ -465,10 +479,10 @@ int videobuf_qbuf(struct videobuf_queue *q,
465{ 479{
466 struct videobuf_buffer *buf; 480 struct videobuf_buffer *buf;
467 enum v4l2_field field; 481 enum v4l2_field field;
468 unsigned long flags=0; 482 unsigned long flags = 0;
469 int retval; 483 int retval;
470 484
471 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 485 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
472 486
473 if (b->memory == V4L2_MEMORY_MMAP) 487 if (b->memory == V4L2_MEMORY_MMAP)
474 down_read(&current->mm->mmap_sem); 488 down_read(&current->mm->mmap_sem);
@@ -476,36 +490,36 @@ int videobuf_qbuf(struct videobuf_queue *q,
476 mutex_lock(&q->lock); 490 mutex_lock(&q->lock);
477 retval = -EBUSY; 491 retval = -EBUSY;
478 if (q->reading) { 492 if (q->reading) {
479 dprintk(1,"qbuf: Reading running...\n"); 493 dprintk(1, "qbuf: Reading running...\n");
480 goto done; 494 goto done;
481 } 495 }
482 retval = -EINVAL; 496 retval = -EINVAL;
483 if (b->type != q->type) { 497 if (b->type != q->type) {
484 dprintk(1,"qbuf: Wrong type.\n"); 498 dprintk(1, "qbuf: Wrong type.\n");
485 goto done; 499 goto done;
486 } 500 }
487 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) { 501 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) {
488 dprintk(1,"qbuf: index out of range.\n"); 502 dprintk(1, "qbuf: index out of range.\n");
489 goto done; 503 goto done;
490 } 504 }
491 buf = q->bufs[b->index]; 505 buf = q->bufs[b->index];
492 if (NULL == buf) { 506 if (NULL == buf) {
493 dprintk(1,"qbuf: buffer is null.\n"); 507 dprintk(1, "qbuf: buffer is null.\n");
494 goto done; 508 goto done;
495 } 509 }
496 MAGIC_CHECK(buf->magic,MAGIC_BUFFER); 510 MAGIC_CHECK(buf->magic, MAGIC_BUFFER);
497 if (buf->memory != b->memory) { 511 if (buf->memory != b->memory) {
498 dprintk(1,"qbuf: memory type is wrong.\n"); 512 dprintk(1, "qbuf: memory type is wrong.\n");
499 goto done; 513 goto done;
500 } 514 }
501 if (buf->state != STATE_NEEDS_INIT && buf->state != STATE_IDLE) { 515 if (buf->state != VIDEOBUF_NEEDS_INIT && buf->state != VIDEOBUF_IDLE) {
502 dprintk(1,"qbuf: buffer is already queued or active.\n"); 516 dprintk(1, "qbuf: buffer is already queued or active.\n");
503 goto done; 517 goto done;
504 } 518 }
505 519
506 if (b->flags & V4L2_BUF_FLAG_INPUT) { 520 if (b->flags & V4L2_BUF_FLAG_INPUT) {
507 if (b->input >= q->inputs) { 521 if (b->input >= q->inputs) {
508 dprintk(1,"qbuf: wrong input.\n"); 522 dprintk(1, "qbuf: wrong input.\n");
509 goto done; 523 goto done;
510 } 524 }
511 buf->input = b->input; 525 buf->input = b->input;
@@ -516,44 +530,46 @@ int videobuf_qbuf(struct videobuf_queue *q,
516 switch (b->memory) { 530 switch (b->memory) {
517 case V4L2_MEMORY_MMAP: 531 case V4L2_MEMORY_MMAP:
518 if (0 == buf->baddr) { 532 if (0 == buf->baddr) {
519 dprintk(1,"qbuf: mmap requested but buffer addr is zero!\n"); 533 dprintk(1, "qbuf: mmap requested "
534 "but buffer addr is zero!\n");
520 goto done; 535 goto done;
521 } 536 }
522 break; 537 break;
523 case V4L2_MEMORY_USERPTR: 538 case V4L2_MEMORY_USERPTR:
524 if (b->length < buf->bsize) { 539 if (b->length < buf->bsize) {
525 dprintk(1,"qbuf: buffer length is not enough\n"); 540 dprintk(1, "qbuf: buffer length is not enough\n");
526 goto done; 541 goto done;
527 } 542 }
528 if (STATE_NEEDS_INIT != buf->state && buf->baddr != b->m.userptr) 543 if (VIDEOBUF_NEEDS_INIT != buf->state &&
529 q->ops->buf_release(q,buf); 544 buf->baddr != b->m.userptr)
545 q->ops->buf_release(q, buf);
530 buf->baddr = b->m.userptr; 546 buf->baddr = b->m.userptr;
531 break; 547 break;
532 case V4L2_MEMORY_OVERLAY: 548 case V4L2_MEMORY_OVERLAY:
533 buf->boff = b->m.offset; 549 buf->boff = b->m.offset;
534 break; 550 break;
535 default: 551 default:
536 dprintk(1,"qbuf: wrong memory type\n"); 552 dprintk(1, "qbuf: wrong memory type\n");
537 goto done; 553 goto done;
538 } 554 }
539 555
540 dprintk(1,"qbuf: requesting next field\n"); 556 dprintk(1, "qbuf: requesting next field\n");
541 field = videobuf_next_field(q); 557 field = videobuf_next_field(q);
542 retval = q->ops->buf_prepare(q,buf,field); 558 retval = q->ops->buf_prepare(q, buf, field);
543 if (0 != retval) { 559 if (0 != retval) {
544 dprintk(1,"qbuf: buffer_prepare returned %d\n",retval); 560 dprintk(1, "qbuf: buffer_prepare returned %d\n", retval);
545 goto done; 561 goto done;
546 } 562 }
547 563
548 list_add_tail(&buf->stream,&q->stream); 564 list_add_tail(&buf->stream, &q->stream);
549 if (q->streaming) { 565 if (q->streaming) {
550 if (q->irqlock) 566 if (q->irqlock)
551 spin_lock_irqsave(q->irqlock,flags); 567 spin_lock_irqsave(q->irqlock, flags);
552 q->ops->buf_queue(q,buf); 568 q->ops->buf_queue(q, buf);
553 if (q->irqlock) 569 if (q->irqlock)
554 spin_unlock_irqrestore(q->irqlock,flags); 570 spin_unlock_irqrestore(q->irqlock, flags);
555 } 571 }
556 dprintk(1,"qbuf: succeded\n"); 572 dprintk(1, "qbuf: succeded\n");
557 retval = 0; 573 retval = 0;
558 574
559 done: 575 done:
@@ -571,49 +587,49 @@ int videobuf_dqbuf(struct videobuf_queue *q,
571 struct videobuf_buffer *buf; 587 struct videobuf_buffer *buf;
572 int retval; 588 int retval;
573 589
574 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 590 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
575 591
576 mutex_lock(&q->lock); 592 mutex_lock(&q->lock);
577 retval = -EBUSY; 593 retval = -EBUSY;
578 if (q->reading) { 594 if (q->reading) {
579 dprintk(1,"dqbuf: Reading running...\n"); 595 dprintk(1, "dqbuf: Reading running...\n");
580 goto done; 596 goto done;
581 } 597 }
582 retval = -EINVAL; 598 retval = -EINVAL;
583 if (b->type != q->type) { 599 if (b->type != q->type) {
584 dprintk(1,"dqbuf: Wrong type.\n"); 600 dprintk(1, "dqbuf: Wrong type.\n");
585 goto done; 601 goto done;
586 } 602 }
587 if (list_empty(&q->stream)) { 603 if (list_empty(&q->stream)) {
588 dprintk(1,"dqbuf: stream running\n"); 604 dprintk(1, "dqbuf: stream running\n");
589 goto done; 605 goto done;
590 } 606 }
591 buf = list_entry(q->stream.next, struct videobuf_buffer, stream); 607 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
592 retval = videobuf_waiton(buf, nonblocking, 1); 608 retval = videobuf_waiton(buf, nonblocking, 1);
593 if (retval < 0) { 609 if (retval < 0) {
594 dprintk(1,"dqbuf: waiton returned %d\n",retval); 610 dprintk(1, "dqbuf: waiton returned %d\n", retval);
595 goto done; 611 goto done;
596 } 612 }
597 switch (buf->state) { 613 switch (buf->state) {
598 case STATE_ERROR: 614 case VIDEOBUF_ERROR:
599 dprintk(1,"dqbuf: state is error\n"); 615 dprintk(1, "dqbuf: state is error\n");
600 retval = -EIO; 616 retval = -EIO;
601 CALL(q,sync,q, buf); 617 CALL(q, sync, q, buf);
602 buf->state = STATE_IDLE; 618 buf->state = VIDEOBUF_IDLE;
603 break; 619 break;
604 case STATE_DONE: 620 case VIDEOBUF_DONE:
605 dprintk(1,"dqbuf: state is done\n"); 621 dprintk(1, "dqbuf: state is done\n");
606 CALL(q,sync,q, buf); 622 CALL(q, sync, q, buf);
607 buf->state = STATE_IDLE; 623 buf->state = VIDEOBUF_IDLE;
608 break; 624 break;
609 default: 625 default:
610 dprintk(1,"dqbuf: state invalid\n"); 626 dprintk(1, "dqbuf: state invalid\n");
611 retval = -EINVAL; 627 retval = -EINVAL;
612 goto done; 628 goto done;
613 } 629 }
614 list_del(&buf->stream); 630 list_del(&buf->stream);
615 memset(b,0,sizeof(*b)); 631 memset(b, 0, sizeof(*b));
616 videobuf_status(q,b,buf,q->type); 632 videobuf_status(q, b, buf, q->type);
617 633
618 done: 634 done:
619 mutex_unlock(&q->lock); 635 mutex_unlock(&q->lock);
@@ -623,7 +639,7 @@ int videobuf_dqbuf(struct videobuf_queue *q,
623int videobuf_streamon(struct videobuf_queue *q) 639int videobuf_streamon(struct videobuf_queue *q)
624{ 640{
625 struct videobuf_buffer *buf; 641 struct videobuf_buffer *buf;
626 unsigned long flags=0; 642 unsigned long flags = 0;
627 int retval; 643 int retval;
628 644
629 mutex_lock(&q->lock); 645 mutex_lock(&q->lock);
@@ -635,12 +651,12 @@ int videobuf_streamon(struct videobuf_queue *q)
635 goto done; 651 goto done;
636 q->streaming = 1; 652 q->streaming = 1;
637 if (q->irqlock) 653 if (q->irqlock)
638 spin_lock_irqsave(q->irqlock,flags); 654 spin_lock_irqsave(q->irqlock, flags);
639 list_for_each_entry(buf, &q->stream, stream) 655 list_for_each_entry(buf, &q->stream, stream)
640 if (buf->state == STATE_PREPARED) 656 if (buf->state == VIDEOBUF_PREPARED)
641 q->ops->buf_queue(q,buf); 657 q->ops->buf_queue(q, buf);
642 if (q->irqlock) 658 if (q->irqlock)
643 spin_unlock_irqrestore(q->irqlock,flags); 659 spin_unlock_irqrestore(q->irqlock, flags);
644 660
645 done: 661 done:
646 mutex_unlock(&q->lock); 662 mutex_unlock(&q->lock);
@@ -676,10 +692,10 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
676 size_t count, loff_t *ppos) 692 size_t count, loff_t *ppos)
677{ 693{
678 enum v4l2_field field; 694 enum v4l2_field field;
679 unsigned long flags=0; 695 unsigned long flags = 0;
680 int retval; 696 int retval;
681 697
682 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 698 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
683 699
684 /* setup stuff */ 700 /* setup stuff */
685 q->read_buf = videobuf_alloc(q); 701 q->read_buf = videobuf_alloc(q);
@@ -691,20 +707,20 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
691 q->read_buf->bsize = count; 707 q->read_buf->bsize = count;
692 708
693 field = videobuf_next_field(q); 709 field = videobuf_next_field(q);
694 retval = q->ops->buf_prepare(q,q->read_buf,field); 710 retval = q->ops->buf_prepare(q, q->read_buf, field);
695 if (0 != retval) 711 if (0 != retval)
696 goto done; 712 goto done;
697 713
698 /* start capture & wait */ 714 /* start capture & wait */
699 if (q->irqlock) 715 if (q->irqlock)
700 spin_lock_irqsave(q->irqlock,flags); 716 spin_lock_irqsave(q->irqlock, flags);
701 q->ops->buf_queue(q,q->read_buf); 717 q->ops->buf_queue(q, q->read_buf);
702 if (q->irqlock) 718 if (q->irqlock)
703 spin_unlock_irqrestore(q->irqlock,flags); 719 spin_unlock_irqrestore(q->irqlock, flags);
704 retval = videobuf_waiton(q->read_buf,0,0); 720 retval = videobuf_waiton(q->read_buf, 0, 0);
705 if (0 == retval) { 721 if (0 == retval) {
706 CALL(q,sync,q,q->read_buf); 722 CALL(q, sync, q, q->read_buf);
707 if (STATE_ERROR == q->read_buf->state) 723 if (VIDEOBUF_ERROR == q->read_buf->state)
708 retval = -EIO; 724 retval = -EIO;
709 else 725 else
710 retval = q->read_buf->size; 726 retval = q->read_buf->size;
@@ -712,7 +728,7 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
712 728
713 done: 729 done:
714 /* cleanup */ 730 /* cleanup */
715 q->ops->buf_release(q,q->read_buf); 731 q->ops->buf_release(q, q->read_buf);
716 kfree(q->read_buf); 732 kfree(q->read_buf);
717 q->read_buf = NULL; 733 q->read_buf = NULL;
718 return retval; 734 return retval;
@@ -723,21 +739,21 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
723 int nonblocking) 739 int nonblocking)
724{ 740{
725 enum v4l2_field field; 741 enum v4l2_field field;
726 unsigned long flags=0; 742 unsigned long flags = 0;
727 unsigned size, nbufs; 743 unsigned size, nbufs;
728 int retval; 744 int retval;
729 745
730 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 746 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
731 747
732 mutex_lock(&q->lock); 748 mutex_lock(&q->lock);
733 749
734 nbufs = 1; size = 0; 750 nbufs = 1; size = 0;
735 q->ops->buf_setup(q,&nbufs,&size); 751 q->ops->buf_setup(q, &nbufs, &size);
736 752
737 if (NULL == q->read_buf && 753 if (NULL == q->read_buf &&
738 count >= size && 754 count >= size &&
739 !nonblocking) { 755 !nonblocking) {
740 retval = videobuf_read_zerocopy(q,data,count,ppos); 756 retval = videobuf_read_zerocopy(q, data, count, ppos);
741 if (retval >= 0 || retval == -EIO) 757 if (retval >= 0 || retval == -EIO)
742 /* ok, all done */ 758 /* ok, all done */
743 goto done; 759 goto done;
@@ -749,25 +765,25 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
749 retval = -ENOMEM; 765 retval = -ENOMEM;
750 q->read_buf = videobuf_alloc(q); 766 q->read_buf = videobuf_alloc(q);
751 767
752 dprintk(1,"video alloc=0x%p\n", q->read_buf); 768 dprintk(1, "video alloc=0x%p\n", q->read_buf);
753 if (NULL == q->read_buf) 769 if (NULL == q->read_buf)
754 goto done; 770 goto done;
755 q->read_buf->memory = V4L2_MEMORY_USERPTR; 771 q->read_buf->memory = V4L2_MEMORY_USERPTR;
756 q->read_buf->bsize = count; /* preferred size */ 772 q->read_buf->bsize = count; /* preferred size */
757 field = videobuf_next_field(q); 773 field = videobuf_next_field(q);
758 retval = q->ops->buf_prepare(q,q->read_buf,field); 774 retval = q->ops->buf_prepare(q, q->read_buf, field);
759 775
760 if (0 != retval) { 776 if (0 != retval) {
761 kfree (q->read_buf); 777 kfree(q->read_buf);
762 q->read_buf = NULL; 778 q->read_buf = NULL;
763 goto done; 779 goto done;
764 } 780 }
765 if (q->irqlock) 781 if (q->irqlock)
766 spin_lock_irqsave(q->irqlock,flags); 782 spin_lock_irqsave(q->irqlock, flags);
767 783
768 q->ops->buf_queue(q,q->read_buf); 784 q->ops->buf_queue(q, q->read_buf);
769 if (q->irqlock) 785 if (q->irqlock)
770 spin_unlock_irqrestore(q->irqlock,flags); 786 spin_unlock_irqrestore(q->irqlock, flags);
771 q->read_off = 0; 787 q->read_off = 0;
772 } 788 }
773 789
@@ -776,11 +792,11 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
776 if (0 != retval) 792 if (0 != retval)
777 goto done; 793 goto done;
778 794
779 CALL(q,sync,q,q->read_buf); 795 CALL(q, sync, q, q->read_buf);
780 796
781 if (STATE_ERROR == q->read_buf->state) { 797 if (VIDEOBUF_ERROR == q->read_buf->state) {
782 /* catch I/O errors */ 798 /* catch I/O errors */
783 q->ops->buf_release(q,q->read_buf); 799 q->ops->buf_release(q, q->read_buf);
784 kfree(q->read_buf); 800 kfree(q->read_buf);
785 q->read_buf = NULL; 801 q->read_buf = NULL;
786 retval = -EIO; 802 retval = -EIO;
@@ -788,14 +804,14 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
788 } 804 }
789 805
790 /* Copy to userspace */ 806 /* Copy to userspace */
791 retval=CALL(q,video_copy_to_user,q,data,count,nonblocking); 807 retval = CALL(q, video_copy_to_user, q, data, count, nonblocking);
792 if (retval<0) 808 if (retval < 0)
793 goto done; 809 goto done;
794 810
795 q->read_off += retval; 811 q->read_off += retval;
796 if (q->read_off == q->read_buf->size) { 812 if (q->read_off == q->read_buf->size) {
797 /* all data copied, cleanup */ 813 /* all data copied, cleanup */
798 q->ops->buf_release(q,q->read_buf); 814 q->ops->buf_release(q, q->read_buf);
799 kfree(q->read_buf); 815 kfree(q->read_buf);
800 q->read_buf = NULL; 816 q->read_buf = NULL;
801 } 817 }
@@ -806,14 +822,14 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
806} 822}
807 823
808/* Locking: Caller holds q->lock */ 824/* Locking: Caller holds q->lock */
809int __videobuf_read_start(struct videobuf_queue *q) 825static int __videobuf_read_start(struct videobuf_queue *q)
810{ 826{
811 enum v4l2_field field; 827 enum v4l2_field field;
812 unsigned long flags=0; 828 unsigned long flags = 0;
813 unsigned int count = 0, size = 0; 829 unsigned int count = 0, size = 0;
814 int err, i; 830 int err, i;
815 831
816 q->ops->buf_setup(q,&count,&size); 832 q->ops->buf_setup(q, &count, &size);
817 if (count < 2) 833 if (count < 2)
818 count = 2; 834 count = 2;
819 if (count > VIDEO_MAX_FRAME) 835 if (count > VIDEO_MAX_FRAME)
@@ -828,17 +844,17 @@ int __videobuf_read_start(struct videobuf_queue *q)
828 844
829 for (i = 0; i < count; i++) { 845 for (i = 0; i < count; i++) {
830 field = videobuf_next_field(q); 846 field = videobuf_next_field(q);
831 err = q->ops->buf_prepare(q,q->bufs[i],field); 847 err = q->ops->buf_prepare(q, q->bufs[i], field);
832 if (err) 848 if (err)
833 return err; 849 return err;
834 list_add_tail(&q->bufs[i]->stream, &q->stream); 850 list_add_tail(&q->bufs[i]->stream, &q->stream);
835 } 851 }
836 if (q->irqlock) 852 if (q->irqlock)
837 spin_lock_irqsave(q->irqlock,flags); 853 spin_lock_irqsave(q->irqlock, flags);
838 for (i = 0; i < count; i++) 854 for (i = 0; i < count; i++)
839 q->ops->buf_queue(q,q->bufs[i]); 855 q->ops->buf_queue(q, q->bufs[i]);
840 if (q->irqlock) 856 if (q->irqlock)
841 spin_unlock_irqrestore(q->irqlock,flags); 857 spin_unlock_irqrestore(q->irqlock, flags);
842 q->reading = 1; 858 q->reading = 1;
843 return 0; 859 return 0;
844} 860}
@@ -859,7 +875,7 @@ static void __videobuf_read_stop(struct videobuf_queue *q)
859 } 875 }
860 q->read_buf = NULL; 876 q->read_buf = NULL;
861 q->reading = 0; 877 q->reading = 0;
862 878
863} 879}
864 880
865int videobuf_read_start(struct videobuf_queue *q) 881int videobuf_read_start(struct videobuf_queue *q)
@@ -899,11 +915,11 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
899 int vbihack, int nonblocking) 915 int vbihack, int nonblocking)
900{ 916{
901 int rc, retval; 917 int rc, retval;
902 unsigned long flags=0; 918 unsigned long flags = 0;
903 919
904 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 920 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
905 921
906 dprintk(2,"%s\n",__FUNCTION__); 922 dprintk(2, "%s\n", __FUNCTION__);
907 mutex_lock(&q->lock); 923 mutex_lock(&q->lock);
908 retval = -EBUSY; 924 retval = -EBUSY;
909 if (q->streaming) 925 if (q->streaming)
@@ -931,8 +947,8 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
931 break; 947 break;
932 } 948 }
933 949
934 if (q->read_buf->state == STATE_DONE) { 950 if (q->read_buf->state == VIDEOBUF_DONE) {
935 rc = CALL (q,copy_stream, q, data + retval, count, 951 rc = CALL(q, copy_stream, q, data + retval, count,
936 retval, vbihack, nonblocking); 952 retval, vbihack, nonblocking);
937 if (rc < 0) { 953 if (rc < 0) {
938 retval = rc; 954 retval = rc;
@@ -953,10 +969,10 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
953 list_add_tail(&q->read_buf->stream, 969 list_add_tail(&q->read_buf->stream,
954 &q->stream); 970 &q->stream);
955 if (q->irqlock) 971 if (q->irqlock)
956 spin_lock_irqsave(q->irqlock,flags); 972 spin_lock_irqsave(q->irqlock, flags);
957 q->ops->buf_queue(q,q->read_buf); 973 q->ops->buf_queue(q, q->read_buf);
958 if (q->irqlock) 974 if (q->irqlock)
959 spin_unlock_irqrestore(q->irqlock,flags); 975 spin_unlock_irqrestore(q->irqlock, flags);
960 q->read_buf = NULL; 976 q->read_buf = NULL;
961 } 977 }
962 if (retval < 0) 978 if (retval < 0)
@@ -999,8 +1015,8 @@ unsigned int videobuf_poll_stream(struct file *file,
999 1015
1000 if (0 == rc) { 1016 if (0 == rc) {
1001 poll_wait(file, &buf->done, wait); 1017 poll_wait(file, &buf->done, wait);
1002 if (buf->state == STATE_DONE || 1018 if (buf->state == VIDEOBUF_DONE ||
1003 buf->state == STATE_ERROR) 1019 buf->state == VIDEOBUF_ERROR)
1004 rc = POLLIN|POLLRDNORM; 1020 rc = POLLIN|POLLRDNORM;
1005 } 1021 }
1006 mutex_unlock(&q->lock); 1022 mutex_unlock(&q->lock);
@@ -1012,10 +1028,11 @@ int videobuf_mmap_mapper(struct videobuf_queue *q,
1012{ 1028{
1013 int retval; 1029 int retval;
1014 1030
1015 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 1031 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1016 1032
1017 mutex_lock(&q->lock); 1033 mutex_lock(&q->lock);
1018 retval=CALL(q,mmap_mapper,q,vma); 1034 retval = CALL(q, mmap_mapper, q, vma);
1035 q->is_mmapped = 1;
1019 mutex_unlock(&q->lock); 1036 mutex_unlock(&q->lock);
1020 1037
1021 return retval; 1038 return retval;
@@ -1026,15 +1043,15 @@ int videobuf_cgmbuf(struct videobuf_queue *q,
1026 struct video_mbuf *mbuf, int count) 1043 struct video_mbuf *mbuf, int count)
1027{ 1044{
1028 struct v4l2_requestbuffers req; 1045 struct v4l2_requestbuffers req;
1029 int rc,i; 1046 int rc, i;
1030 1047
1031 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS); 1048 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1032 1049
1033 memset(&req,0,sizeof(req)); 1050 memset(&req, 0, sizeof(req));
1034 req.type = q->type; 1051 req.type = q->type;
1035 req.count = count; 1052 req.count = count;
1036 req.memory = V4L2_MEMORY_MMAP; 1053 req.memory = V4L2_MEMORY_MMAP;
1037 rc = videobuf_reqbufs(q,&req); 1054 rc = videobuf_reqbufs(q, &req);
1038 if (rc < 0) 1055 if (rc < 0)
1039 return rc; 1056 return rc;
1040 1057
@@ -1079,9 +1096,3 @@ EXPORT_SYMBOL_GPL(videobuf_poll_stream);
1079EXPORT_SYMBOL_GPL(videobuf_mmap_setup); 1096EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
1080EXPORT_SYMBOL_GPL(videobuf_mmap_free); 1097EXPORT_SYMBOL_GPL(videobuf_mmap_free);
1081EXPORT_SYMBOL_GPL(videobuf_mmap_mapper); 1098EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
1082
1083/*
1084 * Local variables:
1085 * c-basic-offset: 8
1086 * End:
1087 */
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index 44ee408e145f..98efd7ab1f50 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -385,30 +385,27 @@ videobuf_vm_close(struct vm_area_struct *vma)
385 * now ...). Bounce buffers don't work very well for the data rates 385 * now ...). Bounce buffers don't work very well for the data rates
386 * video capture has. 386 * video capture has.
387 */ 387 */
388static struct page* 388static int
389videobuf_vm_nopage(struct vm_area_struct *vma, unsigned long vaddr, 389videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
390 int *type)
391{ 390{
392 struct page *page; 391 struct page *page;
393 392
394 dprintk(3,"nopage: fault @ %08lx [vma %08lx-%08lx]\n", 393 dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n",
395 vaddr,vma->vm_start,vma->vm_end); 394 (unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end);
396 if (vaddr > vma->vm_end)
397 return NOPAGE_SIGBUS;
398 page = alloc_page(GFP_USER | __GFP_DMA32); 395 page = alloc_page(GFP_USER | __GFP_DMA32);
399 if (!page) 396 if (!page)
400 return NOPAGE_OOM; 397 return VM_FAULT_OOM;
401 clear_user_page(page_address(page), vaddr, page); 398 clear_user_page(page_address(page), (unsigned long)vmf->virtual_address,
402 if (type) 399 page);
403 *type = VM_FAULT_MINOR; 400 vmf->page = page;
404 return page; 401 return 0;
405} 402}
406 403
407static struct vm_operations_struct videobuf_vm_ops = 404static struct vm_operations_struct videobuf_vm_ops =
408{ 405{
409 .open = videobuf_vm_open, 406 .open = videobuf_vm_open,
410 .close = videobuf_vm_close, 407 .close = videobuf_vm_close,
411 .nopage = videobuf_vm_nopage, 408 .fault = videobuf_vm_fault,
412}; 409};
413 410
414/* --------------------------------------------------------------------- 411/* ---------------------------------------------------------------------
diff --git a/drivers/media/video/videobuf-dvb.c b/drivers/media/video/videobuf-dvb.c
index 880317e04a02..b73aba65d21d 100644
--- a/drivers/media/video/videobuf-dvb.c
+++ b/drivers/media/video/videobuf-dvb.c
@@ -67,7 +67,7 @@ static int videobuf_dvb_thread(void *data)
67 67
68 /* feed buffer data to demux */ 68 /* feed buffer data to demux */
69 dma=videobuf_to_dma(buf); 69 dma=videobuf_to_dma(buf);
70 if (buf->state == STATE_DONE) 70 if (buf->state == VIDEOBUF_DONE)
71 dvb_dmx_swfilter(&dvb->demux, dma->vmalloc, 71 dvb_dmx_swfilter(&dvb->demux, dma->vmalloc,
72 buf->size); 72 buf->size);
73 73
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index e01259438bb2..9b3898347ca5 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -41,7 +41,7 @@ MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
41MODULE_LICENSE("GPL"); 41MODULE_LICENSE("GPL");
42 42
43#define dprintk(level, fmt, arg...) if (debug >= level) \ 43#define dprintk(level, fmt, arg...) if (debug >= level) \
44 printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg) 44 printk(KERN_DEBUG "vbuf-vmalloc: " fmt , ## arg)
45 45
46 46
47/***************************************************************************/ 47/***************************************************************************/
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index 9611c3990285..28655f8983c6 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -973,7 +973,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
973 973
974 *id = vfd->current_norm; 974 *id = vfd->current_norm;
975 975
976 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id); 976 dbgarg (cmd, "value=%08Lx\n", (long long unsigned) *id);
977 977
978 ret=0; 978 ret=0;
979 break; 979 break;
@@ -982,7 +982,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
982 { 982 {
983 v4l2_std_id *id = arg,norm; 983 v4l2_std_id *id = arg,norm;
984 984
985 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id); 985 dbgarg (cmd, "value=%08Lx\n", (long long unsigned) *id);
986 986
987 norm = (*id) & vfd->tvnorms; 987 norm = (*id) & vfd->tvnorms;
988 if ( vfd->tvnorms && !norm) /* Check if std is supported */ 988 if ( vfd->tvnorms && !norm) /* Check if std is supported */
@@ -1008,7 +1008,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1008 break; 1008 break;
1009 ret=vfd->vidioc_querystd(file, fh, arg); 1009 ret=vfd->vidioc_querystd(file, fh, arg);
1010 if (!ret) 1010 if (!ret)
1011 dbgarg (cmd, "detected std=%Lu\n", 1011 dbgarg (cmd, "detected std=%08Lx\n",
1012 (unsigned long long)*p); 1012 (unsigned long long)*p);
1013 break; 1013 break;
1014 } 1014 }
@@ -1028,7 +1028,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1028 if (!ret) 1028 if (!ret)
1029 dbgarg (cmd, "index=%d, name=%s, type=%d, " 1029 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1030 "audioset=%d, " 1030 "audioset=%d, "
1031 "tuner=%d, std=%Ld, status=%d\n", 1031 "tuner=%d, std=%08Lx, status=%d\n",
1032 p->index,p->name,p->type,p->audioset, 1032 p->index,p->name,p->type,p->audioset,
1033 p->tuner, 1033 p->tuner,
1034 (unsigned long long)p->std, 1034 (unsigned long long)p->std,
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 9b54ff9d2e36..1db067c02815 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -44,21 +44,18 @@
44#define WAKE_DENOMINATOR 1001 44#define WAKE_DENOMINATOR 1001
45#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */ 45#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
46 46
47/* These timers are for 1 fps - used only for testing */
48//#define WAKE_DENOMINATOR 30 /* hack for testing purposes */
49//#define BUFFER_TIMEOUT msecs_to_jiffies(5000) /* 5 seconds */
50
51#include "font.h" 47#include "font.h"
52 48
53#define VIVI_MAJOR_VERSION 0 49#define VIVI_MAJOR_VERSION 0
54#define VIVI_MINOR_VERSION 4 50#define VIVI_MINOR_VERSION 4
55#define VIVI_RELEASE 0 51#define VIVI_RELEASE 0
56#define VIVI_VERSION KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE) 52#define VIVI_VERSION \
53 KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE)
57 54
58/* Declare static vars that will be used as parameters */ 55/* Declare static vars that will be used as parameters */
59static unsigned int vid_limit = 16; /* Video memory limit, in Mb */ 56static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
60static struct video_device vivi; /* Video device */
61static int video_nr = -1; /* /dev/videoN, -1 for autodetect */ 57static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
58static int n_devs = 1; /* Number of virtual devices */
62 59
63/* supported controls */ 60/* supported controls */
64static struct v4l2_queryctrl vivi_qctrl[] = { 61static struct v4l2_queryctrl vivi_qctrl[] = {
@@ -71,7 +68,7 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
71 .default_value = 65535, 68 .default_value = 65535,
72 .flags = 0, 69 .flags = 0,
73 .type = V4L2_CTRL_TYPE_INTEGER, 70 .type = V4L2_CTRL_TYPE_INTEGER,
74 },{ 71 }, {
75 .id = V4L2_CID_BRIGHTNESS, 72 .id = V4L2_CID_BRIGHTNESS,
76 .type = V4L2_CTRL_TYPE_INTEGER, 73 .type = V4L2_CTRL_TYPE_INTEGER,
77 .name = "Brightness", 74 .name = "Brightness",
@@ -112,9 +109,9 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
112 109
113static int qctl_regs[ARRAY_SIZE(vivi_qctrl)]; 110static int qctl_regs[ARRAY_SIZE(vivi_qctrl)];
114 111
115#define dprintk(level,fmt, arg...) \ 112#define dprintk(dev, level, fmt, arg...) \
116 do { \ 113 do { \
117 if (vivi.debug >= (level)) \ 114 if (dev->vfd->debug >= (level)) \
118 printk(KERN_DEBUG "vivi: " fmt , ## arg); \ 115 printk(KERN_DEBUG "vivi: " fmt , ## arg); \
119 } while (0) 116 } while (0)
120 117
@@ -166,17 +163,21 @@ struct vivi_dev {
166 struct list_head vivi_devlist; 163 struct list_head vivi_devlist;
167 164
168 struct mutex lock; 165 struct mutex lock;
166 spinlock_t slock;
169 167
170 int users; 168 int users;
171 169
172 /* various device info */ 170 /* various device info */
173 struct video_device vfd; 171 struct video_device *vfd;
174 172
175 struct vivi_dmaqueue vidq; 173 struct vivi_dmaqueue vidq;
176 174
177 /* Several counters */ 175 /* Several counters */
178 int h,m,s,us,jiffies; 176 int h, m, s, ms;
177 unsigned long jiffies;
179 char timestr[13]; 178 char timestr[13];
179
180 int mv_count; /* Controls bars movement */
180}; 181};
181 182
182struct vivi_fh { 183struct vivi_fh {
@@ -184,7 +185,7 @@ struct vivi_fh {
184 185
185 /* video capture */ 186 /* video capture */
186 struct vivi_fmt *fmt; 187 struct vivi_fmt *fmt;
187 unsigned int width,height; 188 unsigned int width, height;
188 struct videobuf_queue vb_vidq; 189 struct videobuf_queue vb_vidq;
189 190
190 enum v4l2_buf_type type; 191 enum v4l2_buf_type type;
@@ -203,109 +204,113 @@ enum colors {
203 GREEN, 204 GREEN,
204 MAGENTA, 205 MAGENTA,
205 RED, 206 RED,
206 BLUE 207 BLUE,
208 BLACK,
207}; 209};
208 210
209static u8 bars[8][3] = { 211static u8 bars[8][3] = {
210 /* R G B */ 212 /* R G B */
211 {204,204,204}, /* white */ 213 {204, 204, 204}, /* white */
212 {208,208, 0}, /* ambar */ 214 {208, 208, 0}, /* ambar */
213 { 0,206,206}, /* cyan */ 215 { 0, 206, 206}, /* cyan */
214 { 0,239, 0}, /* green */ 216 { 0, 239, 0}, /* green */
215 {239, 0,239}, /* magenta */ 217 {239, 0, 239}, /* magenta */
216 {205, 0, 0}, /* red */ 218 {205, 0, 0}, /* red */
217 { 0, 0,255}, /* blue */ 219 { 0, 0, 255}, /* blue */
218 { 0, 0, 0} 220 { 0, 0, 0}, /* black */
219}; 221};
220 222
221#define TO_Y(r,g,b) (((16829*r +33039*g +6416*b + 32768)>>16)+16) 223#define TO_Y(r, g, b) \
224 (((16829 * r + 33039 * g + 6416 * b + 32768) >> 16) + 16)
222/* RGB to V(Cr) Color transform */ 225/* RGB to V(Cr) Color transform */
223#define TO_V(r,g,b) (((28784*r -24103*g -4681*b + 32768)>>16)+128) 226#define TO_V(r, g, b) \
227 (((28784 * r - 24103 * g - 4681 * b + 32768) >> 16) + 128)
224/* RGB to U(Cb) Color transform */ 228/* RGB to U(Cb) Color transform */
225#define TO_U(r,g,b) (((-9714*r -19070*g +28784*b + 32768)>>16)+128) 229#define TO_U(r, g, b) \
230 (((-9714 * r - 19070 * g + 28784 * b + 32768) >> 16) + 128)
226 231
227#define TSTAMP_MIN_Y 24 232#define TSTAMP_MIN_Y 24
228#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15 233#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15
229#define TSTAMP_MIN_X 64 234#define TSTAMP_MIN_X 64
230 235
231static void gen_line(char *basep,int inipos,int wmax, 236static void gen_line(char *basep, int inipos, int wmax,
232 int hmax, int line, int count, char *timestr) 237 int hmax, int line, int count, char *timestr)
233{ 238{
234 int w,i,j,pos=inipos,y; 239 int w, i, j, y;
235 char *p,*s; 240 int pos = inipos;
236 u8 chr,r,g,b,color; 241 char *p, *s;
242 u8 chr, r, g, b, color;
237 243
238 /* We will just duplicate the second pixel at the packet */ 244 /* We will just duplicate the second pixel at the packet */
239 wmax/=2; 245 wmax /= 2;
240 246
241 /* Generate a standard color bar pattern */ 247 /* Generate a standard color bar pattern */
242 for (w=0;w<wmax;w++) { 248 for (w = 0; w < wmax; w++) {
243 int colorpos=((w+count)*8/(wmax+1)) % 8; 249 int colorpos = ((w + count) * 8/(wmax + 1)) % 8;
244 r=bars[colorpos][0]; 250 r = bars[colorpos][0];
245 g=bars[colorpos][1]; 251 g = bars[colorpos][1];
246 b=bars[colorpos][2]; 252 b = bars[colorpos][2];
247 253
248 for (color=0;color<4;color++) { 254 for (color = 0; color < 4; color++) {
249 p=basep+pos; 255 p = basep + pos;
250 256
251 switch (color) { 257 switch (color) {
252 case 0: 258 case 0:
253 case 2: 259 case 2:
254 *p=TO_Y(r,g,b); /* Luminance */ 260 *p = TO_Y(r, g, b); /* Luma */
255 break; 261 break;
256 case 1: 262 case 1:
257 *p=TO_U(r,g,b); /* Cb */ 263 *p = TO_U(r, g, b); /* Cb */
258 break; 264 break;
259 case 3: 265 case 3:
260 *p=TO_V(r,g,b); /* Cr */ 266 *p = TO_V(r, g, b); /* Cr */
261 break; 267 break;
262 } 268 }
263 pos++; 269 pos++;
264 } 270 }
265 } 271 }
266 272
267 /* Checks if it is possible to show timestamp */ 273 /* Checks if it is possible to show timestamp */
268 if (TSTAMP_MAX_Y>=hmax) 274 if (TSTAMP_MAX_Y >= hmax)
269 goto end; 275 goto end;
270 if (TSTAMP_MIN_X+strlen(timestr)>=wmax) 276 if (TSTAMP_MIN_X + strlen(timestr) >= wmax)
271 goto end; 277 goto end;
272 278
273 /* Print stream time */ 279 /* Print stream time */
274 if (line>=TSTAMP_MIN_Y && line<=TSTAMP_MAX_Y) { 280 if (line >= TSTAMP_MIN_Y && line <= TSTAMP_MAX_Y) {
275 j=TSTAMP_MIN_X; 281 j = TSTAMP_MIN_X;
276 for (s=timestr;*s;s++) { 282 for (s = timestr; *s; s++) {
277 chr=rom8x16_bits[(*s-0x30)*16+line-TSTAMP_MIN_Y]; 283 chr = rom8x16_bits[(*s-0x30)*16+line-TSTAMP_MIN_Y];
278 for (i=0;i<7;i++) { 284 for (i = 0; i < 7; i++) {
279 if (chr&1<<(7-i)) { /* Font color*/ 285 if (chr & 1 << (7 - i)) {
280 r=bars[BLUE][0]; 286 /* Font color*/
281 g=bars[BLUE][1]; 287 r = 0;
282 b=bars[BLUE][2]; 288 g = 198;
283 r=g=b=0; 289 b = 0;
284 g=198; 290 } else {
285 } else { /* Background color */ 291 /* Background color */
286 r=bars[WHITE][0]; 292 r = bars[BLACK][0];
287 g=bars[WHITE][1]; 293 g = bars[BLACK][1];
288 b=bars[WHITE][2]; 294 b = bars[BLACK][2];
289 r=g=b=0;
290 } 295 }
291 296
292 pos=inipos+j*2; 297 pos = inipos + j * 2;
293 for (color=0;color<4;color++) { 298 for (color = 0; color < 4; color++) {
294 p=basep+pos; 299 p = basep + pos;
295 300
296 y=TO_Y(r,g,b); 301 y = TO_Y(r, g, b);
297 302
298 switch (color) { 303 switch (color) {
299 case 0: 304 case 0:
300 case 2: 305 case 2:
301 *p=TO_Y(r,g,b); /* Luminance */ 306 *p = TO_Y(r, g, b); /* Luma */
302 break; 307 break;
303 case 1: 308 case 1:
304 *p=TO_U(r,g,b); /* Cb */ 309 *p = TO_U(r, g, b); /* Cb */
305 break; 310 break;
306 case 3: 311 case 3:
307 *p=TO_V(r,g,b); /* Cr */ 312 *p = TO_V(r, g, b); /* Cr */
308 break; 313 break;
309 } 314 }
310 pos++; 315 pos++;
311 } 316 }
@@ -314,63 +319,60 @@ static void gen_line(char *basep,int inipos,int wmax,
314 } 319 }
315 } 320 }
316 321
317
318end: 322end:
319 return; 323 return;
320} 324}
321static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf) 325static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
322{ 326{
323 int h,pos=0; 327 int h , pos = 0;
324 int hmax = buf->vb.height; 328 int hmax = buf->vb.height;
325 int wmax = buf->vb.width; 329 int wmax = buf->vb.width;
326 struct timeval ts; 330 struct timeval ts;
327 char *tmpbuf = kmalloc(wmax*2,GFP_KERNEL); 331 char *tmpbuf = kmalloc(wmax * 2, GFP_KERNEL);
328 void *vbuf=videobuf_to_vmalloc (&buf->vb); 332 void *vbuf = videobuf_to_vmalloc(&buf->vb);
329 /* FIXME: move to dev struct */
330 static int mv_count=0;
331 333
332 if (!tmpbuf) 334 if (!tmpbuf)
333 return; 335 return;
334 336
335 for (h=0;h<hmax;h++) { 337 for (h = 0; h < hmax; h++) {
336 gen_line(tmpbuf,0,wmax,hmax,h,mv_count, 338 gen_line(tmpbuf, 0, wmax, hmax, h, dev->mv_count,
337 dev->timestr); 339 dev->timestr);
338 /* FIXME: replacing to __copy_to_user */ 340 /* FIXME: replacing to __copy_to_user */
339 if (copy_to_user(vbuf+pos,tmpbuf,wmax*2)!=0) 341 if (copy_to_user(vbuf + pos, tmpbuf, wmax * 2) != 0)
340 dprintk(2,"vivifill copy_to_user failed.\n"); 342 dprintk(dev, 2, "vivifill copy_to_user failed.\n");
341 pos += wmax*2; 343 pos += wmax*2;
342 } 344 }
343 345
344 mv_count++; 346 dev->mv_count++;
345 347
346 kfree(tmpbuf); 348 kfree(tmpbuf);
347 349
348 /* Updates stream time */ 350 /* Updates stream time */
349 351
350 dev->us+=jiffies_to_usecs(jiffies-dev->jiffies); 352 dev->ms += jiffies_to_msecs(jiffies-dev->jiffies);
351 dev->jiffies=jiffies; 353 dev->jiffies = jiffies;
352 if (dev->us>=1000000) { 354 if (dev->ms >= 1000) {
353 dev->us-=1000000; 355 dev->ms -= 1000;
354 dev->s++; 356 dev->s++;
355 if (dev->s>=60) { 357 if (dev->s >= 60) {
356 dev->s-=60; 358 dev->s -= 60;
357 dev->m++; 359 dev->m++;
358 if (dev->m>60) { 360 if (dev->m > 60) {
359 dev->m-=60; 361 dev->m -= 60;
360 dev->h++; 362 dev->h++;
361 if (dev->h>24) 363 if (dev->h > 24)
362 dev->h-=24; 364 dev->h -= 24;
363 } 365 }
364 } 366 }
365 } 367 }
366 sprintf(dev->timestr,"%02d:%02d:%02d:%03d", 368 sprintf(dev->timestr, "%02d:%02d:%02d:%03d",
367 dev->h,dev->m,dev->s,(dev->us+500)/1000); 369 dev->h, dev->m, dev->s, dev->ms);
368 370
369 dprintk(2,"vivifill at %s: Buffer 0x%08lx size= %d\n",dev->timestr, 371 dprintk(dev, 2, "vivifill at %s: Buffer 0x%08lx size= %d\n",
370 (unsigned long)tmpbuf,pos); 372 dev->timestr, (unsigned long)tmpbuf, pos);
371 373
372 /* Advice that buffer was filled */ 374 /* Advice that buffer was filled */
373 buf->vb.state = STATE_DONE; 375 buf->vb.state = VIDEOBUF_DONE;
374 buf->vb.field_count++; 376 buf->vb.field_count++;
375 do_gettimeofday(&ts); 377 do_gettimeofday(&ts);
376 buf->vb.ts = ts; 378 buf->vb.ts = ts;
@@ -384,14 +386,15 @@ static int restart_video_queue(struct vivi_dmaqueue *dma_q);
384static void vivi_thread_tick(struct vivi_dmaqueue *dma_q) 386static void vivi_thread_tick(struct vivi_dmaqueue *dma_q)
385{ 387{
386 struct vivi_buffer *buf; 388 struct vivi_buffer *buf;
387 struct vivi_dev *dev= container_of(dma_q,struct vivi_dev,vidq); 389 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
388 390
389 int bc; 391 int bc;
390 392
393 spin_lock(&dev->slock);
391 /* Announces videobuf that all went ok */ 394 /* Announces videobuf that all went ok */
392 for (bc = 0;; bc++) { 395 for (bc = 0;; bc++) {
393 if (list_empty(&dma_q->active)) { 396 if (list_empty(&dma_q->active)) {
394 dprintk(1,"No active queue to serve\n"); 397 dprintk(dev, 1, "No active queue to serve\n");
395 break; 398 break;
396 } 399 }
397 400
@@ -401,65 +404,89 @@ static void vivi_thread_tick(struct vivi_dmaqueue *dma_q)
401 /* Nobody is waiting something to be done, just return */ 404 /* Nobody is waiting something to be done, just return */
402 if (!waitqueue_active(&buf->vb.done)) { 405 if (!waitqueue_active(&buf->vb.done)) {
403 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 406 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
407 spin_unlock(&dev->slock);
404 return; 408 return;
405 } 409 }
406 410
407 do_gettimeofday(&buf->vb.ts); 411 do_gettimeofday(&buf->vb.ts);
408 dprintk(2,"[%p/%d] wakeup\n",buf,buf->vb.i); 412 dprintk(dev, 2, "[%p/%d] wakeup\n", buf, buf->vb. i);
409 413
410 /* Fill buffer */ 414 /* Fill buffer */
411 vivi_fillbuff(dev,buf); 415 vivi_fillbuff(dev, buf);
412 416
413 if (list_empty(&dma_q->active)) { 417 if (list_empty(&dma_q->active)) {
414 del_timer(&dma_q->timeout); 418 del_timer(&dma_q->timeout);
415 } else { 419 } else {
416 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 420 mod_timer(&dma_q->timeout, jiffies + BUFFER_TIMEOUT);
417 } 421 }
418 } 422 }
419 if (bc != 1) 423 if (bc != 1)
420 dprintk(1,"%s: %d buffers handled (should be 1)\n",__FUNCTION__,bc); 424 dprintk(dev, 1, "%s: %d buffers handled (should be 1)\n",
425 __FUNCTION__, bc);
426 spin_unlock(&dev->slock);
421} 427}
422 428
429#define frames_to_ms(frames) \
430 ((frames * WAKE_NUMERATOR * 1000) / WAKE_DENOMINATOR)
431
423static void vivi_sleep(struct vivi_dmaqueue *dma_q) 432static void vivi_sleep(struct vivi_dmaqueue *dma_q)
424{ 433{
425 int timeout; 434 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
435 int timeout, running_time;
426 DECLARE_WAITQUEUE(wait, current); 436 DECLARE_WAITQUEUE(wait, current);
427 437
428 dprintk(1,"%s dma_q=0x%08lx\n",__FUNCTION__,(unsigned long)dma_q); 438 dprintk(dev, 1, "%s dma_q=0x%08lx\n", __FUNCTION__,
439 (unsigned long)dma_q);
429 440
430 add_wait_queue(&dma_q->wq, &wait); 441 add_wait_queue(&dma_q->wq, &wait);
431 if (!kthread_should_stop()) { 442 if (kthread_should_stop())
432 dma_q->frame++; 443 goto stop_task;
433 444
434 /* Calculate time to wake up */ 445 running_time = jiffies - dma_q->ini_jiffies;
435 timeout=dma_q->ini_jiffies+msecs_to_jiffies((dma_q->frame*WAKE_NUMERATOR*1000)/WAKE_DENOMINATOR)-jiffies; 446 dma_q->frame++;
436 447
437 if (timeout <= 0) { 448 /* Calculate time to wake up */
438 int old=dma_q->frame; 449 timeout = msecs_to_jiffies(frames_to_ms(dma_q->frame)) - running_time;
439 dma_q->frame=(jiffies_to_msecs(jiffies-dma_q->ini_jiffies)*WAKE_DENOMINATOR)/(WAKE_NUMERATOR*1000)+1;
440 450
441 timeout=dma_q->ini_jiffies+msecs_to_jiffies((dma_q->frame*WAKE_NUMERATOR*1000)/WAKE_DENOMINATOR)-jiffies; 451 if (timeout > msecs_to_jiffies(frames_to_ms(2)) || timeout <= 0) {
452 int old = dma_q->frame;
453 int nframes;
442 454
443 dprintk(1,"underrun, losed %d frames. " 455 dma_q->frame = (jiffies_to_msecs(running_time) /
444 "Now, frame is %d. Waking on %d jiffies\n", 456 frames_to_ms(1)) + 1;
445 dma_q->frame-old,dma_q->frame,timeout);
446 } else
447 dprintk(1,"will sleep for %i jiffies\n",timeout);
448 457
449 vivi_thread_tick(dma_q); 458 timeout = msecs_to_jiffies(frames_to_ms(dma_q->frame))
459 - running_time;
450 460
451 schedule_timeout_interruptible (timeout); 461 if (unlikely (timeout <= 0))
452 } 462 timeout = 1;
463
464 nframes = (dma_q->frame > old)?
465 dma_q->frame - old : old - dma_q->frame;
466
467 dprintk(dev, 1, "%ld: %s %d frames. "
468 "Current frame is %d. Will sleep for %d jiffies\n",
469 jiffies,
470 (dma_q->frame > old)? "Underrun, losed" : "Overrun of",
471 nframes, dma_q->frame, timeout);
472 } else
473 dprintk(dev, 1, "will sleep for %d jiffies\n", timeout);
453 474
475 vivi_thread_tick(dma_q);
476
477 schedule_timeout_interruptible(timeout);
478
479stop_task:
454 remove_wait_queue(&dma_q->wq, &wait); 480 remove_wait_queue(&dma_q->wq, &wait);
455 try_to_freeze(); 481 try_to_freeze();
456} 482}
457 483
458static int vivi_thread(void *data) 484static int vivi_thread(void *data)
459{ 485{
460 struct vivi_dmaqueue *dma_q=data; 486 struct vivi_dmaqueue *dma_q = data;
487 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
461 488
462 dprintk(1,"thread started\n"); 489 dprintk(dev, 1, "thread started\n");
463 490
464 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 491 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
465 set_freezable(); 492 set_freezable();
@@ -470,16 +497,18 @@ static int vivi_thread(void *data)
470 if (kthread_should_stop()) 497 if (kthread_should_stop())
471 break; 498 break;
472 } 499 }
473 dprintk(1, "thread: exit\n"); 500 dprintk(dev, 1, "thread: exit\n");
474 return 0; 501 return 0;
475} 502}
476 503
477static int vivi_start_thread(struct vivi_dmaqueue *dma_q) 504static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
478{ 505{
479 dma_q->frame=0; 506 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
480 dma_q->ini_jiffies=jiffies;
481 507
482 dprintk(1,"%s\n",__FUNCTION__); 508 dma_q->frame = 0;
509 dma_q->ini_jiffies = jiffies;
510
511 dprintk(dev, 1, "%s\n", __FUNCTION__);
483 512
484 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi"); 513 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi");
485 514
@@ -490,39 +519,43 @@ static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
490 /* Wakes thread */ 519 /* Wakes thread */
491 wake_up_interruptible(&dma_q->wq); 520 wake_up_interruptible(&dma_q->wq);
492 521
493 dprintk(1,"returning from %s\n",__FUNCTION__); 522 dprintk(dev, 1, "returning from %s\n", __FUNCTION__);
494 return 0; 523 return 0;
495} 524}
496 525
497static void vivi_stop_thread(struct vivi_dmaqueue *dma_q) 526static void vivi_stop_thread(struct vivi_dmaqueue *dma_q)
498{ 527{
499 dprintk(1,"%s\n",__FUNCTION__); 528 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
529
530 dprintk(dev, 1, "%s\n", __FUNCTION__);
500 /* shutdown control thread */ 531 /* shutdown control thread */
501 if (dma_q->kthread) { 532 if (dma_q->kthread) {
502 kthread_stop(dma_q->kthread); 533 kthread_stop(dma_q->kthread);
503 dma_q->kthread=NULL; 534 dma_q->kthread = NULL;
504 } 535 }
505} 536}
506 537
507static int restart_video_queue(struct vivi_dmaqueue *dma_q) 538static int restart_video_queue(struct vivi_dmaqueue *dma_q)
508{ 539{
540 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
509 struct vivi_buffer *buf, *prev; 541 struct vivi_buffer *buf, *prev;
510 542
511 dprintk(1,"%s dma_q=0x%08lx\n",__FUNCTION__,(unsigned long)dma_q); 543 dprintk(dev, 1, "%s dma_q=0x%08lx\n", __FUNCTION__,
544 (unsigned long)dma_q);
512 545
513 if (!list_empty(&dma_q->active)) { 546 if (!list_empty(&dma_q->active)) {
514 buf = list_entry(dma_q->active.next, struct vivi_buffer, vb.queue); 547 buf = list_entry(dma_q->active.next,
515 dprintk(2,"restart_queue [%p/%d]: restart dma\n", 548 struct vivi_buffer, vb.queue);
549 dprintk(dev, 2, "restart_queue [%p/%d]: restart dma\n",
516 buf, buf->vb.i); 550 buf, buf->vb.i);
517 551
518 dprintk(1,"Restarting video dma\n"); 552 dprintk(dev, 1, "Restarting video dma\n");
519 vivi_stop_thread(dma_q); 553 vivi_stop_thread(dma_q);
520// vivi_start_thread(dma_q);
521 554
522 /* cancel all outstanding capture / vbi requests */ 555 /* cancel all outstanding capture / vbi requests */
523 list_for_each_entry_safe(buf, prev, &dma_q->active, vb.queue) { 556 list_for_each_entry_safe(buf, prev, &dma_q->active, vb.queue) {
524 list_del(&buf->vb.queue); 557 list_del(&buf->vb.queue);
525 buf->vb.state = STATE_ERROR; 558 buf->vb.state = VIDEOBUF_ERROR;
526 wake_up(&buf->vb.done); 559 wake_up(&buf->vb.done);
527 } 560 }
528 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 561 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
@@ -534,28 +567,31 @@ static int restart_video_queue(struct vivi_dmaqueue *dma_q)
534 for (;;) { 567 for (;;) {
535 if (list_empty(&dma_q->queued)) 568 if (list_empty(&dma_q->queued))
536 return 0; 569 return 0;
537 buf = list_entry(dma_q->queued.next, struct vivi_buffer, vb.queue); 570 buf = list_entry(dma_q->queued.next,
571 struct vivi_buffer, vb.queue);
538 if (NULL == prev) { 572 if (NULL == prev) {
539 list_del(&buf->vb.queue); 573 list_del(&buf->vb.queue);
540 list_add_tail(&buf->vb.queue,&dma_q->active); 574 list_add_tail(&buf->vb.queue, &dma_q->active);
541 575
542 dprintk(1,"Restarting video dma\n"); 576 dprintk(dev, 1, "Restarting video dma\n");
543 vivi_stop_thread(dma_q); 577 vivi_stop_thread(dma_q);
544 vivi_start_thread(dma_q); 578 vivi_start_thread(dma_q);
545 579
546 buf->vb.state = STATE_ACTIVE; 580 buf->vb.state = VIDEOBUF_ACTIVE;
547 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 581 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
548 dprintk(2,"[%p/%d] restart_queue - first active\n", 582 dprintk(dev, 2,
549 buf,buf->vb.i); 583 "[%p/%d] restart_queue - first active\n",
584 buf, buf->vb.i);
550 585
551 } else if (prev->vb.width == buf->vb.width && 586 } else if (prev->vb.width == buf->vb.width &&
552 prev->vb.height == buf->vb.height && 587 prev->vb.height == buf->vb.height &&
553 prev->fmt == buf->fmt) { 588 prev->fmt == buf->fmt) {
554 list_del(&buf->vb.queue); 589 list_del(&buf->vb.queue);
555 list_add_tail(&buf->vb.queue,&dma_q->active); 590 list_add_tail(&buf->vb.queue, &dma_q->active);
556 buf->vb.state = STATE_ACTIVE; 591 buf->vb.state = VIDEOBUF_ACTIVE;
557 dprintk(2,"[%p/%d] restart_queue - move to active\n", 592 dprintk(dev, 2,
558 buf,buf->vb.i); 593 "[%p/%d] restart_queue - move to active\n",
594 buf, buf->vb.i);
559 } else { 595 } else {
560 return 0; 596 return 0;
561 } 597 }
@@ -565,19 +601,23 @@ static int restart_video_queue(struct vivi_dmaqueue *dma_q)
565 601
566static void vivi_vid_timeout(unsigned long data) 602static void vivi_vid_timeout(unsigned long data)
567{ 603{
568 struct vivi_dev *dev = (struct vivi_dev*)data; 604 struct vivi_dev *dev = (struct vivi_dev *)data;
569 struct vivi_dmaqueue *vidq = &dev->vidq; 605 struct vivi_dmaqueue *vidq = &dev->vidq;
570 struct vivi_buffer *buf; 606 struct vivi_buffer *buf;
571 607
608 spin_lock(&dev->slock);
609
572 while (!list_empty(&vidq->active)) { 610 while (!list_empty(&vidq->active)) {
573 buf = list_entry(vidq->active.next, struct vivi_buffer, vb.queue); 611 buf = list_entry(vidq->active.next,
612 struct vivi_buffer, vb.queue);
574 list_del(&buf->vb.queue); 613 list_del(&buf->vb.queue);
575 buf->vb.state = STATE_ERROR; 614 buf->vb.state = VIDEOBUF_ERROR;
576 wake_up(&buf->vb.done); 615 wake_up(&buf->vb.done);
577 printk("vivi/0: [%p/%d] timeout\n", buf, buf->vb.i); 616 printk(KERN_INFO "vivi/0: [%p/%d] timeout\n", buf, buf->vb.i);
578 } 617 }
579
580 restart_video_queue(vidq); 618 restart_video_queue(vidq);
619
620 spin_unlock(&dev->slock);
581} 621}
582 622
583/* ------------------------------------------------------------------ 623/* ------------------------------------------------------------------
@@ -586,7 +626,8 @@ static void vivi_vid_timeout(unsigned long data)
586static int 626static int
587buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) 627buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
588{ 628{
589 struct vivi_fh *fh = vq->priv_data; 629 struct vivi_fh *fh = vq->priv_data;
630 struct vivi_dev *dev = fh->dev;
590 631
591 *size = fh->width*fh->height*2; 632 *size = fh->width*fh->height*2;
592 633
@@ -596,21 +637,25 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
596 while (*size * *count > vid_limit * 1024 * 1024) 637 while (*size * *count > vid_limit * 1024 * 1024)
597 (*count)--; 638 (*count)--;
598 639
599 dprintk(1,"%s, count=%d, size=%d\n",__FUNCTION__,*count, *size); 640 dprintk(dev, 1, "%s, count=%d, size=%d\n", __FUNCTION__,
641 *count, *size);
600 642
601 return 0; 643 return 0;
602} 644}
603 645
604static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf) 646static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
605{ 647{
606 dprintk(1,"%s\n",__FUNCTION__); 648 struct vivi_fh *fh = vq->priv_data;
649 struct vivi_dev *dev = fh->dev;
650
651 dprintk(dev, 1, "%s\n", __FUNCTION__);
607 652
608 if (in_interrupt()) 653 if (in_interrupt())
609 BUG(); 654 BUG();
610 655
611 videobuf_waiton(&buf->vb,0,0); 656 videobuf_waiton(&buf->vb, 0, 0);
612 videobuf_vmalloc_free(&buf->vb); 657 videobuf_vmalloc_free(&buf->vb);
613 buf->vb.state = STATE_NEEDS_INIT; 658 buf->vb.state = VIDEOBUF_NEEDS_INIT;
614} 659}
615 660
616#define norm_maxw() 1024 661#define norm_maxw() 1024
@@ -620,10 +665,11 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
620 enum v4l2_field field) 665 enum v4l2_field field)
621{ 666{
622 struct vivi_fh *fh = vq->priv_data; 667 struct vivi_fh *fh = vq->priv_data;
623 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb); 668 struct vivi_dev *dev = fh->dev;
669 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
624 int rc, init_buffer = 0; 670 int rc, init_buffer = 0;
625 671
626 dprintk(1,"%s, field=%d\n",__FUNCTION__,field); 672 dprintk(dev, 1, "%s, field=%d\n", __FUNCTION__, field);
627 673
628 BUG_ON(NULL == fh->fmt); 674 BUG_ON(NULL == fh->fmt);
629 if (fh->width < 48 || fh->width > norm_maxw() || 675 if (fh->width < 48 || fh->width > norm_maxw() ||
@@ -644,75 +690,81 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
644 init_buffer = 1; 690 init_buffer = 1;
645 } 691 }
646 692
647 if (STATE_NEEDS_INIT == buf->vb.state) { 693 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
648 if (0 != (rc = videobuf_iolock(vq,&buf->vb,NULL))) 694 rc = videobuf_iolock(vq, &buf->vb, NULL);
695 if (rc < 0)
649 goto fail; 696 goto fail;
650 } 697 }
651 698
652 buf->vb.state = STATE_PREPARED; 699 buf->vb.state = VIDEOBUF_PREPARED;
653 700
654 return 0; 701 return 0;
655 702
656fail: 703fail:
657 free_buffer(vq,buf); 704 free_buffer(vq, buf);
658 return rc; 705 return rc;
659} 706}
660 707
661static void 708static void
662buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) 709buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
663{ 710{
664 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb); 711 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
665 struct vivi_fh *fh = vq->priv_data; 712 struct vivi_fh *fh = vq->priv_data;
666 struct vivi_dev *dev = fh->dev; 713 struct vivi_dev *dev = fh->dev;
667 struct vivi_dmaqueue *vidq = &dev->vidq; 714 struct vivi_dmaqueue *vidq = &dev->vidq;
668 struct vivi_buffer *prev; 715 struct vivi_buffer *prev;
669 716
670 if (!list_empty(&vidq->queued)) { 717 if (!list_empty(&vidq->queued)) {
671 dprintk(1,"adding vb queue=0x%08lx\n",(unsigned long)&buf->vb.queue); 718 dprintk(dev, 1, "adding vb queue=0x%08lx\n",
672 list_add_tail(&buf->vb.queue,&vidq->queued); 719 (unsigned long)&buf->vb.queue);
673 buf->vb.state = STATE_QUEUED; 720 list_add_tail(&buf->vb.queue, &vidq->queued);
674 dprintk(2,"[%p/%d] buffer_queue - append to queued\n", 721 buf->vb.state = VIDEOBUF_QUEUED;
722 dprintk(dev, 2, "[%p/%d] buffer_queue - append to queued\n",
675 buf, buf->vb.i); 723 buf, buf->vb.i);
676 } else if (list_empty(&vidq->active)) { 724 } else if (list_empty(&vidq->active)) {
677 list_add_tail(&buf->vb.queue,&vidq->active); 725 list_add_tail(&buf->vb.queue, &vidq->active);
678 726
679 buf->vb.state = STATE_ACTIVE; 727 buf->vb.state = VIDEOBUF_ACTIVE;
680 mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT); 728 mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT);
681 dprintk(2,"[%p/%d] buffer_queue - first active\n", 729 dprintk(dev, 2, "[%p/%d] buffer_queue - first active\n",
682 buf, buf->vb.i); 730 buf, buf->vb.i);
683 731
684 vivi_start_thread(vidq); 732 vivi_start_thread(vidq);
685 } else { 733 } else {
686 prev = list_entry(vidq->active.prev, struct vivi_buffer, vb.queue); 734 prev = list_entry(vidq->active.prev,
735 struct vivi_buffer, vb.queue);
687 if (prev->vb.width == buf->vb.width && 736 if (prev->vb.width == buf->vb.width &&
688 prev->vb.height == buf->vb.height && 737 prev->vb.height == buf->vb.height &&
689 prev->fmt == buf->fmt) { 738 prev->fmt == buf->fmt) {
690 list_add_tail(&buf->vb.queue,&vidq->active); 739 list_add_tail(&buf->vb.queue, &vidq->active);
691 buf->vb.state = STATE_ACTIVE; 740 buf->vb.state = VIDEOBUF_ACTIVE;
692 dprintk(2,"[%p/%d] buffer_queue - append to active\n", 741 dprintk(dev, 2,
742 "[%p/%d] buffer_queue - append to active\n",
693 buf, buf->vb.i); 743 buf, buf->vb.i);
694 744
695 } else { 745 } else {
696 list_add_tail(&buf->vb.queue,&vidq->queued); 746 list_add_tail(&buf->vb.queue, &vidq->queued);
697 buf->vb.state = STATE_QUEUED; 747 buf->vb.state = VIDEOBUF_QUEUED;
698 dprintk(2,"[%p/%d] buffer_queue - first queued\n", 748 dprintk(dev, 2,
749 "[%p/%d] buffer_queue - first queued\n",
699 buf, buf->vb.i); 750 buf, buf->vb.i);
700 } 751 }
701 } 752 }
702} 753}
703 754
704static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb) 755static void buffer_release(struct videobuf_queue *vq,
756 struct videobuf_buffer *vb)
705{ 757{
706 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb); 758 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
707 struct vivi_fh *fh = vq->priv_data; 759 struct vivi_fh *fh = vq->priv_data;
708 struct vivi_dev *dev = (struct vivi_dev*)fh->dev; 760 struct vivi_dev *dev = (struct vivi_dev *)fh->dev;
709 struct vivi_dmaqueue *vidq = &dev->vidq; 761 struct vivi_dmaqueue *vidq = &dev->vidq;
710 762
711 dprintk(1,"%s\n",__FUNCTION__); 763 dprintk(dev, 1, "%s\n", __FUNCTION__);
712 764
713 vivi_stop_thread(vidq); 765 vivi_stop_thread(vidq);
714 766
715 free_buffer(vq,buf); 767 free_buffer(vq, buf);
716} 768}
717 769
718static struct videobuf_queue_ops vivi_video_qops = { 770static struct videobuf_queue_ops vivi_video_qops = {
@@ -725,7 +777,7 @@ static struct videobuf_queue_ops vivi_video_qops = {
725/* ------------------------------------------------------------------ 777/* ------------------------------------------------------------------
726 IOCTL vidioc handling 778 IOCTL vidioc handling
727 ------------------------------------------------------------------*/ 779 ------------------------------------------------------------------*/
728static int vidioc_querycap (struct file *file, void *priv, 780static int vidioc_querycap(struct file *file, void *priv,
729 struct v4l2_capability *cap) 781 struct v4l2_capability *cap)
730{ 782{
731 strcpy(cap->driver, "vivi"); 783 strcpy(cap->driver, "vivi");
@@ -737,21 +789,21 @@ static int vidioc_querycap (struct file *file, void *priv,
737 return 0; 789 return 0;
738} 790}
739 791
740static int vidioc_enum_fmt_cap (struct file *file, void *priv, 792static int vidioc_enum_fmt_cap(struct file *file, void *priv,
741 struct v4l2_fmtdesc *f) 793 struct v4l2_fmtdesc *f)
742{ 794{
743 if (f->index > 0) 795 if (f->index > 0)
744 return -EINVAL; 796 return -EINVAL;
745 797
746 strlcpy(f->description,format.name,sizeof(f->description)); 798 strlcpy(f->description, format.name, sizeof(f->description));
747 f->pixelformat = format.fourcc; 799 f->pixelformat = format.fourcc;
748 return 0; 800 return 0;
749} 801}
750 802
751static int vidioc_g_fmt_cap (struct file *file, void *priv, 803static int vidioc_g_fmt_cap(struct file *file, void *priv,
752 struct v4l2_format *f) 804 struct v4l2_format *f)
753{ 805{
754 struct vivi_fh *fh=priv; 806 struct vivi_fh *fh = priv;
755 807
756 f->fmt.pix.width = fh->width; 808 f->fmt.pix.width = fh->width;
757 f->fmt.pix.height = fh->height; 809 f->fmt.pix.height = fh->height;
@@ -765,26 +817,29 @@ static int vidioc_g_fmt_cap (struct file *file, void *priv,
765 return (0); 817 return (0);
766} 818}
767 819
768static int vidioc_try_fmt_cap (struct file *file, void *priv, 820static int vidioc_try_fmt_cap(struct file *file, void *priv,
769 struct v4l2_format *f) 821 struct v4l2_format *f)
770{ 822{
823 struct vivi_fh *fh = priv;
824 struct vivi_dev *dev = fh->dev;
771 struct vivi_fmt *fmt; 825 struct vivi_fmt *fmt;
772 enum v4l2_field field; 826 enum v4l2_field field;
773 unsigned int maxw, maxh; 827 unsigned int maxw, maxh;
774 828
775 if (format.fourcc != f->fmt.pix.pixelformat) { 829 if (format.fourcc != f->fmt.pix.pixelformat) {
776 dprintk(1,"Fourcc format (0x%08x) invalid. Driver accepts " 830 dprintk(dev, 1, "Fourcc format (0x%08x) invalid. "
777 "only 0x%08x\n",f->fmt.pix.pixelformat,format.fourcc); 831 "Driver accepts only 0x%08x\n",
832 f->fmt.pix.pixelformat, format.fourcc);
778 return -EINVAL; 833 return -EINVAL;
779 } 834 }
780 fmt=&format; 835 fmt = &format;
781 836
782 field = f->fmt.pix.field; 837 field = f->fmt.pix.field;
783 838
784 if (field == V4L2_FIELD_ANY) { 839 if (field == V4L2_FIELD_ANY) {
785 field=V4L2_FIELD_INTERLACED; 840 field = V4L2_FIELD_INTERLACED;
786 } else if (V4L2_FIELD_INTERLACED != field) { 841 } else if (V4L2_FIELD_INTERLACED != field) {
787 dprintk(1,"Field type invalid.\n"); 842 dprintk(dev, 1, "Field type invalid.\n");
788 return -EINVAL; 843 return -EINVAL;
789 } 844 }
790 845
@@ -810,11 +865,11 @@ static int vidioc_try_fmt_cap (struct file *file, void *priv,
810} 865}
811 866
812/*FIXME: This seems to be generic enough to be at videodev2 */ 867/*FIXME: This seems to be generic enough to be at videodev2 */
813static int vidioc_s_fmt_cap (struct file *file, void *priv, 868static int vidioc_s_fmt_cap(struct file *file, void *priv,
814 struct v4l2_format *f) 869 struct v4l2_format *f)
815{ 870{
816 struct vivi_fh *fh=priv; 871 struct vivi_fh *fh = priv;
817 int ret = vidioc_try_fmt_cap(file,fh,f); 872 int ret = vidioc_try_fmt_cap(file, fh, f);
818 if (ret < 0) 873 if (ret < 0)
819 return (ret); 874 return (ret);
820 875
@@ -827,47 +882,48 @@ static int vidioc_s_fmt_cap (struct file *file, void *priv,
827 return (0); 882 return (0);
828} 883}
829 884
830static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p) 885static int vidioc_reqbufs(struct file *file, void *priv,
886 struct v4l2_requestbuffers *p)
831{ 887{
832 struct vivi_fh *fh=priv; 888 struct vivi_fh *fh = priv;
833 889
834 return (videobuf_reqbufs(&fh->vb_vidq, p)); 890 return (videobuf_reqbufs(&fh->vb_vidq, p));
835} 891}
836 892
837static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p) 893static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
838{ 894{
839 struct vivi_fh *fh=priv; 895 struct vivi_fh *fh = priv;
840 896
841 return (videobuf_querybuf(&fh->vb_vidq, p)); 897 return (videobuf_querybuf(&fh->vb_vidq, p));
842} 898}
843 899
844static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p) 900static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
845{ 901{
846 struct vivi_fh *fh=priv; 902 struct vivi_fh *fh = priv;
847 903
848 return (videobuf_qbuf(&fh->vb_vidq, p)); 904 return (videobuf_qbuf(&fh->vb_vidq, p));
849} 905}
850 906
851static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p) 907static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
852{ 908{
853 struct vivi_fh *fh=priv; 909 struct vivi_fh *fh = priv;
854 910
855 return (videobuf_dqbuf(&fh->vb_vidq, p, 911 return (videobuf_dqbuf(&fh->vb_vidq, p,
856 file->f_flags & O_NONBLOCK)); 912 file->f_flags & O_NONBLOCK));
857} 913}
858 914
859#ifdef CONFIG_VIDEO_V4L1_COMPAT 915#ifdef CONFIG_VIDEO_V4L1_COMPAT
860static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf) 916static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
861{ 917{
862 struct vivi_fh *fh=priv; 918 struct vivi_fh *fh = priv;
863 919
864 return videobuf_cgmbuf (&fh->vb_vidq, mbuf, 8); 920 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
865} 921}
866#endif 922#endif
867 923
868static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) 924static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
869{ 925{
870 struct vivi_fh *fh=priv; 926 struct vivi_fh *fh = priv;
871 927
872 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 928 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
873 return -EINVAL; 929 return -EINVAL;
@@ -879,7 +935,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
879 935
880static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) 936static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
881{ 937{
882 struct vivi_fh *fh=priv; 938 struct vivi_fh *fh = priv;
883 939
884 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 940 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
885 return -EINVAL; 941 return -EINVAL;
@@ -889,32 +945,32 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
889 return videobuf_streamoff(&fh->vb_vidq); 945 return videobuf_streamoff(&fh->vb_vidq);
890} 946}
891 947
892static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *i) 948static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
893{ 949{
894 return 0; 950 return 0;
895} 951}
896 952
897/* only one input in this sample driver */ 953/* only one input in this sample driver */
898static int vidioc_enum_input (struct file *file, void *priv, 954static int vidioc_enum_input(struct file *file, void *priv,
899 struct v4l2_input *inp) 955 struct v4l2_input *inp)
900{ 956{
901 if (inp->index != 0) 957 if (inp->index != 0)
902 return -EINVAL; 958 return -EINVAL;
903 959
904 inp->type = V4L2_INPUT_TYPE_CAMERA; 960 inp->type = V4L2_INPUT_TYPE_CAMERA;
905 inp->std = V4L2_STD_NTSC_M; 961 inp->std = V4L2_STD_525_60;
906 strcpy(inp->name,"Camera"); 962 strcpy(inp->name, "Camera");
907 963
908 return (0); 964 return (0);
909} 965}
910 966
911static int vidioc_g_input (struct file *file, void *priv, unsigned int *i) 967static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
912{ 968{
913 *i = 0; 969 *i = 0;
914 970
915 return (0); 971 return (0);
916} 972}
917static int vidioc_s_input (struct file *file, void *priv, unsigned int i) 973static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
918{ 974{
919 if (i > 0) 975 if (i > 0)
920 return -EINVAL; 976 return -EINVAL;
@@ -923,8 +979,8 @@ static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
923} 979}
924 980
925 /* --- controls ---------------------------------------------- */ 981 /* --- controls ---------------------------------------------- */
926static int vidioc_queryctrl (struct file *file, void *priv, 982static int vidioc_queryctrl(struct file *file, void *priv,
927 struct v4l2_queryctrl *qc) 983 struct v4l2_queryctrl *qc)
928{ 984{
929 int i; 985 int i;
930 986
@@ -938,33 +994,31 @@ static int vidioc_queryctrl (struct file *file, void *priv,
938 return -EINVAL; 994 return -EINVAL;
939} 995}
940 996
941static int vidioc_g_ctrl (struct file *file, void *priv, 997static int vidioc_g_ctrl(struct file *file, void *priv,
942 struct v4l2_control *ctrl) 998 struct v4l2_control *ctrl)
943{ 999{
944 int i; 1000 int i;
945 1001
946 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) 1002 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
947 if (ctrl->id == vivi_qctrl[i].id) { 1003 if (ctrl->id == vivi_qctrl[i].id) {
948 ctrl->value=qctl_regs[i]; 1004 ctrl->value = qctl_regs[i];
949 return (0); 1005 return (0);
950 } 1006 }
951 1007
952 return -EINVAL; 1008 return -EINVAL;
953} 1009}
954static int vidioc_s_ctrl (struct file *file, void *priv, 1010static int vidioc_s_ctrl(struct file *file, void *priv,
955 struct v4l2_control *ctrl) 1011 struct v4l2_control *ctrl)
956{ 1012{
957 int i; 1013 int i;
958 1014
959 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) 1015 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
960 if (ctrl->id == vivi_qctrl[i].id) { 1016 if (ctrl->id == vivi_qctrl[i].id) {
961 if (ctrl->value < 1017 if (ctrl->value < vivi_qctrl[i].minimum
962 vivi_qctrl[i].minimum 1018 || ctrl->value > vivi_qctrl[i].maximum) {
963 || ctrl->value >
964 vivi_qctrl[i].maximum) {
965 return (-ERANGE); 1019 return (-ERANGE);
966 } 1020 }
967 qctl_regs[i]=ctrl->value; 1021 qctl_regs[i] = ctrl->value;
968 return (0); 1022 return (0);
969 } 1023 }
970 return -EINVAL; 1024 return -EINVAL;
@@ -983,24 +1037,22 @@ static int vivi_open(struct inode *inode, struct file *file)
983 struct vivi_fh *fh; 1037 struct vivi_fh *fh;
984 int i; 1038 int i;
985 1039
986 printk(KERN_DEBUG "vivi: open called (minor=%d)\n",minor); 1040 printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor);
987 1041
988 list_for_each_entry(dev, &vivi_devlist, vivi_devlist) 1042 list_for_each_entry(dev, &vivi_devlist, vivi_devlist)
989 if (dev->vfd.minor == minor) 1043 if (dev->vfd->minor == minor)
990 goto found; 1044 goto found;
991 return -ENODEV; 1045 return -ENODEV;
992found:
993
994
995 1046
1047found:
996 /* If more than one user, mutex should be added */ 1048 /* If more than one user, mutex should be added */
997 dev->users++; 1049 dev->users++;
998 1050
999 dprintk(1, "open minor=%d type=%s users=%d\n", minor, 1051 dprintk(dev, 1, "open minor=%d type=%s users=%d\n", minor,
1000 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users); 1052 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
1001 1053
1002 /* allocate + initialize per filehandle data */ 1054 /* allocate + initialize per filehandle data */
1003 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 1055 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1004 if (NULL == fh) { 1056 if (NULL == fh) {
1005 dev->users--; 1057 dev->users--;
1006 return -ENOMEM; 1058 return -ENOMEM;
@@ -1016,27 +1068,21 @@ found:
1016 1068
1017 /* Put all controls at a sane state */ 1069 /* Put all controls at a sane state */
1018 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) 1070 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
1019 qctl_regs[i] =vivi_qctrl[i].default_value; 1071 qctl_regs[i] = vivi_qctrl[i].default_value;
1020
1021 dprintk(1,"Open: fh=0x%08lx, dev=0x%08lx, dev->vidq=0x%08lx\n",
1022 (unsigned long)fh,(unsigned long)dev,(unsigned long)&dev->vidq);
1023 dprintk(1,"Open: list_empty queued=%d\n",list_empty(&dev->vidq.queued));
1024 dprintk(1,"Open: list_empty active=%d\n",list_empty(&dev->vidq.active));
1025 1072
1026 /* Resets frame counters */ 1073 /* Resets frame counters */
1027 dev->h=0; 1074 dev->h = 0;
1028 dev->m=0; 1075 dev->m = 0;
1029 dev->s=0; 1076 dev->s = 0;
1030 dev->us=0; 1077 dev->ms = 0;
1031 dev->jiffies=jiffies; 1078 dev->mv_count = 0;
1032 sprintf(dev->timestr,"%02d:%02d:%02d:%03d", 1079 dev->jiffies = jiffies;
1033 dev->h,dev->m,dev->s,(dev->us+500)/1000); 1080 sprintf(dev->timestr, "%02d:%02d:%02d:%03d",
1081 dev->h, dev->m, dev->s, dev->ms);
1034 1082
1035 videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops, 1083 videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops,
1036 NULL, NULL, 1084 NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED,
1037 fh->type, 1085 sizeof(struct vivi_buffer), fh);
1038 V4L2_FIELD_INTERLACED,
1039 sizeof(struct vivi_buffer),fh);
1040 1086
1041 return 0; 1087 return 0;
1042} 1088}
@@ -1044,9 +1090,9 @@ found:
1044static ssize_t 1090static ssize_t
1045vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos) 1091vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1046{ 1092{
1047 struct vivi_fh *fh = file->private_data; 1093 struct vivi_fh *fh = file->private_data;
1048 1094
1049 if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1095 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1050 return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0, 1096 return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0,
1051 file->f_flags & O_NONBLOCK); 1097 file->f_flags & O_NONBLOCK);
1052 } 1098 }
@@ -1057,9 +1103,10 @@ static unsigned int
1057vivi_poll(struct file *file, struct poll_table_struct *wait) 1103vivi_poll(struct file *file, struct poll_table_struct *wait)
1058{ 1104{
1059 struct vivi_fh *fh = file->private_data; 1105 struct vivi_fh *fh = file->private_data;
1106 struct vivi_dev *dev = fh->dev;
1060 struct videobuf_queue *q = &fh->vb_vidq; 1107 struct videobuf_queue *q = &fh->vb_vidq;
1061 1108
1062 dprintk(1,"%s\n",__FUNCTION__); 1109 dprintk(dev, 1, "%s\n", __FUNCTION__);
1063 1110
1064 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) 1111 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1065 return POLLERR; 1112 return POLLERR;
@@ -1067,7 +1114,7 @@ vivi_poll(struct file *file, struct poll_table_struct *wait)
1067 return videobuf_poll_stream(file, q, wait); 1114 return videobuf_poll_stream(file, q, wait);
1068} 1115}
1069 1116
1070static int vivi_release(struct inode *inode, struct file *file) 1117static int vivi_close(struct inode *inode, struct file *file)
1071{ 1118{
1072 struct vivi_fh *fh = file->private_data; 1119 struct vivi_fh *fh = file->private_data;
1073 struct vivi_dev *dev = fh->dev; 1120 struct vivi_dev *dev = fh->dev;
@@ -1079,26 +1126,48 @@ static int vivi_release(struct inode *inode, struct file *file)
1079 videobuf_stop(&fh->vb_vidq); 1126 videobuf_stop(&fh->vb_vidq);
1080 videobuf_mmap_free(&fh->vb_vidq); 1127 videobuf_mmap_free(&fh->vb_vidq);
1081 1128
1082 kfree (fh); 1129 kfree(fh);
1083 1130
1084 dev->users--; 1131 dev->users--;
1085 1132
1086 printk(KERN_DEBUG "vivi: close called (minor=%d, users=%d)\n",minor,dev->users); 1133 dprintk(dev, 1, "close called (minor=%d, users=%d)\n",
1134 minor, dev->users);
1087 1135
1088 return 0; 1136 return 0;
1089} 1137}
1090 1138
1091static int 1139static int vivi_release(void)
1092vivi_mmap(struct file *file, struct vm_area_struct * vma)
1093{ 1140{
1094 struct vivi_fh *fh = file->private_data; 1141 struct vivi_dev *dev;
1142 struct list_head *list;
1143
1144 while (!list_empty(&vivi_devlist)) {
1145 list = vivi_devlist.next;
1146 list_del(list);
1147 dev = list_entry(list, struct vivi_dev, vivi_devlist);
1148
1149 if (-1 != dev->vfd->minor)
1150 video_unregister_device(dev->vfd);
1151 else
1152 video_device_release(dev->vfd);
1153
1154 kfree(dev);
1155 }
1156
1157 return 0;
1158}
1159
1160static int vivi_mmap(struct file *file, struct vm_area_struct *vma)
1161{
1162 struct vivi_fh *fh = file->private_data;
1163 struct vivi_dev *dev = fh->dev;
1095 int ret; 1164 int ret;
1096 1165
1097 dprintk (1,"mmap called, vma=0x%08lx\n",(unsigned long)vma); 1166 dprintk(dev, 1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
1098 1167
1099 ret=videobuf_mmap_mapper(&fh->vb_vidq, vma); 1168 ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1100 1169
1101 dprintk (1,"vma start=0x%08lx, size=%ld, ret=%d\n", 1170 dprintk(dev, 1, "vma start=0x%08lx, size=%ld, ret=%d\n",
1102 (unsigned long)vma->vm_start, 1171 (unsigned long)vma->vm_start,
1103 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start, 1172 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
1104 ret); 1173 ret);
@@ -1109,7 +1178,7 @@ vivi_mmap(struct file *file, struct vm_area_struct * vma)
1109static const struct file_operations vivi_fops = { 1178static const struct file_operations vivi_fops = {
1110 .owner = THIS_MODULE, 1179 .owner = THIS_MODULE,
1111 .open = vivi_open, 1180 .open = vivi_open,
1112 .release = vivi_release, 1181 .release = vivi_close,
1113 .read = vivi_read, 1182 .read = vivi_read,
1114 .poll = vivi_poll, 1183 .poll = vivi_poll,
1115 .ioctl = video_ioctl2, /* V4L2 ioctl handler */ 1184 .ioctl = video_ioctl2, /* V4L2 ioctl handler */
@@ -1117,12 +1186,12 @@ static const struct file_operations vivi_fops = {
1117 .llseek = no_llseek, 1186 .llseek = no_llseek,
1118}; 1187};
1119 1188
1120static struct video_device vivi = { 1189static struct video_device vivi_template = {
1121 .name = "vivi", 1190 .name = "vivi",
1122 .type = VID_TYPE_CAPTURE, 1191 .type = VID_TYPE_CAPTURE,
1123 .fops = &vivi_fops, 1192 .fops = &vivi_fops,
1124 .minor = -1, 1193 .minor = -1,
1125// .release = video_device_release, 1194 .release = video_device_release,
1126 1195
1127 .vidioc_querycap = vidioc_querycap, 1196 .vidioc_querycap = vidioc_querycap,
1128 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap, 1197 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
@@ -1145,7 +1214,7 @@ static struct video_device vivi = {
1145#ifdef CONFIG_VIDEO_V4L1_COMPAT 1214#ifdef CONFIG_VIDEO_V4L1_COMPAT
1146 .vidiocgmbuf = vidiocgmbuf, 1215 .vidiocgmbuf = vidiocgmbuf,
1147#endif 1216#endif
1148 .tvnorms = V4L2_STD_NTSC_M, 1217 .tvnorms = V4L2_STD_525_60,
1149 .current_norm = V4L2_STD_NTSC_M, 1218 .current_norm = V4L2_STD_NTSC_M,
1150}; 1219};
1151/* ----------------------------------------------------------------- 1220/* -----------------------------------------------------------------
@@ -1154,43 +1223,61 @@ static struct video_device vivi = {
1154 1223
1155static int __init vivi_init(void) 1224static int __init vivi_init(void)
1156{ 1225{
1157 int ret; 1226 int ret = -ENOMEM, i;
1158 struct vivi_dev *dev; 1227 struct vivi_dev *dev;
1228 struct video_device *vfd;
1159 1229
1160 dev = kzalloc(sizeof(*dev),GFP_KERNEL); 1230 for (i = 0; i < n_devs; i++) {
1161 if (NULL == dev) 1231 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1162 return -ENOMEM; 1232 if (NULL == dev)
1163 list_add_tail(&dev->vivi_devlist,&vivi_devlist); 1233 break;
1164 1234
1165 /* init video dma queues */ 1235 list_add_tail(&dev->vivi_devlist, &vivi_devlist);
1166 INIT_LIST_HEAD(&dev->vidq.active);
1167 INIT_LIST_HEAD(&dev->vidq.queued);
1168 init_waitqueue_head(&dev->vidq.wq);
1169 1236
1170 /* initialize locks */ 1237 /* init video dma queues */
1171 mutex_init(&dev->lock); 1238 INIT_LIST_HEAD(&dev->vidq.active);
1239 INIT_LIST_HEAD(&dev->vidq.queued);
1240 init_waitqueue_head(&dev->vidq.wq);
1172 1241
1173 dev->vidq.timeout.function = vivi_vid_timeout; 1242 /* initialize locks */
1174 dev->vidq.timeout.data = (unsigned long)dev; 1243 mutex_init(&dev->lock);
1175 init_timer(&dev->vidq.timeout); 1244 spin_lock_init(&dev->slock);
1176 1245
1177 ret = video_register_device(&vivi, VFL_TYPE_GRABBER, video_nr); 1246 dev->vidq.timeout.function = vivi_vid_timeout;
1178 printk(KERN_INFO "Video Technology Magazine Virtual Video Capture Board (Load status: %d)\n", ret); 1247 dev->vidq.timeout.data = (unsigned long)dev;
1248 init_timer(&dev->vidq.timeout);
1249
1250 vfd = video_device_alloc();
1251 if (NULL == vfd)
1252 break;
1253
1254 *vfd = vivi_template;
1255
1256 ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr);
1257 if (ret < 0)
1258 break;
1259
1260 snprintf(vfd->name, sizeof(vfd->name), "%s (%i)",
1261 vivi_template.name, vfd->minor);
1262
1263 if (video_nr >= 0)
1264 video_nr++;
1265
1266 dev->vfd = vfd;
1267 }
1268
1269 if (ret < 0) {
1270 vivi_release();
1271 printk(KERN_INFO "Error %d while loading vivi driver\n", ret);
1272 } else
1273 printk(KERN_INFO "Video Technology Magazine Virtual Video "
1274 "Capture Board successfully loaded.\n");
1179 return ret; 1275 return ret;
1180} 1276}
1181 1277
1182static void __exit vivi_exit(void) 1278static void __exit vivi_exit(void)
1183{ 1279{
1184 struct vivi_dev *h; 1280 vivi_release();
1185 struct list_head *list;
1186
1187 while (!list_empty(&vivi_devlist)) {
1188 list = vivi_devlist.next;
1189 list_del(list);
1190 h = list_entry(list, struct vivi_dev, vivi_devlist);
1191 kfree (h);
1192 }
1193 video_unregister_device(&vivi);
1194} 1281}
1195 1282
1196module_init(vivi_init); 1283module_init(vivi_init);
@@ -1201,10 +1288,13 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
1201MODULE_LICENSE("Dual BSD/GPL"); 1288MODULE_LICENSE("Dual BSD/GPL");
1202 1289
1203module_param(video_nr, int, 0); 1290module_param(video_nr, int, 0);
1291MODULE_PARM_DESC(video_nr, "video iminor start number");
1204 1292
1205module_param_named(debug,vivi.debug, int, 0644); 1293module_param(n_devs, int, 0);
1206MODULE_PARM_DESC(debug,"activates debug info"); 1294MODULE_PARM_DESC(n_devs, "number of video devices to create");
1207 1295
1208module_param(vid_limit,int,0644); 1296module_param_named(debug, vivi_template.debug, int, 0444);
1209MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes"); 1297MODULE_PARM_DESC(debug, "activates debug info");
1210 1298
1299module_param(vid_limit, int, 0644);
1300MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
diff --git a/drivers/media/video/vp27smpx.c b/drivers/media/video/vp27smpx.c
index 63002e0ac764..282c81403c97 100644
--- a/drivers/media/video/vp27smpx.c
+++ b/drivers/media/video/vp27smpx.c
@@ -30,15 +30,12 @@
30#include <linux/videodev.h> 30#include <linux/videodev.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h> 32#include <media/v4l2-chip-ident.h>
33#include <media/v4l2-i2c-drv.h>
33 34
34MODULE_DESCRIPTION("vp27smpx driver"); 35MODULE_DESCRIPTION("vp27smpx driver");
35MODULE_AUTHOR("Hans Verkuil"); 36MODULE_AUTHOR("Hans Verkuil");
36MODULE_LICENSE("GPL"); 37MODULE_LICENSE("GPL");
37 38
38static unsigned short normal_i2c[] = { 0xb6 >> 1, I2C_CLIENT_END };
39
40
41I2C_CLIENT_INSMOD;
42 39
43/* ----------------------------------------------------------------------- */ 40/* ----------------------------------------------------------------------- */
44 41
@@ -53,28 +50,26 @@ static void vp27smpx_set_audmode(struct i2c_client *client, u32 audmode)
53 u8 data[3] = { 0x00, 0x00, 0x04 }; 50 u8 data[3] = { 0x00, 0x00, 0x04 };
54 51
55 switch (audmode) { 52 switch (audmode) {
56 case V4L2_TUNER_MODE_MONO: 53 case V4L2_TUNER_MODE_MONO:
57 case V4L2_TUNER_MODE_LANG1: 54 case V4L2_TUNER_MODE_LANG1:
58 break; 55 break;
59 case V4L2_TUNER_MODE_STEREO: 56 case V4L2_TUNER_MODE_STEREO:
60 case V4L2_TUNER_MODE_LANG1_LANG2: 57 case V4L2_TUNER_MODE_LANG1_LANG2:
61 data[1] = 0x01; 58 data[1] = 0x01;
62 break; 59 break;
63 case V4L2_TUNER_MODE_LANG2: 60 case V4L2_TUNER_MODE_LANG2:
64 data[1] = 0x02; 61 data[1] = 0x02;
65 break; 62 break;
66 } 63 }
67 64
68 if (i2c_master_send(client, data, sizeof(data)) != sizeof(data)) { 65 if (i2c_master_send(client, data, sizeof(data)) != sizeof(data))
69 v4l_err(client, "%s: I/O error setting audmode\n", client->name); 66 v4l_err(client, "%s: I/O error setting audmode\n",
70 } 67 client->name);
71 else { 68 else
72 state->audmode = audmode; 69 state->audmode = audmode;
73 }
74} 70}
75 71
76static int vp27smpx_command(struct i2c_client *client, unsigned int cmd, 72static int vp27smpx_command(struct i2c_client *client, unsigned cmd, void *arg)
77 void *arg)
78{ 73{
79 struct vp27smpx_state *state = i2c_get_clientdata(client); 74 struct vp27smpx_state *state = i2c_get_clientdata(client);
80 struct v4l2_tuner *vt = arg; 75 struct v4l2_tuner *vt = arg;
@@ -103,7 +98,8 @@ static int vp27smpx_command(struct i2c_client *client, unsigned int cmd,
103 break; 98 break;
104 99
105 case VIDIOC_G_CHIP_IDENT: 100 case VIDIOC_G_CHIP_IDENT:
106 return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_VP27SMPX, 0); 101 return v4l2_chip_ident_i2c_client(client, arg,
102 V4L2_IDENT_VP27SMPX, 0);
107 103
108 case VIDIOC_LOG_STATUS: 104 case VIDIOC_LOG_STATUS:
109 v4l_info(client, "Audio Mode: %u%s\n", state->audmode, 105 v4l_info(client, "Audio Mode: %u%s\n", state->audmode,
@@ -125,88 +121,43 @@ static int vp27smpx_command(struct i2c_client *client, unsigned int cmd,
125 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 121 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
126 */ 122 */
127 123
128static struct i2c_driver i2c_driver; 124static int vp27smpx_probe(struct i2c_client *client)
129
130static int vp27smpx_attach(struct i2c_adapter *adapter, int address, int kind)
131{ 125{
132 struct i2c_client *client;
133 struct vp27smpx_state *state; 126 struct vp27smpx_state *state;
134 127
135 /* Check if the adapter supports the needed features */ 128 /* Check if the adapter supports the needed features */
136 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 129 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
137 return 0; 130 return -EIO;
138
139 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
140 if (client == 0)
141 return -ENOMEM;
142 131
143 client->addr = address;
144 client->adapter = adapter;
145 client->driver = &i2c_driver;
146 snprintf(client->name, sizeof(client->name) - 1, "vp27smpx"); 132 snprintf(client->name, sizeof(client->name) - 1, "vp27smpx");
147 133
148 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name); 134 v4l_info(client, "chip found @ 0x%x (%s)\n",
135 client->addr << 1, client->adapter->name);
149 136
150 state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL); 137 state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL);
151 if (state == NULL) { 138 if (state == NULL)
152 kfree(client);
153 return -ENOMEM; 139 return -ENOMEM;
154 }
155 state->audmode = V4L2_TUNER_MODE_STEREO; 140 state->audmode = V4L2_TUNER_MODE_STEREO;
156 i2c_set_clientdata(client, state); 141 i2c_set_clientdata(client, state);
157 142
158 /* initialize vp27smpx */ 143 /* initialize vp27smpx */
159 vp27smpx_set_audmode(client, state->audmode); 144 vp27smpx_set_audmode(client, state->audmode);
160 i2c_attach_client(client);
161
162 return 0; 145 return 0;
163} 146}
164 147
165static int vp27smpx_probe(struct i2c_adapter *adapter) 148static int vp27smpx_remove(struct i2c_client *client)
166{ 149{
167 if (adapter->class & I2C_CLASS_TV_ANALOG) 150 kfree(i2c_get_clientdata(client));
168 return i2c_probe(adapter, &addr_data, vp27smpx_attach);
169 return 0;
170}
171
172static int vp27smpx_detach(struct i2c_client *client)
173{
174 struct vp27smpx_state *state = i2c_get_clientdata(client);
175 int err;
176
177 err = i2c_detach_client(client);
178 if (err) {
179 return err;
180 }
181 kfree(state);
182 kfree(client);
183
184 return 0; 151 return 0;
185} 152}
186 153
187/* ----------------------------------------------------------------------- */ 154/* ----------------------------------------------------------------------- */
188 155
189/* i2c implementation */ 156static struct v4l2_i2c_driver_data v4l2_i2c_data = {
190static struct i2c_driver i2c_driver = { 157 .name = "vp27smpx",
191 .driver = { 158 .driverid = I2C_DRIVERID_VP27SMPX,
192 .name = "vp27smpx", 159 .command = vp27smpx_command,
193 }, 160 .probe = vp27smpx_probe,
194 .id = I2C_DRIVERID_VP27SMPX, 161 .remove = vp27smpx_remove,
195 .attach_adapter = vp27smpx_probe,
196 .detach_client = vp27smpx_detach,
197 .command = vp27smpx_command,
198}; 162};
199 163
200
201static int __init vp27smpx_init_module(void)
202{
203 return i2c_add_driver(&i2c_driver);
204}
205
206static void __exit vp27smpx_cleanup_module(void)
207{
208 i2c_del_driver(&i2c_driver);
209}
210
211module_init(vp27smpx_init_module);
212module_exit(vp27smpx_cleanup_module);
diff --git a/drivers/media/video/wm8739.c b/drivers/media/video/wm8739.c
index 1bf4cbec6a87..31795b4f8b63 100644
--- a/drivers/media/video/wm8739.c
+++ b/drivers/media/video/wm8739.c
@@ -30,21 +30,19 @@
30#include <linux/videodev.h> 30#include <linux/videodev.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h> 32#include <media/v4l2-chip-ident.h>
33#include <media/v4l2-i2c-drv.h>
33 34
34MODULE_DESCRIPTION("wm8739 driver"); 35MODULE_DESCRIPTION("wm8739 driver");
35MODULE_AUTHOR("T. Adachi, Hans Verkuil"); 36MODULE_AUTHOR("T. Adachi, Hans Verkuil");
36MODULE_LICENSE("GPL"); 37MODULE_LICENSE("GPL");
37 38
38static int debug = 0; 39static int debug;
39static unsigned short normal_i2c[] = { 0x34 >> 1, 0x36 >> 1, I2C_CLIENT_END };
40 40
41module_param(debug, int, 0644); 41module_param(debug, int, 0644);
42 42
43MODULE_PARM_DESC(debug, "Debug level (0-1)"); 43MODULE_PARM_DESC(debug, "Debug level (0-1)");
44 44
45 45
46I2C_CLIENT_INSMOD;
47
48/* ------------------------------------------------------------------------ */ 46/* ------------------------------------------------------------------------ */
49 47
50enum { 48enum {
@@ -75,12 +73,10 @@ static int wm8739_write(struct i2c_client *client, int reg, u16 val)
75 73
76 v4l_dbg(1, debug, client, "write: %02x %02x\n", reg, val); 74 v4l_dbg(1, debug, client, "write: %02x %02x\n", reg, val);
77 75
78 for (i = 0; i < 3; i++) { 76 for (i = 0; i < 3; i++)
79 if (i2c_smbus_write_byte_data(client, (reg << 1) | 77 if (i2c_smbus_write_byte_data(client,
80 (val >> 8), val & 0xff) == 0) { 78 (reg << 1) | (val >> 8), val & 0xff) == 0)
81 return 0; 79 return 0;
82 }
83 }
84 v4l_err(client, "I2C: cannot write %03x to register R%d\n", val, reg); 80 v4l_err(client, "I2C: cannot write %03x to register R%d\n", val, reg);
85 return -1; 81 return -1;
86} 82}
@@ -167,7 +163,7 @@ static struct v4l2_queryctrl wm8739_qctrl[] = {
167 .default_value = 58880, 163 .default_value = 58880,
168 .flags = 0, 164 .flags = 0,
169 .type = V4L2_CTRL_TYPE_INTEGER, 165 .type = V4L2_CTRL_TYPE_INTEGER,
170 },{ 166 }, {
171 .id = V4L2_CID_AUDIO_MUTE, 167 .id = V4L2_CID_AUDIO_MUTE,
172 .name = "Mute", 168 .name = "Mute",
173 .minimum = 0, 169 .minimum = 0,
@@ -176,7 +172,7 @@ static struct v4l2_queryctrl wm8739_qctrl[] = {
176 .default_value = 1, 172 .default_value = 1,
177 .flags = 0, 173 .flags = 0,
178 .type = V4L2_CTRL_TYPE_BOOLEAN, 174 .type = V4L2_CTRL_TYPE_BOOLEAN,
179 },{ 175 }, {
180 .id = V4L2_CID_AUDIO_BALANCE, 176 .id = V4L2_CID_AUDIO_BALANCE,
181 .name = "Balance", 177 .name = "Balance",
182 .minimum = 0, 178 .minimum = 0,
@@ -190,7 +186,7 @@ static struct v4l2_queryctrl wm8739_qctrl[] = {
190 186
191/* ------------------------------------------------------------------------ */ 187/* ------------------------------------------------------------------------ */
192 188
193static int wm8739_command(struct i2c_client *client, unsigned int cmd, void *arg) 189static int wm8739_command(struct i2c_client *client, unsigned cmd, void *arg)
194{ 190{
195 struct wm8739_state *state = i2c_get_clientdata(client); 191 struct wm8739_state *state = i2c_get_clientdata(client);
196 192
@@ -200,21 +196,26 @@ static int wm8739_command(struct i2c_client *client, unsigned int cmd, void *arg
200 u32 audiofreq = *(u32 *)arg; 196 u32 audiofreq = *(u32 *)arg;
201 197
202 state->clock_freq = audiofreq; 198 state->clock_freq = audiofreq;
203 wm8739_write(client, R9, 0x000); /* de-activate */ 199 /* de-activate */
200 wm8739_write(client, R9, 0x000);
204 switch (audiofreq) { 201 switch (audiofreq) {
205 case 44100: 202 case 44100:
206 wm8739_write(client, R8, 0x020); /* 256fps, fs=44.1k */ 203 /* 256fps, fs=44.1k */
204 wm8739_write(client, R8, 0x020);
207 break; 205 break;
208 case 48000: 206 case 48000:
209 wm8739_write(client, R8, 0x000); /* 256fps, fs=48k */ 207 /* 256fps, fs=48k */
208 wm8739_write(client, R8, 0x000);
210 break; 209 break;
211 case 32000: 210 case 32000:
212 wm8739_write(client, R8, 0x018); /* 256fps, fs=32k */ 211 /* 256fps, fs=32k */
212 wm8739_write(client, R8, 0x018);
213 break; 213 break;
214 default: 214 default:
215 break; 215 break;
216 } 216 }
217 wm8739_write(client, R9, 0x001); /* activate */ 217 /* activate */
218 wm8739_write(client, R9, 0x001);
218 break; 219 break;
219 } 220 }
220 221
@@ -238,7 +239,8 @@ static int wm8739_command(struct i2c_client *client, unsigned int cmd, void *arg
238 } 239 }
239 240
240 case VIDIOC_G_CHIP_IDENT: 241 case VIDIOC_G_CHIP_IDENT:
241 return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_WM8739, 0); 242 return v4l2_chip_ident_i2c_client(client,
243 arg, V4L2_IDENT_WM8739, 0);
242 244
243 case VIDIOC_LOG_STATUS: 245 case VIDIOC_LOG_STATUS:
244 v4l_info(client, "Frequency: %u Hz\n", state->clock_freq); 246 v4l_info(client, "Frequency: %u Hz\n", state->clock_freq);
@@ -259,27 +261,16 @@ static int wm8739_command(struct i2c_client *client, unsigned int cmd, void *arg
259 261
260/* i2c implementation */ 262/* i2c implementation */
261 263
262static struct i2c_driver i2c_driver; 264static int wm8739_probe(struct i2c_client *client)
263
264static int wm8739_attach(struct i2c_adapter *adapter, int address, int kind)
265{ 265{
266 struct i2c_client *client;
267 struct wm8739_state *state; 266 struct wm8739_state *state;
268 267
269 /* Check if the adapter supports the needed features */ 268 /* Check if the adapter supports the needed features */
270 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 269 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
271 return 0; 270 return -EIO;
272
273 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
274 if (client == NULL)
275 return -ENOMEM;
276
277 client->addr = address;
278 client->adapter = adapter;
279 client->driver = &i2c_driver;
280 snprintf(client->name, sizeof(client->name) - 1, "wm8739");
281 271
282 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name); 272 v4l_info(client, "chip found @ 0x%x (%s)\n",
273 client->addr << 1, client->adapter->name);
283 274
284 state = kmalloc(sizeof(struct wm8739_state), GFP_KERNEL); 275 state = kmalloc(sizeof(struct wm8739_state), GFP_KERNEL);
285 if (state == NULL) { 276 if (state == NULL) {
@@ -295,67 +286,37 @@ static int wm8739_attach(struct i2c_adapter *adapter, int address, int kind)
295 state->clock_freq = 48000; 286 state->clock_freq = 48000;
296 i2c_set_clientdata(client, state); 287 i2c_set_clientdata(client, state);
297 288
298 /* initialize wm8739 */ 289 /* Initialize wm8739 */
299 wm8739_write(client, R15, 0x00); /* reset */ 290
300 wm8739_write(client, R5, 0x000); /* filter setting, high path, offet clear */ 291 /* reset */
301 wm8739_write(client, R6, 0x000); /* ADC, OSC, Power Off mode Disable */ 292 wm8739_write(client, R15, 0x00);
302 wm8739_write(client, R7, 0x049); /* Digital Audio interface format */ 293 /* filter setting, high path, offet clear */
303 /* Enable Master mode */ 294 wm8739_write(client, R5, 0x000);
304 /* 24 bit, MSB first/left justified */ 295 /* ADC, OSC, Power Off mode Disable */
305 wm8739_write(client, R8, 0x000); /* sampling control */ 296 wm8739_write(client, R6, 0x000);
306 /* normal, 256fs, 48KHz sampling rate */ 297 /* Digital Audio interface format:
307 wm8739_write(client, R9, 0x001); /* activate */ 298 Enable Master mode, 24 bit, MSB first/left justified */
308 wm8739_set_audio(client); /* set volume/mute */ 299 wm8739_write(client, R7, 0x049);
309 300 /* sampling control: normal, 256fs, 48KHz sampling rate */
310 i2c_attach_client(client); 301 wm8739_write(client, R8, 0x000);
311 302 /* activate */
312 return 0; 303 wm8739_write(client, R9, 0x001);
313} 304 /* set volume/mute */
314 305 wm8739_set_audio(client);
315static int wm8739_probe(struct i2c_adapter *adapter)
316{
317 if (adapter->class & I2C_CLASS_TV_ANALOG)
318 return i2c_probe(adapter, &addr_data, wm8739_attach);
319 return 0; 306 return 0;
320} 307}
321 308
322static int wm8739_detach(struct i2c_client *client) 309static int wm8739_remove(struct i2c_client *client)
323{ 310{
324 struct wm8739_state *state = i2c_get_clientdata(client); 311 kfree(i2c_get_clientdata(client));
325 int err;
326
327 err = i2c_detach_client(client);
328 if (err)
329 return err;
330
331 kfree(state);
332 kfree(client);
333 return 0; 312 return 0;
334} 313}
335 314
336/* ----------------------------------------------------------------------- */ 315static struct v4l2_i2c_driver_data v4l2_i2c_data = {
337 316 .name = "wm8739",
338/* i2c implementation */ 317 .driverid = I2C_DRIVERID_WM8739,
339static struct i2c_driver i2c_driver = {
340 .driver = {
341 .name = "wm8739",
342 },
343 .id = I2C_DRIVERID_WM8739,
344 .attach_adapter = wm8739_probe,
345 .detach_client = wm8739_detach,
346 .command = wm8739_command, 318 .command = wm8739_command,
319 .probe = wm8739_probe,
320 .remove = wm8739_remove,
347}; 321};
348 322
349
350static int __init wm8739_init_module(void)
351{
352 return i2c_add_driver(&i2c_driver);
353}
354
355static void __exit wm8739_cleanup_module(void)
356{
357 i2c_del_driver(&i2c_driver);
358}
359
360module_init(wm8739_init_module);
361module_exit(wm8739_cleanup_module);
diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
index 9f7e894ef962..869f9e7946b6 100644
--- a/drivers/media/video/wm8775.c
+++ b/drivers/media/video/wm8775.c
@@ -34,6 +34,7 @@
34#include <linux/videodev.h> 34#include <linux/videodev.h>
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-chip-ident.h> 36#include <media/v4l2-chip-ident.h>
37#include <media/v4l2-i2c-drv-legacy.h>
37 38
38MODULE_DESCRIPTION("wm8775 driver"); 39MODULE_DESCRIPTION("wm8775 driver");
39MODULE_AUTHOR("Ulf Eklund, Hans Verkuil"); 40MODULE_AUTHOR("Ulf Eklund, Hans Verkuil");
@@ -44,6 +45,7 @@ static unsigned short normal_i2c[] = { 0x36 >> 1, I2C_CLIENT_END };
44 45
45I2C_CLIENT_INSMOD; 46I2C_CLIENT_INSMOD;
46 47
48
47/* ----------------------------------------------------------------------- */ 49/* ----------------------------------------------------------------------- */
48 50
49enum { 51enum {
@@ -66,18 +68,15 @@ static int wm8775_write(struct i2c_client *client, int reg, u16 val)
66 return -1; 68 return -1;
67 } 69 }
68 70
69 for (i = 0; i < 3; i++) { 71 for (i = 0; i < 3; i++)
70 if (i2c_smbus_write_byte_data(client, (reg << 1) | 72 if (i2c_smbus_write_byte_data(client,
71 (val >> 8), val & 0xff) == 0) { 73 (reg << 1) | (val >> 8), val & 0xff) == 0)
72 return 0; 74 return 0;
73 }
74 }
75 v4l_err(client, "I2C: cannot write %03x to register R%d\n", val, reg); 75 v4l_err(client, "I2C: cannot write %03x to register R%d\n", val, reg);
76 return -1; 76 return -1;
77} 77}
78 78
79static int wm8775_command(struct i2c_client *client, unsigned int cmd, 79static int wm8775_command(struct i2c_client *client, unsigned cmd, void *arg)
80 void *arg)
81{ 80{
82 struct wm8775_state *state = i2c_get_clientdata(client); 81 struct wm8775_state *state = i2c_get_clientdata(client);
83 struct v4l2_routing *route = arg; 82 struct v4l2_routing *route = arg;
@@ -126,7 +125,8 @@ static int wm8775_command(struct i2c_client *client, unsigned int cmd,
126 break; 125 break;
127 126
128 case VIDIOC_G_CHIP_IDENT: 127 case VIDIOC_G_CHIP_IDENT:
129 return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_WM8775, 0); 128 return v4l2_chip_ident_i2c_client(client,
129 arg, V4L2_IDENT_WM8775, 0);
130 130
131 case VIDIOC_LOG_STATUS: 131 case VIDIOC_LOG_STATUS:
132 v4l_info(client, "Input: %d%s\n", state->input, 132 v4l_info(client, "Input: %d%s\n", state->input,
@@ -159,105 +159,67 @@ static int wm8775_command(struct i2c_client *client, unsigned int cmd,
159 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 159 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
160 */ 160 */
161 161
162static struct i2c_driver i2c_driver; 162static int wm8775_probe(struct i2c_client *client)
163
164static int wm8775_attach(struct i2c_adapter *adapter, int address, int kind)
165{ 163{
166 struct i2c_client *client;
167 struct wm8775_state *state; 164 struct wm8775_state *state;
168 165
169 /* Check if the adapter supports the needed features */ 166 /* Check if the adapter supports the needed features */
170 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 167 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
171 return 0; 168 return -EIO;
172
173 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
174 if (client == 0)
175 return -ENOMEM;
176
177 client->addr = address;
178 client->adapter = adapter;
179 client->driver = &i2c_driver;
180 snprintf(client->name, sizeof(client->name) - 1, "wm8775");
181 169
182 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name); 170 v4l_info(client, "chip found @ 0x%x (%s)\n",
171 client->addr << 1, client->adapter->name);
183 172
184 state = kmalloc(sizeof(struct wm8775_state), GFP_KERNEL); 173 state = kmalloc(sizeof(struct wm8775_state), GFP_KERNEL);
185 if (state == NULL) { 174 if (state == NULL)
186 kfree(client);
187 return -ENOMEM; 175 return -ENOMEM;
188 }
189 state->input = 2; 176 state->input = 2;
190 state->muted = 0; 177 state->muted = 0;
191 i2c_set_clientdata(client, state); 178 i2c_set_clientdata(client, state);
192 179
193 /* initialize wm8775 */ 180 /* Initialize wm8775 */
194 wm8775_write(client, R23, 0x000); /* RESET */ 181
195 wm8775_write(client, R7, 0x000); /* Disable zero cross detect timeout */ 182 /* RESET */
196 wm8775_write(client, R11, 0x021); /* Left justified, 24-bit mode */ 183 wm8775_write(client, R23, 0x000);
197 wm8775_write(client, R12, 0x102); /* Master mode, clock ratio 256fs */ 184 /* Disable zero cross detect timeout */
198 wm8775_write(client, R13, 0x000); /* Powered up */ 185 wm8775_write(client, R7, 0x000);
199 wm8775_write(client, R14, 0x1d4); /* ADC gain +2.5dB, enable zero cross */ 186 /* Left justified, 24-bit mode */
200 wm8775_write(client, R15, 0x1d4); /* ADC gain +2.5dB, enable zero cross */ 187 wm8775_write(client, R11, 0x021);
201 wm8775_write(client, R16, 0x1bf); /* ALC Stereo, ALC target level -1dB FS */ 188 /* Master mode, clock ratio 256fs */
202 /* max gain +8dB */ 189 wm8775_write(client, R12, 0x102);
203 wm8775_write(client, R17, 0x185); /* Enable gain control, use zero cross */ 190 /* Powered up */
204 /* detection, ALC hold time 42.6 ms */ 191 wm8775_write(client, R13, 0x000);
205 wm8775_write(client, R18, 0x0a2); /* ALC gain ramp up delay 34 s, */ 192 /* ADC gain +2.5dB, enable zero cross */
206 /* ALC gain ramp down delay 33 ms */ 193 wm8775_write(client, R14, 0x1d4);
207 wm8775_write(client, R19, 0x005); /* Enable noise gate, threshold -72dBfs */ 194 /* ADC gain +2.5dB, enable zero cross */
208 wm8775_write(client, R20, 0x07a); /* Transient window 4ms, lower PGA gain */ 195 wm8775_write(client, R15, 0x1d4);
209 /* limit -1dB */ 196 /* ALC Stereo, ALC target level -1dB FS max gain +8dB */
210 wm8775_write(client, R21, 0x102); /* LRBOTH = 1, use input 2. */ 197 wm8775_write(client, R16, 0x1bf);
211 i2c_attach_client(client); 198 /* Enable gain control, use zero cross detection,
212 199 ALC hold time 42.6 ms */
200 wm8775_write(client, R17, 0x185);
201 /* ALC gain ramp up delay 34 s, ALC gain ramp down delay 33 ms */
202 wm8775_write(client, R18, 0x0a2);
203 /* Enable noise gate, threshold -72dBfs */
204 wm8775_write(client, R19, 0x005);
205 /* Transient window 4ms, lower PGA gain limit -1dB */
206 wm8775_write(client, R20, 0x07a);
207 /* LRBOTH = 1, use input 2. */
208 wm8775_write(client, R21, 0x102);
213 return 0; 209 return 0;
214} 210}
215 211
216static int wm8775_probe(struct i2c_adapter *adapter) 212static int wm8775_remove(struct i2c_client *client)
217{ 213{
218 if (adapter->class & I2C_CLASS_TV_ANALOG) 214 kfree(i2c_get_clientdata(client));
219 return i2c_probe(adapter, &addr_data, wm8775_attach);
220 return 0; 215 return 0;
221} 216}
222 217
223static int wm8775_detach(struct i2c_client *client) 218static struct v4l2_i2c_driver_data v4l2_i2c_data = {
224{ 219 .name = "wm8775",
225 struct wm8775_state *state = i2c_get_clientdata(client); 220 .driverid = I2C_DRIVERID_WM8775,
226 int err; 221 .command = wm8775_command,
227 222 .probe = wm8775_probe,
228 err = i2c_detach_client(client); 223 .remove = wm8775_remove,
229 if (err) {
230 return err;
231 }
232 kfree(state);
233 kfree(client);
234
235 return 0;
236}
237
238/* ----------------------------------------------------------------------- */
239
240/* i2c implementation */
241static struct i2c_driver i2c_driver = {
242 .driver = {
243 .name = "wm8775",
244 },
245 .id = I2C_DRIVERID_WM8775,
246 .attach_adapter = wm8775_probe,
247 .detach_client = wm8775_detach,
248 .command = wm8775_command,
249}; 224};
250 225
251
252static int __init wm8775_init_module(void)
253{
254 return i2c_add_driver(&i2c_driver);
255}
256
257static void __exit wm8775_cleanup_module(void)
258{
259 i2c_del_driver(&i2c_driver);
260}
261
262module_init(wm8775_init_module);
263module_exit(wm8775_cleanup_module);
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index 6f1892585cbb..1fdbb46de7f3 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -749,7 +749,7 @@ static int zr364xx_mmap(struct file *file, struct vm_area_struct *vma)
749} 749}
750 750
751 751
752static struct file_operations zr364xx_fops = { 752static const struct file_operations zr364xx_fops = {
753 .owner = THIS_MODULE, 753 .owner = THIS_MODULE,
754 .open = zr364xx_open, 754 .open = zr364xx_open,
755 .release = zr364xx_release, 755 .release = zr364xx_release,
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index e18017d45758..c7a51a196f51 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -125,6 +125,8 @@
125#define I2C_DRIVERID_LM4857 92 /* LM4857 Audio Amplifier */ 125#define I2C_DRIVERID_LM4857 92 /* LM4857 Audio Amplifier */
126#define I2C_DRIVERID_VP27SMPX 93 /* Panasonic VP27s tuner internal MPX */ 126#define I2C_DRIVERID_VP27SMPX 93 /* Panasonic VP27s tuner internal MPX */
127#define I2C_DRIVERID_CS4270 94 /* Cirrus Logic 4270 audio codec */ 127#define I2C_DRIVERID_CS4270 94 /* Cirrus Logic 4270 audio codec */
128#define I2C_DRIVERID_M52790 95 /* Mitsubishi M52790SP/FP AV switch */
129#define I2C_DRIVERID_CS5345 96 /* cs5345 audio processor */
128 130
129#define I2C_DRIVERID_I2CDEV 900 131#define I2C_DRIVERID_I2CDEV 900
130#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */ 132#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
diff --git a/include/media/cs5345.h b/include/media/cs5345.h
new file mode 100644
index 000000000000..6ccae24e65ed
--- /dev/null
+++ b/include/media/cs5345.h
@@ -0,0 +1,39 @@
1/*
2 cs5345.h - definition for cs5345 inputs and outputs
3
4 Copyright (C) 2007 Hans Verkuil (hverkuil@xs4all.nl)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef _CS5345_H_
22#define _CS5345_H_
23
24/* CS5345 HW inputs */
25#define CS5345_IN_MIC 0
26#define CS5345_IN_1 1
27#define CS5345_IN_2 2
28#define CS5345_IN_3 3
29#define CS5345_IN_4 4
30#define CS5345_IN_5 5
31#define CS5345_IN_6 6
32
33#define CS5345_MCLK_1 0x00
34#define CS5345_MCLK_1_5 0x10
35#define CS5345_MCLK_2 0x20
36#define CS5345_MCLK_3 0x30
37#define CS5345_MCLK_4 0x40
38
39#endif
diff --git a/include/media/cx2341x.h b/include/media/cx2341x.h
index af8071d7620d..5f4608e88476 100644
--- a/include/media/cx2341x.h
+++ b/include/media/cx2341x.h
@@ -83,7 +83,7 @@ struct cx2341x_mpeg_params {
83#define CX2341X_MBOX_MAX_DATA 16 83#define CX2341X_MBOX_MAX_DATA 16
84 84
85extern const u32 cx2341x_mpeg_ctrls[]; 85extern const u32 cx2341x_mpeg_ctrls[];
86typedef int (*cx2341x_mbox_func)(void *priv, int cmd, int in, int out, 86typedef int (*cx2341x_mbox_func)(void *priv, u32 cmd, int in, int out,
87 u32 data[CX2341X_MBOX_MAX_DATA]); 87 u32 data[CX2341X_MBOX_MAX_DATA]);
88int cx2341x_update(void *priv, cx2341x_mbox_func func, 88int cx2341x_update(void *priv, cx2341x_mbox_func func,
89 const struct cx2341x_mpeg_params *old, 89 const struct cx2341x_mpeg_params *old,
diff --git a/include/media/cx25840.h b/include/media/cx25840.h
index 8e7e52d659a0..cd599ad29fb2 100644
--- a/include/media/cx25840.h
+++ b/include/media/cx25840.h
@@ -49,6 +49,25 @@ enum cx25840_video_input {
49 CX25840_SVIDEO2 = 0x620, 49 CX25840_SVIDEO2 = 0x620,
50 CX25840_SVIDEO3 = 0x730, 50 CX25840_SVIDEO3 = 0x730,
51 CX25840_SVIDEO4 = 0x840, 51 CX25840_SVIDEO4 = 0x840,
52
53 /* Allow frames to specify specific input configurations */
54 CX25840_VIN1_CH1 = 0x80000000,
55 CX25840_VIN2_CH1 = 0x80000001,
56 CX25840_VIN3_CH1 = 0x80000002,
57 CX25840_VIN4_CH1 = 0x80000003,
58 CX25840_VIN5_CH1 = 0x80000004,
59 CX25840_VIN6_CH1 = 0x80000005,
60 CX25840_VIN7_CH1 = 0x80000006,
61 CX25840_VIN8_CH1 = 0x80000007,
62 CX25840_VIN4_CH2 = 0x80000000,
63 CX25840_VIN5_CH2 = 0x80000010,
64 CX25840_VIN6_CH2 = 0x80000020,
65 CX25840_NONE_CH2 = 0x80000030,
66 CX25840_VIN7_CH3 = 0x80000000,
67 CX25840_VIN8_CH3 = 0x80000040,
68 CX25840_NONE0_CH3 = 0x80000080,
69 CX25840_NONE1_CH3 = 0x800000c0,
70 CX25840_SVIDEO_ON = 0x80000100,
52}; 71};
53 72
54enum cx25840_audio_input { 73enum cx25840_audio_input {
diff --git a/include/media/ir-common.h b/include/media/ir-common.h
index 7a785fa77212..831547d79683 100644
--- a/include/media/ir-common.h
+++ b/include/media/ir-common.h
@@ -97,7 +97,6 @@ int ir_dump_samples(u32 *samples, int count);
97int ir_decode_biphase(u32 *samples, int count, int low, int high); 97int ir_decode_biphase(u32 *samples, int count, int low, int high);
98int ir_decode_pulsedistance(u32 *samples, int count, int low, int high); 98int ir_decode_pulsedistance(u32 *samples, int count, int low, int high);
99 99
100u32 ir_rc5_decode(unsigned int code);
101void ir_rc5_timer_end(unsigned long data); 100void ir_rc5_timer_end(unsigned long data);
102void ir_rc5_timer_keyup(unsigned long data); 101void ir_rc5_timer_keyup(unsigned long data);
103 102
@@ -141,6 +140,8 @@ extern IR_KEYTAB_TYPE ir_codes_asus_pc39[IR_KEYTAB_SIZE];
141extern IR_KEYTAB_TYPE ir_codes_encore_enltv[IR_KEYTAB_SIZE]; 140extern IR_KEYTAB_TYPE ir_codes_encore_enltv[IR_KEYTAB_SIZE];
142extern IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE]; 141extern IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE];
143extern IR_KEYTAB_TYPE ir_codes_fusionhdtv_mce[IR_KEYTAB_SIZE]; 142extern IR_KEYTAB_TYPE ir_codes_fusionhdtv_mce[IR_KEYTAB_SIZE];
143extern IR_KEYTAB_TYPE ir_codes_behold[IR_KEYTAB_SIZE];
144extern IR_KEYTAB_TYPE ir_codes_pinnacle_pctv_hd[IR_KEYTAB_SIZE];
144 145
145#endif 146#endif
146 147
diff --git a/include/media/m52790.h b/include/media/m52790.h
new file mode 100644
index 000000000000..7ddffae31a67
--- /dev/null
+++ b/include/media/m52790.h
@@ -0,0 +1,93 @@
1/*
2 m52790.h - definition for m52790 inputs and outputs
3
4 Copyright (C) 2007 Hans Verkuil (hverkuil@xs4all.nl)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef _M52790_H_
22#define _M52790_H_
23
24/* Input routing switch 1 */
25
26#define M52790_SW1_IN_MASK 0x0003
27#define M52790_SW1_IN_TUNER 0x0000
28#define M52790_SW1_IN_V2 0x0001
29#define M52790_SW1_IN_V3 0x0002
30#define M52790_SW1_IN_V4 0x0003
31
32/* Selects component input instead of composite */
33#define M52790_SW1_YCMIX 0x0004
34
35
36/* Input routing switch 2 */
37
38#define M52790_SW2_IN_MASK 0x0300
39#define M52790_SW2_IN_TUNER 0x0000
40#define M52790_SW2_IN_V2 0x0100
41#define M52790_SW2_IN_V3 0x0200
42#define M52790_SW2_IN_V4 0x0300
43
44/* Selects component input instead of composite */
45#define M52790_SW2_YCMIX 0x0400
46
47
48/* Output routing switch 1 */
49
50/* Enable 6dB amplifier for composite out */
51#define M52790_SW1_V_AMP 0x0008
52
53/* Enable 6dB amplifier for component out */
54#define M52790_SW1_YC_AMP 0x0010
55
56/* Audio output mode */
57#define M52790_SW1_AUDIO_MASK 0x00c0
58#define M52790_SW1_AUDIO_MUTE 0x0000
59#define M52790_SW1_AUDIO_R 0x0040
60#define M52790_SW1_AUDIO_L 0x0080
61#define M52790_SW1_AUDIO_STEREO 0x00c0
62
63
64/* Output routing switch 2 */
65
66/* Enable 6dB amplifier for composite out */
67#define M52790_SW2_V_AMP 0x0800
68
69/* Enable 6dB amplifier for component out */
70#define M52790_SW2_YC_AMP 0x1000
71
72/* Audio output mode */
73#define M52790_SW2_AUDIO_MASK 0xc000
74#define M52790_SW2_AUDIO_MUTE 0x0000
75#define M52790_SW2_AUDIO_R 0x4000
76#define M52790_SW2_AUDIO_L 0x8000
77#define M52790_SW2_AUDIO_STEREO 0xc000
78
79
80/* Common values */
81#define M52790_IN_TUNER (M52790_SW1_IN_TUNER | M52790_SW2_IN_TUNER)
82#define M52790_IN_V2 (M52790_SW1_IN_V2 | M52790_SW2_IN_V2)
83#define M52790_IN_V3 (M52790_SW1_IN_V3 | M52790_SW2_IN_V3)
84#define M52790_IN_V4 (M52790_SW1_IN_V4 | M52790_SW2_IN_V4)
85
86#define M52790_OUT_STEREO (M52790_SW1_AUDIO_STEREO | \
87 M52790_SW2_AUDIO_STEREO)
88#define M52790_OUT_AMP_STEREO (M52790_SW1_AUDIO_STEREO | \
89 M52790_SW1_V_AMP | \
90 M52790_SW2_AUDIO_STEREO | \
91 M52790_SW2_V_AMP)
92
93#endif
diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
index e49f7e156061..89c442eb8849 100644
--- a/include/media/saa7146_vv.h
+++ b/include/media/saa7146_vv.h
@@ -1,7 +1,6 @@
1#ifndef __SAA7146_VV__ 1#ifndef __SAA7146_VV__
2#define __SAA7146_VV__ 2#define __SAA7146_VV__
3 3
4#include <linux/videodev.h>
5#include <media/v4l2-common.h> 4#include <media/v4l2-common.h>
6#include <media/saa7146.h> 5#include <media/saa7146.h>
7#include <media/videobuf-dma-sg.h> 6#include <media/videobuf-dma-sg.h>
diff --git a/include/media/tuner.h b/include/media/tuner.h
index c03dceb92605..1bf24a6ed8f1 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -24,8 +24,6 @@
24 24
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26 26
27extern int tuner_debug;
28
29#define ADDR_UNSET (255) 27#define ADDR_UNSET (255)
30 28
31#define TUNER_TEMIC_PAL 0 /* 4002 FH5 (3X 7756, 9483) */ 29#define TUNER_TEMIC_PAL 0 /* 4002 FH5 (3X 7756, 9483) */
@@ -117,12 +115,13 @@ extern int tuner_debug;
117#define TUNER_PHILIPS_TUV1236D 68 /* ATI HDTV Wonder */ 115#define TUNER_PHILIPS_TUV1236D 68 /* ATI HDTV Wonder */
118#define TUNER_TNF_5335MF 69 /* Sabrent Bt848 */ 116#define TUNER_TNF_5335MF 69 /* Sabrent Bt848 */
119#define TUNER_SAMSUNG_TCPN_2121P30A 70 /* Hauppauge PVR-500MCE NTSC */ 117#define TUNER_SAMSUNG_TCPN_2121P30A 70 /* Hauppauge PVR-500MCE NTSC */
120#define TUNER_XCEIVE_XC3028 71 118#define TUNER_XC2028 71
121 119
122#define TUNER_THOMSON_FE6600 72 /* DViCO FusionHDTV DVB-T Hybrid */ 120#define TUNER_THOMSON_FE6600 72 /* DViCO FusionHDTV DVB-T Hybrid */
123#define TUNER_SAMSUNG_TCPG_6121P30A 73 /* Hauppauge PVR-500 PAL */ 121#define TUNER_SAMSUNG_TCPG_6121P30A 73 /* Hauppauge PVR-500 PAL */
124#define TUNER_TDA9887 74 /* This tuner should be used only internally */ 122#define TUNER_TDA9887 74 /* This tuner should be used only internally */
125#define TUNER_TEA5761 75 /* Only FM Radio Tuner */ 123#define TUNER_TEA5761 75 /* Only FM Radio Tuner */
124#define TUNER_XC5000 76 /* Xceive Silicon Tuner */
126 125
127/* tv card specific */ 126/* tv card specific */
128#define TDA9887_PRESENT (1<<0) 127#define TDA9887_PRESENT (1<<0)
diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h
index 8ae42c41dd08..032bb75f69c2 100644
--- a/include/media/v4l2-chip-ident.h
+++ b/include/media/v4l2-chip-ident.h
@@ -68,6 +68,9 @@ enum {
68 /* module vp27smpx: just ident 2700 */ 68 /* module vp27smpx: just ident 2700 */
69 V4L2_IDENT_VP27SMPX = 2700, 69 V4L2_IDENT_VP27SMPX = 2700,
70 70
71 /* module cs5345: just ident 5345 */
72 V4L2_IDENT_CS5345 = 5345,
73
71 /* module wm8739: just ident 8739 */ 74 /* module wm8739: just ident 8739 */
72 V4L2_IDENT_WM8739 = 8739, 75 V4L2_IDENT_WM8739 = 8739,
73 76
@@ -83,6 +86,9 @@ enum {
83 /* module upd64083: just ident 64083 */ 86 /* module upd64083: just ident 64083 */
84 V4L2_IDENT_UPD64083 = 64083, 87 V4L2_IDENT_UPD64083 = 64083,
85 88
89 /* module m52790: just ident 52790 */
90 V4L2_IDENT_M52790 = 52790,
91
86 /* module msp34xx: reserved range 34000-34999 */ 92 /* module msp34xx: reserved range 34000-34999 */
87 V4L2_IDENT_MSP3400B = 34002, 93 V4L2_IDENT_MSP3400B = 34002,
88 V4L2_IDENT_MSP3410B = 34102, 94 V4L2_IDENT_MSP3410B = 34102,
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 181a40c46a52..475d0d8275e0 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -104,6 +104,17 @@ int v4l2_chip_match_host(u32 id_type, u32 chip_id);
104 104
105/* ------------------------------------------------------------------------- */ 105/* ------------------------------------------------------------------------- */
106 106
107/* Helper function for I2C legacy drivers */
108
109struct i2c_driver;
110struct i2c_adapter;
111struct i2c_client;
112
113int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver,
114 const char *name, int (*probe)(struct i2c_client *));
115
116/* ------------------------------------------------------------------------- */
117
107/* Internal ioctls */ 118/* Internal ioctls */
108 119
109/* VIDIOC_INT_DECODE_VBI_LINE */ 120/* VIDIOC_INT_DECODE_VBI_LINE */
@@ -116,6 +127,11 @@ struct v4l2_decode_vbi_line {
116 u32 type; /* VBI service type (V4L2_SLICED_*). 0 if no service found */ 127 u32 type; /* VBI service type (V4L2_SLICED_*). 0 if no service found */
117}; 128};
118 129
130struct v4l2_priv_tun_config {
131 int tuner;
132 void *priv;
133};
134
119/* audio ioctls */ 135/* audio ioctls */
120 136
121/* v4l device was opened in Radio mode, to be replaced by VIDIOC_INT_S_TUNER_MODE */ 137/* v4l device was opened in Radio mode, to be replaced by VIDIOC_INT_S_TUNER_MODE */
@@ -131,7 +147,7 @@ struct v4l2_decode_vbi_line {
131#define TUNER_SET_STANDBY _IOW('d', 91, int) 147#define TUNER_SET_STANDBY _IOW('d', 91, int)
132 148
133/* Sets tda9887 specific stuff, like port1, port2 and qss */ 149/* Sets tda9887 specific stuff, like port1, port2 and qss */
134#define TDA9887_SET_CONFIG _IOW('d', 92, int) 150#define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config)
135 151
136/* Switch the tuner to a specific tuner mode. Replacement of AUDC_SET_RADIO */ 152/* Switch the tuner to a specific tuner mode. Replacement of AUDC_SET_RADIO */
137#define VIDIOC_INT_S_TUNER_MODE _IOW('d', 93, enum v4l2_tuner_type) 153#define VIDIOC_INT_S_TUNER_MODE _IOW('d', 93, enum v4l2_tuner_type)
diff --git a/include/media/v4l2-i2c-drv-legacy.h b/include/media/v4l2-i2c-drv-legacy.h
new file mode 100644
index 000000000000..241854229d6f
--- /dev/null
+++ b/include/media/v4l2-i2c-drv-legacy.h
@@ -0,0 +1,140 @@
1/*
2 * v4l2-i2c-drv-legacy.h - contains I2C handling code that's identical
3 * for all V4L2 I2C drivers. Use this header if the
4 * I2C driver is used by both legacy drivers and
5 * drivers converted to the bus-based I2C API.
6 *
7 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24struct v4l2_i2c_driver_data {
25 const char * const name;
26 int driverid;
27 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);
28 int (*probe)(struct i2c_client *client);
29 int (*remove)(struct i2c_client *client);
30 int (*suspend)(struct i2c_client *client, pm_message_t state);
31 int (*resume)(struct i2c_client *client);
32 int (*legacy_probe)(struct i2c_adapter *adapter);
33 int legacy_class;
34};
35
36static struct v4l2_i2c_driver_data v4l2_i2c_data;
37static struct i2c_client_address_data addr_data;
38static struct i2c_driver v4l2_i2c_driver_legacy;
39static char v4l2_i2c_drv_name_legacy[32];
40
41static int v4l2_i2c_drv_attach_legacy(struct i2c_adapter *adapter, int address, int kind)
42{
43 return v4l2_i2c_attach(adapter, address, &v4l2_i2c_driver_legacy,
44 v4l2_i2c_drv_name_legacy, v4l2_i2c_data.probe);
45}
46
47static int v4l2_i2c_drv_probe_legacy(struct i2c_adapter *adapter)
48{
49 if (v4l2_i2c_data.legacy_probe) {
50 if (v4l2_i2c_data.legacy_probe(adapter))
51 return i2c_probe(adapter, &addr_data, v4l2_i2c_drv_attach_legacy);
52 return 0;
53 }
54 if (adapter->class & v4l2_i2c_data.legacy_class)
55 return i2c_probe(adapter, &addr_data, v4l2_i2c_drv_attach_legacy);
56 return 0;
57}
58
59static int v4l2_i2c_drv_detach_legacy(struct i2c_client *client)
60{
61 int err;
62
63 if (v4l2_i2c_data.remove)
64 v4l2_i2c_data.remove(client);
65
66 err = i2c_detach_client(client);
67 if (err)
68 return err;
69 kfree(client);
70
71 return 0;
72}
73
74static int v4l2_i2c_drv_suspend_helper(struct i2c_client *client, pm_message_t state)
75{
76 return v4l2_i2c_data.suspend ? v4l2_i2c_data.suspend(client, state) : 0;
77}
78
79static int v4l2_i2c_drv_resume_helper(struct i2c_client *client)
80{
81 return v4l2_i2c_data.resume ? v4l2_i2c_data.resume(client) : 0;
82}
83
84/* ----------------------------------------------------------------------- */
85
86/* i2c implementation */
87static struct i2c_driver v4l2_i2c_driver_legacy = {
88 .driver = {
89 .owner = THIS_MODULE,
90 },
91 .attach_adapter = v4l2_i2c_drv_probe_legacy,
92 .detach_client = v4l2_i2c_drv_detach_legacy,
93 .suspend = v4l2_i2c_drv_suspend_helper,
94 .resume = v4l2_i2c_drv_resume_helper,
95};
96
97/* ----------------------------------------------------------------------- */
98
99/* i2c implementation */
100static struct i2c_driver v4l2_i2c_driver = {
101 .suspend = v4l2_i2c_drv_suspend_helper,
102 .resume = v4l2_i2c_drv_resume_helper,
103};
104
105static int __init v4l2_i2c_drv_init(void)
106{
107 int err;
108
109 strlcpy(v4l2_i2c_drv_name_legacy, v4l2_i2c_data.name, sizeof(v4l2_i2c_drv_name_legacy));
110 strlcat(v4l2_i2c_drv_name_legacy, "'", sizeof(v4l2_i2c_drv_name_legacy));
111
112 if (v4l2_i2c_data.legacy_class == 0)
113 v4l2_i2c_data.legacy_class = I2C_CLASS_TV_ANALOG;
114
115 v4l2_i2c_driver_legacy.driver.name = v4l2_i2c_drv_name_legacy;
116 v4l2_i2c_driver_legacy.id = v4l2_i2c_data.driverid;
117 v4l2_i2c_driver_legacy.command = v4l2_i2c_data.command;
118 err = i2c_add_driver(&v4l2_i2c_driver_legacy);
119
120 if (err)
121 return err;
122 v4l2_i2c_driver.driver.name = v4l2_i2c_data.name;
123 v4l2_i2c_driver.id = v4l2_i2c_data.driverid;
124 v4l2_i2c_driver.command = v4l2_i2c_data.command;
125 v4l2_i2c_driver.probe = v4l2_i2c_data.probe;
126 v4l2_i2c_driver.remove = v4l2_i2c_data.remove;
127 err = i2c_add_driver(&v4l2_i2c_driver);
128 if (err)
129 i2c_del_driver(&v4l2_i2c_driver_legacy);
130 return err;
131}
132
133static void __exit v4l2_i2c_drv_cleanup(void)
134{
135 i2c_del_driver(&v4l2_i2c_driver_legacy);
136 i2c_del_driver(&v4l2_i2c_driver);
137}
138
139module_init(v4l2_i2c_drv_init);
140module_exit(v4l2_i2c_drv_cleanup);
diff --git a/include/media/v4l2-i2c-drv.h b/include/media/v4l2-i2c-drv.h
new file mode 100644
index 000000000000..9e4bab276915
--- /dev/null
+++ b/include/media/v4l2-i2c-drv.h
@@ -0,0 +1,68 @@
1/*
2 * v4l2-i2c-drv.h - contains I2C handling code that's identical for
3 * all V4L2 I2C drivers. Use this header if the
4 * I2C driver is only used by drivers converted
5 * to the bus-based I2C API.
6 *
7 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#ifndef __V4L2_I2C_DRV_H__
25#define __V4L2_I2C_DRV_H__
26
27#include <media/v4l2-common.h>
28
29struct v4l2_i2c_driver_data {
30 const char * const name;
31 int driverid;
32 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);
33 int (*probe)(struct i2c_client *client);
34 int (*remove)(struct i2c_client *client);
35 int (*suspend)(struct i2c_client *client, pm_message_t state);
36 int (*resume)(struct i2c_client *client);
37 int (*legacy_probe)(struct i2c_adapter *adapter);
38 int legacy_class;
39};
40
41static struct v4l2_i2c_driver_data v4l2_i2c_data;
42static struct i2c_driver v4l2_i2c_driver;
43
44
45/* Bus-based I2C implementation for kernels >= 2.6.22 */
46
47static int __init v4l2_i2c_drv_init(void)
48{
49 v4l2_i2c_driver.driver.name = v4l2_i2c_data.name;
50 v4l2_i2c_driver.id = v4l2_i2c_data.driverid;
51 v4l2_i2c_driver.command = v4l2_i2c_data.command;
52 v4l2_i2c_driver.probe = v4l2_i2c_data.probe;
53 v4l2_i2c_driver.remove = v4l2_i2c_data.remove;
54 v4l2_i2c_driver.suspend = v4l2_i2c_data.suspend;
55 v4l2_i2c_driver.resume = v4l2_i2c_data.resume;
56 return i2c_add_driver(&v4l2_i2c_driver);
57}
58
59
60static void __exit v4l2_i2c_drv_cleanup(void)
61{
62 i2c_del_driver(&v4l2_i2c_driver);
63}
64
65module_init(v4l2_i2c_drv_init);
66module_exit(v4l2_i2c_drv_cleanup);
67
68#endif /* __V4L2_I2C_DRV_H__ */
diff --git a/include/media/v4l2-int-device.h b/include/media/v4l2-int-device.h
index 066ebfc4f983..c8b80e0f0651 100644
--- a/include/media/v4l2-int-device.h
+++ b/include/media/v4l2-int-device.h
@@ -44,9 +44,8 @@ enum v4l2_int_type {
44struct v4l2_int_device; 44struct v4l2_int_device;
45 45
46struct v4l2_int_master { 46struct v4l2_int_master {
47 int (*attach)(struct v4l2_int_device *master, 47 int (*attach)(struct v4l2_int_device *slave);
48 struct v4l2_int_device *slave); 48 void (*detach)(struct v4l2_int_device *slave);
49 void (*detach)(struct v4l2_int_device *master);
50}; 49};
51 50
52typedef int (v4l2_int_ioctl_func)(struct v4l2_int_device *); 51typedef int (v4l2_int_ioctl_func)(struct v4l2_int_device *);
diff --git a/include/media/videobuf-core.h b/include/media/videobuf-core.h
index 4fd5d0eaa935..97f14d469595 100644
--- a/include/media/videobuf-core.h
+++ b/include/media/videobuf-core.h
@@ -56,13 +56,13 @@ struct videobuf_mapping {
56}; 56};
57 57
58enum videobuf_state { 58enum videobuf_state {
59 STATE_NEEDS_INIT = 0, 59 VIDEOBUF_NEEDS_INIT = 0,
60 STATE_PREPARED = 1, 60 VIDEOBUF_PREPARED = 1,
61 STATE_QUEUED = 2, 61 VIDEOBUF_QUEUED = 2,
62 STATE_ACTIVE = 3, 62 VIDEOBUF_ACTIVE = 3,
63 STATE_DONE = 4, 63 VIDEOBUF_DONE = 4,
64 STATE_ERROR = 5, 64 VIDEOBUF_ERROR = 5,
65 STATE_IDLE = 6, 65 VIDEOBUF_IDLE = 6,
66}; 66};
67 67
68struct videobuf_buffer { 68struct videobuf_buffer {
@@ -162,12 +162,14 @@ struct videobuf_queue {
162 struct videobuf_queue_ops *ops; 162 struct videobuf_queue_ops *ops;
163 struct videobuf_qtype_ops *int_ops; 163 struct videobuf_qtype_ops *int_ops;
164 164
165 unsigned int streaming:1;
166 unsigned int reading:1;
167 unsigned int is_mmapped:1;
168
165 /* capture via mmap() + ioctl(QBUF/DQBUF) */ 169 /* capture via mmap() + ioctl(QBUF/DQBUF) */
166 unsigned int streaming;
167 struct list_head stream; 170 struct list_head stream;
168 171
169 /* capture via read() */ 172 /* capture via read() */
170 unsigned int reading;
171 unsigned int read_off; 173 unsigned int read_off;
172 struct videobuf_buffer *read_buf; 174 struct videobuf_buffer *read_buf;
173 175